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

Changing MAC Address in nrf52

Hello,

I am trying to change the MAC address of my device nRF52, by using NRF_FICR->DEVICEADDR[0], NRF_FICR->DEVICEADDR[1], I am able to see the device address.

But when I try to change it by using below code it doesn't change, it shows the same address,

p_addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE;

for(uint8_t i = 0; i<6; i++)
{
	p_addr.addr[i] = 0xAAAAAAAA;
}

I am calling this in main function. After executing this code when I try to read NRF_FICR->DEVICEADDR[0], NRF_FICR->DEVICEADDR[1], i still see the same previous address.

what would be the problem ?

Parents
  • The error code 12802 (0x3202) corresponds to BLE_ERROR_GAP_INVALID_BLE_ADDR. You should make sure the address you enter use the correct format for the address type. You can set the address from FICR like this:

    static ble_gap_addr_t m_central_addr;
    
    m_central_addr.addr_type     = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
    m_central_addr.addr[0] = (uint8_t)NRF_FICR->DEVICEADDR[0];
    m_central_addr.addr[1] = (uint8_t)(NRF_FICR->DEVICEADDR[0] >> 8);
    m_central_addr.addr[2] = (uint8_t)(NRF_FICR->DEVICEADDR[0] >> 16);
    m_central_addr.addr[3] = (uint8_t)(NRF_FICR->DEVICEADDR[0] >> 24);
    m_central_addr.addr[4] = (uint8_t)NRF_FICR->DEVICEADDR[1];
    m_central_addr.addr[5] = (uint8_t)((NRF_FICR->DEVICEADDR[1] >> 8) | 0xC0); // 2MSB must be set 11
    
    sd_ble_gap_addr_set(&m_central_addr);
    
Reply
  • The error code 12802 (0x3202) corresponds to BLE_ERROR_GAP_INVALID_BLE_ADDR. You should make sure the address you enter use the correct format for the address type. You can set the address from FICR like this:

    static ble_gap_addr_t m_central_addr;
    
    m_central_addr.addr_type     = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
    m_central_addr.addr[0] = (uint8_t)NRF_FICR->DEVICEADDR[0];
    m_central_addr.addr[1] = (uint8_t)(NRF_FICR->DEVICEADDR[0] >> 8);
    m_central_addr.addr[2] = (uint8_t)(NRF_FICR->DEVICEADDR[0] >> 16);
    m_central_addr.addr[3] = (uint8_t)(NRF_FICR->DEVICEADDR[0] >> 24);
    m_central_addr.addr[4] = (uint8_t)NRF_FICR->DEVICEADDR[1];
    m_central_addr.addr[5] = (uint8_t)((NRF_FICR->DEVICEADDR[1] >> 8) | 0xC0); // 2MSB must be set 11
    
    sd_ble_gap_addr_set(&m_central_addr);
    
Children
Related