Reply
Posts: 10
Registered: ‎12-12-2016
Accepted Solution

Extracting BGM111 Board Address in C

I am trying to extract the board address from a BGM111. I do it in BGScript as follows:

 

call system_get_bt_address()(sn(0:6))
call print_hex(sn(0:1))
call print_hex(sn(1:1))
call print_hex(sn(2:1))
call print_hex(sn(3:1))
call print_hex(sn(4:1))
call print_hex(sn(5:1))

 

and I get 5F541D570B00  which appears to make sense.

 

I really need to do it in C and found a piece of code that compiles but results in all zeros. The code:

 

uint32_t uniqueId;
uint8_t btAddr[6];
struct gecko_msg_system_get_bt_address_rsp_t *btAddrRsp;

// Extract unique ID from BT Address
btAddrRsp = gecko_cmd_system_get_bt_address();
memcpy(btAddr, btAddrRsp->address.addr, 6);
uniqueId = 0xFFFFFF & *((uint32*) btAddr);

 

I admit I am not sure I follow this code exactly but when debugging I get all zeros for btAddr and for uniqueId.

 

Any thoughts or a clearer example of the use of the gecko_cmd_system_get_bt_address function?

 

Thanks 

 

 

Posts: 2,052
Registered: ‎09-01-2015

Re: Extracting BGM111 Board Address in C

>> and I get 5F541D570B00  which appears to make sense.

 

Try reversing the byte order and you get:

00:0B:57:1D:54:5F

 

Makes more sense now?

 

The C code snippet that you attached: this will not work if you call it before the system_boot event has been raised. Could it be possible that you are calling it too early in your program ? (before system_boot) ?

Posts: 10
Registered: ‎12-12-2016

Re: Extracting BGM111 Board Address in C

Thanks, that was the problem. I was calling for the address before the boot event.