新闻  |   论坛  |   博客  |   在线研讨会
802..15.4(zigbee协议)
xiajiashan | 2012-08-28 16:46:29    阅读:1376   发布文章

作者:下家山

一:802.15.4帧格式     20110607_xjs_f1.jpg

图一

 
1.1 Preamble Sequence

此字段包含4个字节,有cc2420自动产生。

1.2 Start of Frame Delimiter

此字段包含1个字节,有cc2420自动产生。

=============================================================================

1.3 Mac Protocol Data Unit

接下来的字段是我们需要设置的

二:结构体表示MPDU

通常我们用一个结构体来表示

typedef struct

{

/* The following fields are transmitted/received on the radio. */

char length;

char fcfhi;

char fcflo;

char dsn;

int destpan;

int addr;

char type;

char group;

char Txdata[TOSH_DATA_LENGTH];

 

/* The following fields are not actually transmitted or received

* on the radio! They are used for internal accounting only.

* The reason they are in this structure is that the AM interface

* requires them to be part of the TOS_Msg that is passed to

* send/receive operations.

*/

char strength;

char lqi;

int crc;

int ack;

int time;//

} Msg;

如果,我们要发送一个字节0x55,程序该怎么写:

#define CC2420_DEF_FCF_LO 0x08

#define TOS_BCAST_ADDR 0xffff

#define CC2420_DEF_FCF_HI_ACK 0x21 // with ACK

#define CC2420_DEF_FCF_HI 0x01 // without ACK

void main()

{

 

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

hardwareinit();

Msg * data;

long int i,j;

data=(Msg*)malloc(sizeof(Msg));

 

P5DIR|=0X70;//0111 0000 1out 0 in

P5OUT|=0X70; //1高电平

data -> length = 12; //msg data length:10 last lqi&rssi:2

data -> fcflo = CC2420_DEF_FCF_LO;//destination address mode:10

data -> fcfhi = CC2420_DEF_FCF_HI_ACK;//ack request:1 frame type:10

// destination PAN is broadcast

data -> destpan = TOS_BCAST_ADDR;

// adjust the destination address to be in the right byte order

data -> addr = 0x0001;

// adjust the data type if need

data -> type = FRAME_TYPE_DATA;

// keep the DSN increasing for ACK recognition

data -> dsn = 1;

// reset the time field

data -> time = 0;

data -> group=0x00;

data -> Txdata[0]=0x55;

 

for(i=0;i<100;i++)

{

data->dsn =i;

sendAMessage(data -> length,(char*)data);

for(j=0;j<50000;j++);

}

free(data);

P5OUT|=0X10;

}

2.1发送数据截图

那么最终发送出去的数据是:

 

20110607_xjs_f2.jpg

图二

有了这些,我们可以把协议与代码,还有实际发送的数据一一对应起来

2.2 代码与发送数据汇总

20110607_xjs_f3.jpg

20110607_xjs_f4.jpg

 

2.3接收数据截图

 

那么接收到的数据呢?

首先,我们把发送与接收的数据的截图做一个比较:

20110607_xjs_f5.jpg

三:怎么找到RSSI

那么我们MODEMCTRL0,AUTOCRC有没有被置位呢?

20110607_xjs_f6.jpg

2010-10-18 11:06 写于上海.松江

(请尊重原创,转载请注明:作者,下家山)

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
02年接触ARM和ucos,开发过有线和无线图像报警器,IPCamera,人脸识别系统,OCR识别系统,指纹识别系统,05年开始从事Linux及Rtems下WiFi,camera,Ethernet等驱动开发工作,专做嵌入式linux培训,致力于把我十年来的研发经验传授给每一个学员,招人的可以找我,ximenpiaoxue4016@sina.com
推荐文章
最近访客