cc2530关闭射频
扫描二维码
随时随地手机看文章
#include "ioCC2530.h"
#define led1 P1_0
#define led2 P2_0
static unsigned char buf[128];
static unsigned char len=8;
void init_usart()
{
PERCFG = 0x00;
P0SEL = 0x3c; // 0011 1100
U0CSR |= 0x80;
U0GCR |= 11;
U0BAUD = 216; // set baudrate 115200
UTX0IF = 1;
U0CSR |= 0x40;
}
void rf_init()
{
FRMCTRL0 |= (0x20 | 0x40); /* AUTO_ACK | AUTO_CRC */
TXFILTCFG = 0x09;
AGCCTRL1 = 0x15;
FSCAL1 = 0x00;
/* enable RXPKTDONE interrupt */
RFIRQM0 |= (1<<6);
/* enable general RF interrupts */
IEN2 |= (1<<0);
FREQCTRL = 0x0b; /* channel 11 */
SHORT_ADDR0 = 0x05;
SHORT_ADDR1 = 0x00;
PAN_ID0 = 0x22; /* MUST set, or even can't receive broadcast message */
PAN_ID1 = 0x00;
RFST = 0xed; /* ISFLUSHRX */
RFST = 0xe3; /* ISRXON */
}
#pragma vector=RF_VECTOR
__interrupt void rf_isr(void)
{
unsigned char e, i;
led1 ^=1;
led2 ^=1;
e = EA;
EA = 0; /* disable global interrupt */
if (RFIRQF0 & (1<<6)) {
len = RFD;
len &= 0x7f;
for (i = 0; i < len; i++) {
buf[i] = RFD;
};
S1CON = 0; /* clear general RF interrupt flag */
RFIRQF0 &= ~(1<<6); /* clear RXPKTDONE interrupt */
}
EA = e; /* restore global interrupt state */
}
void tx()
{
unsigned char i;
RFST = 0xe3; /* ISRXON */
/* wait for SFD not active and TX_Active not active */
while (FSMSTAT1 & ((1<<1) | (1<<5))); /* TX_ACTIVE | SFD */
RFIRQM0 &= ~(1<<6); /* disable RXPKTDONE interrupt */
IEN2 &= ~(1<<0); /* disable general RF interrupts */
RFST = 0xee; /* ISFLUSHTX */
RFIRQF1 = ~(1<<1); /* clear TXDONE interrupt */
RFD = len; /* the first byte to TX is the length of the frame */
for (i = 0; i < len; i++) {
RFD = buf[i];
}
/* trun on RX interrupt */
RFIRQM0 |= (1<<6);
IEN2 |= (1<<0);
RFST = 0xe9; /* ISTXON */
while (!(RFIRQF1 & (1<<1))); /* waiting for transmission to finish */
RFIRQF1 = ~(1<<1); /* clear TXDONE interrupt */
}
void main(void)
{
P1SEL &= ~(1<<0); //P1为普通 I/O 口
P2SEL &= ~(1<<0);
P1DIR |= 0x01; //P1.0 输出
P2DIR |= 0x01;
led1=0;
led2=0;
EA = 0;
/* set main clock source to 32MHz */
SLEEPCMD &= ~0x04;
while(!(SLEEPSTA & 0x40));
CLKCONCMD &= ~0x47;
SLEEPCMD |= 0x04;
//init_usart();
rf_init();
EA = 1; /* enable global interrupt */
while(1) {
if (len > 0) {
led1=1;
led2=1;
tx();
}
}
}
节点2的代码与节点1差不多,只是在接收中断处理程序里加了亮灯的代码。
烧写节点以后,发现节点1能发送,但是节点2一点反应都没有。。这是为什么呢?在烧写的时候要设置IEEE地址吗?本人是初学CC2530,请各位指教!