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.

Parents
  • Maybe try something like this:

    char InfoPacket[80];
    // Get actual BLE address in case it is different from hardware register BLE address
    ble_gap_addr_t device_addr;  // 48-bit address, LSB format
    sd_ble_gap_addr_get(&device_addr);
    snprintf(InfoPacket, sizeof(InfoPacket), "BLE %02X%02X:%02X%02X%02X%02X%02X%02X",
                         device_addr.addr_id_peer, device_addr.addr_type, device_addr.addr[0], device_addr.addr[1], device_addr.addr[2], device_addr.addr[3], device_addr.addr[4], device_addr.addr[5]);
    

Reply
  • Maybe try something like this:

    char InfoPacket[80];
    // Get actual BLE address in case it is different from hardware register BLE address
    ble_gap_addr_t device_addr;  // 48-bit address, LSB format
    sd_ble_gap_addr_get(&device_addr);
    snprintf(InfoPacket, sizeof(InfoPacket), "BLE %02X%02X:%02X%02X%02X%02X%02X%02X",
                         device_addr.addr_id_peer, device_addr.addr_type, device_addr.addr[0], device_addr.addr[1], device_addr.addr[2], device_addr.addr[3], device_addr.addr[4], device_addr.addr[5]);
    

Children
  • Could do the same without using Soft Device or library? I'm working with my own code and by registers.

    Best regards,

    Jorge.

  • Yes, of course. This is the trace from both techniques with the first part using the code I posted earlier:

    BLE 0001:58EAA39F67F4 (1FC5B4679FA3EA58)

    The second (in parenthesis) is the 64-bit device address from which the 48-bit BLE address is formed.

    // print format (%08X%08X)
    NRF_FICR->DEVICEADDR[1], NRF_FICR->DEVICEADDR[0]
    
    /**@brief Bluetooth Low Energy address. */
    typedef struct
    {
      uint8_t addr_id_peer : 1;       /**< Only valid for peer addresses.
                                           Reference to peer in device identities list (as set with @ref sd_ble_gap_device_identities_set) when peer is using privacy. */
      uint8_t addr_type    : 7;       /**< See @ref BLE_GAP_ADDR_TYPES. */
      uint8_t addr[BLE_GAP_ADDR_LEN]; /**< 48-bit address, LSB format. */
    } ble_gap_addr_t;
    

    This shows the byte-reversal, and also note the top bits; I forget where these details are described so can't give a better description I'm afraid ..

  • Now I'm wondering whether you are looking for the permanent Id? NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0], as I don't know what the actual label is meant to indicate. I haven't had time to load an nRF52840 dongle up yet so can't test this ..

  • Could you test my code in other nrf52 device?? Maybe you only have to change the transmit function thats I created for UART transmission.

  • 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.

Related