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

Change mac address quickly

I'm trying to change the mac address of my nRF51822 chip using something like:

ble_gap_addr_t m_address_1;
m_address_1.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE;
m_address_1.addr ...
m_address_1.addr[5] = 8;
sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &m_address);

I'm trying to switch between m_address_1 and m_address_2 every 500ms. It seems to work if the rate I switch is more than 1 second, but at 500ms, the address does not change fast enough and the advertisements packets get sent out at incorrect addresses.

Is there anyway to make this address change instantly for the next advertisement packet?

  • Hi

    I can't really see why that won't work for you, but I made an example for you. It uses a timer to change the mac address at an interval of your own choosing. It seemed to work at least down to a 100ms. It is a quick and dirty example based on the ble template example in SDK 9.0.0. Just extract it to e.g. "SDK_9.0.0_folder\examples\ble_peripheral" and hopefully it will compile out of the box.

    change-mac-address-quickly.zip

  • I use the code below but I got the mac address is different from I set .What's more,I find it is constant.

    ble_gap_addr_t m_address_1;
    m_address_1.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE;
    
    for(uint8_t i = 0; i < 2; i++)
    {
        m_address_1.addr[i] = 0xAAAAAAAA;
    }
    
    sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &m_address_1);
    
    while(1)
    {      
        for(uint8_t i = 0; i < 2; i++)
        {
            Serial.println(NRF_FICR->DEVICEID[i]);
        }
        delay(1000);
    }
    
  • As far as I can see you are only setting the mac address once before you enter a while forever loop that does nothing but print the value of the FICR register?

    And it also looks like you are only setting the first two bytes of the mac address as 0xAA. The rest of the bytes will then be random. Try for i<6 instead of i<2 to iterate through all 6 bytes of the mac address.

Related