802..15.4(zigbee协议)
作者:下家山
图一
此字段包含4个字节,有cc2420自动产生。
此字段包含1个字节,有cc2420自动产生。
=============================================================================
接下来的字段是我们需要设置的
通常我们用一个结构体来表示
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.3接收数据截图
那么接收到的数据呢?
首先,我们把发送与接收的数据的截图做一个比较:
那么我们MODEMCTRL0,AUTOCRC有没有被置位呢?
2010-10-18 11:06 写于上海.松江
(请尊重原创,转载请注明:作者,下家山)
用户1037328 2011-6-9 16:16
用户1037328 2011-6-8 11:22
用户1602177 2011-6-7 15:36
博主,图片已经贴在内文中,请调整位置! PS:在编辑框里有一个插图按钮(下图中第三个就是),您可以留意一下~
用户1037328 2011-6-7 14:49
用户1037328 2011-6-7 14:37
请问怎么插入图片啊