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];
    }

Reply
  • 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];
    }

Children
Related