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

MAC Address for BLE Communication

Hi,

I'm trying send me the mac address of the device by UART by the following method:

void sendMacAddress(void){
  uint8_t packet[6];
  packet[0] = NRF_FICR->DEVICEADDR[0];
  packet[1] = NRF_FICR->DEVICEADDR[0]>>8;
  packet[2] = NRF_FICR->DEVICEADDR[0]>>16;
  packet[3] = NRF_FICR->DEVICEADDR[0]>>24;
  packet[4] = NRF_FICR->DEVICEADDR[1];
  packet[5] = NRF_FICR->DEVICEADDR[1]>>8;
  transmit_string_CR("Start",5);
  for(int i=5; i>=0; --i){
    char msg[2]={0};
    itoa(packet[i],msg,16);
    transmit_string_NCR(msg,2);
    if(i!=0)transmit_string_NCR(":",1);
  }
  CR();
  nrf_delay_ms(1000);
}

By serial I receive: 

Start
b9:24:82:d5:4f:81

The problem its that the device which I receive is not the same that appears in the stick device, I attach photo:

Could anyone tell me that I'm do it correctly?

Best,

Jorge.

  • Your code is correct except for the last 2 bits, which is expected. The last 2 bits in the serial BLE stream are listed below as the most significant 2 bits in the last byte (ie your packet[5]).

    This is the response from an nRF52832, but it doesn't have a label such as the label in your photo above so I can't actually verify if the calculated address matches the expected address on the label:

     // >Central SD Ver. [5.1.0] [59 A5 9] BLE 0001:9132FEF505E6 (DD082605F5FE3291)
     // BLE 0001: 91 32 FE F5 05 E6
     //           DD 08 26 05 F5 FE 32 91
     // reverse   91 32 FE F5 05 26 08 DD
    
     //  BLE 0001:91 32 FE F5 05 E6
     // Your code 91 32 FE F5 05 26
     // packet[i]  0  1  2  3  4  5

    The last 2 bits in the bit stream have different meaning as defined in the Bluetooth Sig; one bit is public/random address but I forget what the other bit is, and I don't have docs to hand. Maybe a Nordic engineer can point to that .. 

    Your photo actually matches your log, I just checked! Except for the 2 special bits, of course.

  • Ah, its a Static Random address see this post - that's why the last 2 bits in the serial bit stream are both '1' - this is the most sig top 2 bits in byte 5 in your packet[] array. (Each byte in the array are transmitted least significant bit first in the serial bit stream).

    Note that even though the address is "Random", it is invariant and never changes for a specific Nordic device as the NRF_FICR->DEVICEADDR registers are Read-Only.

  • I understand that in BLE Steam the 2 MSB bits of the address depends of the type of address as you attached in the comment before. But in this case we're reading a register, that could be use as on-air address or I could make my own address, so I think that there are other reason for this case.

    Also, as I can saw in the Product Specification Docs, there is a register in which appears the type of address:

    As we can appreciated if the register is 0xFFFFFFFF its a Random Address, and if the register is 0xFFFFFFFE, it's a public Address. I attach the code:

    void sendMacAddress(void){
      uint8_t packet[6];
      packet[0] = NRF_FICR->DEVICEADDR[0];
      packet[1] = NRF_FICR->DEVICEADDR[0]>>8;
      packet[2] = NRF_FICR->DEVICEADDR[0]>>16;
      packet[3] = NRF_FICR->DEVICEADDR[0]>>24;
      packet[4] = NRF_FICR->DEVICEADDR[1];
      packet[5] = NRF_FICR->DEVICEADDR[1]>>8;
      transmit_string_CR("Start",5);
      if(NRF_FICR->DEVICEADDRTYPE == 0xFFFFFFFF) transmit_string_CR("Random",6);
      else transmit_string_CR("Public",6);
      for(int i=5; i>=0; --i){
        char msg[2]={0};
        itoa(packet[i],msg,16);
        transmit_string_NCR(msg,2);
        if(i!=0)transmit_string_NCR(":",1);
      }
      CR();
      CR();
      nrf_delay_ms(1000);
    }

    And I see by serial port:

    I have test that and the results are that there's a random address, so I don't understand why and don't correspond with the "public address" of the label.

    So what address I have to use in the PREFIX and BASE register of the Radio?

  • The address on the label is actually "Static Random", not "Public". You cannot change the DEVICEADDRTYPE register as it is also read-only. Nordic appear to hardcode the psuedo-random 48-bit address and then set the upper 2 bits within the SoftDevice stack to indicate "Static Random". These 3 registers can not be changed.

    If you want your own BLE "Public" address I believe you can set it using sd_ble_gap_addr_set() which you can find in the Infocenter. However it looks to me like your decoding is correct and matches the label provided you always set the upper 2 bits.

  • Many thanks , I'm going to try the code with another dongle and also with DK.

    I think thats my code reads the Public Address, and the label has the Static Random Address may be I could change it to Non Resolvable and Resolvable, masking with 0x02 and 0x03 the 2 bits.

    I tell you if the dongle or the DK has the same behavior. 

    Best,

    Jorge.

Related