Hi PJ
I was borrowing your code and noticed that it didn’t always produce the correct MAC Address value.
You need to add the last line to the function.
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];
// To ensure compliance with the Bluetooth Core Specification v4.0,
// which states that the two most significant bits (MSB) of the address
// must be set to '11' for random static addresses, you need to modify
// the first byte of the MAC address after retrieving it from the hardware.
// ( see Bluetooth Core v4.0, Vol 3, Part C, chapter 10.8.1.)
mac_address[0] |= 0xC0; // 0xC0 is binary 11000000
}
Regards
Dave