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);

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值