"); //-->
作者:下家山
一:802.15.4帧格式图一
此字段包含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发送数据截图那么最终发送出去的数据是:
图二
有了这些,我们可以把协议与代码,还有实际发送的数据一一对应起来
2.2 代码与发送数据汇总
2.3接收数据截图
那么接收到的数据呢?
首先,我们把发送与接收的数据的截图做一个比较:
三:怎么找到RSSI
那么我们MODEMCTRL0,AUTOCRC有没有被置位呢?
2010-10-18 11:06 写于上海.松江
(请尊重原创,转载请注明:作者,下家山)
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。
eleaction01 阅读:4524