This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Retrieve BLE MAC address in Zephyr environment

When using the nRF5 SDK v17.x development environment, the BLE MAC address can be retrieved using:

  ble_gap_addr_t mac;

  // Get MAC address
  sd_ble_gap_addr_get(&mac);

This will return the assigned MAC address (eg. from the nRF52840 on a Laird Module).     Does a similar call exist when using nRF Connect SDK (NCS)   (I see void bt_id_get(bt_addr_le_t *addrs, size_t *count), but the description leaves questions...)?

Thanks!

Parents
  • I was looking for this too. My solution was using the ficr. 

    static void get_mac_address(uint8_t mac_address[6]) {
    	unsigned int device_addr_0 = NRF_FICR->DEVICEADDR[0];
    	unsigned int device_addr_1 = NRF_FICR->DEVICEADDR[1];
    	const uint8_t* part_0 = reinterpret_cast<const uint8_t*>(&device_addr_0);
    	const uint8_t* part_1 = reinterpret_cast<const uint8_t*>(&device_addr_1);
    	mac_address[0] = part_1[1];
    	mac_address[1] = part_1[0];
    	mac_address[2] = part_0[3];
    	mac_address[3] = part_0[2];
    	mac_address[4] = part_0[1];
    	mac_address[5] = part_0[0];
    }

  • Line 7 should be mac_address[0] = part_1[1] | 0xC0;

    According to the BLE spec on valid MAC addresses, in Core Spec 5.3, Vol 6, Part B, Chapter 1.3.2.1, the two most significant bits of the address must be equal to 1 for a static device address.  If you don't do this, it will not match what you get with the bt_read_static_addr function.

Reply Children
Related