BLE协议栈之读取CC2541的MAC地址

                                                                   CC2541MAC地址的读取

  在读取蓝牙MAC地址时有一种非常简便的方法,就是直接去读寄存器里的MAC地址 ,

The Information Page is a 2-KB read-only region that stores various device information. Among other
things, it contains for IEEE 802.15.4 or Bluetooth low energy compliant devices a unique IEEE address
from the TI range of addresses. For CC253x, this is a 64-bit IEEE address stored with least-significant
byte first at XDATA address 0x780C. For CC2540/41, this is a 48-bit IEEE address stored with
least-significant byte first at XDATA address 0x780E

 

于是读出寄存器中的值,就可以得到MAC地址了 ,这里是只读空间,网上有说直接改变MAC地址的,甚是不能理解啊!!!

void ReadMac(unsigned char *TempMacAddress,int len)  // Len 一定是6
{
   TempMacAddress[5]=XREG(0x780E); // 直接指向指针内容
   TempMacAddress[4]=XREG(0x780F);
   TempMacAddress[3]=XREG(0x7810);
   TempMacAddress[2]=XREG(0x7811);                // define 函数直接读出数据
   TempMacAddress[1]=XREG(0x7812);
   TempMacAddress[0]=XREG(0x7813);
   return ;
}

顺便说一下XREG的定义:
#define XREG(addr)       ((unsigned char volatile __xdata *) 0)[addr]

volatile 是为了在优化的时候值被改写,xdata是放在xdata空间中。

这句话是为了直接读出addr地址的内容!!!

 

在BLE协议栈中也可以调用系统的API获取MAC地址

static uint8 MAC_Address[B_ADDR_LEN]={0}; //   mac 地址
 GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress);
  osal_memcpy( MAC_Address,ownAddress,B_ADDR_LEN);

 

你可能感兴趣的:(BLE协议栈之读取CC2541的MAC地址)