This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ZIGBEE-COMMUNICATION PROBLEM

Other Parts Discussed in Thread: CC2530

Hello,

I'm working on zigBee cc2530 module........

we have written a transmitter and receiver programme for ADC,such a way that transmitter is continuously transmitting the ADC signal by forming frames...........

At the receiving end we are receiving  all the frames continuously and it is sent to PC using UART.......

PROBLEM

My problem is that, when we receiving frames ,some times it receives correct frames and some times bytes are getting shifted........please give me some suggestions and give a appropriate solution for it...................

Do the needful................


transmitter programme

#include <iocc2530.h>
void tx();
void rf_init();
void delay();
void delay1();
void adc();
void init_adc();
#define led1 P1_0
#define switch P1_5 //switch s6//
#define on 1
#define off 0
void main()
{
P1DIR =0x01;
led1=0;
EA = 0;
/* set main clock source to 32MHz */
SLEEPCMD &= ~0x04;
while(!(SLEEPSTA & 0x40));
delay();
CLKCONCMD &= ~0x47;
SLEEPCMD |= 0x04;
//init_usart();
rf_init();
init_adc();
EA = 1; /* enable global interrupt */

while(1)
{
tx();
delay1();
}
}

void tx()
{

RFST = 0xe3; /* ISRXON */
/* wait for SFD not active and TX_Active not active */
while (FSMSTAT1 & (0x02 | 0x20)); /* TX_ACTIVE | SFD */
RFIRQM0 &= ~0x40; /* disable RXPKTDONE interrupt */
IEN2 &= ~0x01; /* disable general RF interrupts */
RFST = 0xee; /* ISFLUSHTX */
RFIRQF1 = ~0x01; /* clear TXDONE interrupt */
RFD=0x06;
RFD=0x22;
RFD=0xFF;
adc();
RFD=0x00;
RFD=0x00;
/* trun on RX interrupt */
RFIRQM0 |= 0x40;
IEN2 |= 0x01;
RFST = 0xe9; /* ISTXON */
while (!(RFIRQF1 & 0x02)); /* waiting for transmission to finish */
RFIRQF1 = ~0x02; /* clear TXDONE interrupt */

}

void rf_init()
{
FRMCTRL0 |= (0x20 | 0x40); /* AUTO_ACK | AUTO_CRC */
TXFILTCFG = 0x09;
AGCCTRL1 = 0x15;
FSCAL1 = 0x00;
/* enable RXPKTDONE interrupt */
RFIRQM0 |= 0x40;
/* enable general RF interrupts */
IEN2 |= 0x01;
FREQCTRL = 0x0b; /* channel 11 */
SHORT_ADDR0 = 0x04;
SHORT_ADDR1 = 0x00;
PAN_ID0 = 0xFF;/* MUST set, or even can't receive broadcast message */
PAN_ID1 = 0xFF;
RFST = 0xec; /* ISFLUSHRX */
RFST = 0xe3; /* ISRXON */
}
void delay()
{
int i;
for(i=0;i<1;i++);
}

void delay1()
{
int i;
for(i=0;i<500;i++);
}


void init_adc()

{
P1DIR |=0xFF;
P0SEL |= 0xFF; /* Set pin (sample) as GPIO */
P0DIR |= 0x10; /* Set pin as input*/
APCFG |= 0x10; /* configure ADC on pin*/
ADCCON2 |= 0x74; /*This represents the paramters passed into ADCCON2*/
}
void adc()
{
ADCCON1 |=0X40;
while((ADCCON1&&0X80)==0);
{
RFD=ADCH;
RFD=ADCL;
}
}

Reciever programme

#include<iocc2530.h>
void rf_init();
void delay();
void init_usart();
void uartsend();
void main()
{
//EA = 0;
/* set main clock source to 32MHz */
int a;
SLEEPCMD &= ~0x04;
while(!(SLEEPSTA & 0x40));
//delay();
CLKCONCMD &= ~0x47;
SLEEPCMD |= 0x04;

while(1)
{
//RFST = 0xe3;
rf_init();
EA = 1;
/* trun on RX interrupt */
RFIRQM1 |= 0x01;
IEN2 |= 0x01;
RFST = 0xef;
RFST = 0xed;
RFST = 0xe9;
RFST = 0xec; /* ISFLUSHRX */
RFST = 0xe3; /* ISRXON */
while (!(RFIRQF0 & 0x40));


RFIRQF0 = ~0x40; /* interrupt */
RFIRQM1 |= 0x00;
IEN2 |= 0x00;


init_usart();
len=RFD;
for(i=0;i<len;i++)
{
uartsend();
}

RFST=0xD2;
RFST = 0xe3;
RFST = 0xed; /* ISFLUSHRX */
//delay();
}
}


void rf_init()
{
FRMCTRL0 |= (0x20 | 0x40); /* AUTO_ACK | AUTO_CRC */
FRMFILT0 = 0x02;
FRMCTRL1 = 0x00;
TXFILTCFG = 0x09;
AGCCTRL1 = 0x15;
FSCAL1 = 0x00;
/* enable RXPKTDONE interrupt */
RFIRQM0 |= 0x40;
/* enable general RF interrupts */
IEN2 |= 0x01;
FREQCTRL = 0x0b; /* channel 11 */
SHORT_ADDR0 = 0x04;
SHORT_ADDR1 = 0x00;
PAN_ID0 = 0x22; /* MUST set, or even can't receive broadcast message */
PAN_ID1 = 0x00;
}

void init_usart()
{
CLKCONCMD=CLKCONSTA & 0xB8;
while(CLKCONSTA & 0x40);

PERCFG = ~0x01;
P0SEL |= 0x0C; // 0011 1100
U0CSR |= 0xC0;
U0UCR |= 0x00;
U0GCR |= 0x0B;
U0BAUD = 0xD8; // set baudrate 115200
//IRCON2 |=0x02;
//U0CSR |= 0x40;
//IEN2 |= 0x04;
delay();
}

void uartsend()
{
UTX0IF = 0x00;
U0DBUF =RFD;
while(!UTX0IF);
UTX0IF = 0x00;
}
void delay()
{
int i,j;
for(i=0;i<200;i++)
for(j=0;j<25;j++);
}

  PROPER RESULT                                                    

1ST BYTE-06(LENGTH)

2ND BYTE-22(SOURCE ADRESS)

3RD BYTE-FF(BROAD CAST ADRESS)

4TH BYTE-7F(ADCH)

5TH BYTE-34(ADCL)

6TH BYTE-EC(CHECKSUM)

7TH BYTE-6

  INPROPER RESULT(SHIFTED DATA)

1ST BYTE-EC

2ND BYTE-06

3RD BYTE-22

4TH BYTE-FF

5TH BYTE-06

6TH BYTE-22

7TH BYTE-7F

                                                                                           Thanking you

  

  • Hi,

    First of all, due to lack of indentation the code you'he attached is unreadable. Next time you are about to attach some code for us to review, please, either use the "Insert code" option,  or attach it as a .c file.

    Now, to your problem.

    From what I managed to see, several bytes in the incoming packet are overwritten with another set of bytes, hence using a packet sniffer will give you a lot of valuable information, such as is the sender corrupting these packets, or the receiving side.


  • Sorry for the inconvenience ....now i hope you can see the code.... i have attached both transmitter and receiver code ..please do the need full.....
    transmitter programme

    #include <iocc2530.h> void tx(); void rf_init(); void delay(); void delay1(); void adc(); void init_adc(); #define led1 P1_0 #define switch P1_5 //switch s6// #define on 1 #define off 0 void main() { P1DIR =0x01; led1=0; EA = 0; /* set main clock source to 32MHz */ SLEEPCMD &= ~0x04; while(!(SLEEPSTA & 0x40)); delay(); CLKCONCMD &= ~0x47; SLEEPCMD |= 0x04; //init_usart(); rf_init(); init_adc(); EA = 1; /* enable global interrupt */ while(1) { tx(); delay1(); } } void tx() { RFST = 0xe3; /* ISRXON */ /* wait for SFD not active and TX_Active not active */ while (FSMSTAT1 & (0x02 | 0x20)); /* TX_ACTIVE | SFD */ RFIRQM0 &= ~0x40; /* disable RXPKTDONE interrupt */ IEN2 &= ~0x01; /* disable general RF interrupts */ RFST = 0xee; /* ISFLUSHTX */ RFIRQF1 = ~0x01; /* clear TXDONE interrupt */ RFD=0x00;//START OF DELIMITER RFD=0x00; RFD=0x00; RFD=0x00; RFD=0x7A; RFD=0x06;//LENGTH RFD=0x22;//SOURCE ADRESS RFD=0xFF;//BROADCAST ADRESS adc(); RFD=0x00;//CHECKSUM RFD=0x00; /* trun on RX interrupt */ RFIRQM0 |= 0x40; IEN2 |= 0x01; RFST = 0xe9; /* ISTXON */ while (!(RFIRQF1 & 0x02)); /* waiting for transmission to finish */ RFIRQF1 = ~0x02; /* clear TXDONE interrupt */ } void rf_init() { FRMCTRL0 |= (0x20 | 0x40); /* AUTO_ACK | AUTO_CRC */ TXFILTCFG = 0x09; AGCCTRL1 = 0x15; FSCAL1 = 0x00; /* enable RXPKTDONE interrupt */ RFIRQM0 |= 0x40; /* enable general RF interrupts */ IEN2 |= 0x01; FREQCTRL = 0x0b; /* channel 11 */ SHORT_ADDR0 = 0x04; SHORT_ADDR1 = 0x00; PAN_ID0 = 0xFF;/* MUST set, or even can't receive broadcast message */ PAN_ID1 = 0xFF; RFST = 0xec; /* ISFLUSHRX */ RFST = 0xe3; /* ISRXON */ } void delay() { int i; for(i=0;i<1;i++); } void delay1() { int i; for(i=0;i<500;i++); } void init_adc() { P1DIR |=0xFF; P0SEL |= 0xFF; /* Set pin (sample) as GPIO */ P0DIR |= 0x10; /* Set pin as input*/ APCFG |= 0x10; /* configure ADC on pin*/ ADCCON2 |= 0x74; /*This represents the paramters passed into ADCCON2*/ } void adc() { ADCCON1 |=0X40; while((ADCCON1&&0X80)==0); { RFD=ADCH; RFD=ADCL; } } receiver programme
    #include<iocc2530.h>
    void rf_init();
    void delay();
    void init_usart();
    void uartsend();
    void main()
    {
            //EA = 0;
    	/* set main clock source to 32MHz */
            int a;
    	SLEEPCMD &= ~0x04;
    	while(!(SLEEPSTA & 0x40));
    	//delay();
    	CLKCONCMD &= ~0x47;
    	SLEEPCMD |= 0x04; 
    
    while(1)
             {
             //RFST = 0xe3;        
             rf_init();
             EA = 1;
    	 /* trun on RX interrupt */
    	 RFIRQM1 |= 0x01;
             IEN2 |= 0x01;   
             RFST = 0xef;
             RFST = 0xed;
             RFST = 0xe9;
             RFST =  0xec; /* ISFLUSHRX */
    	 RFST = 0xe3; /* ISRXON */
             while (!(RFIRQF0 & 0x40));
                   
            
             RFIRQF0  = ~0x40; /*  interrupt */
             RFIRQM1 |= 0x00;
    	 IEN2 |= 0x00;
    
    
             init_usart();
             len=RFD;         
             for(i=0;i<len;i++)
             {         
             uartsend();
             }
    
             RFST=0xD2;
             RFST = 0xe3;
             RFST =  0xed; /* ISFLUSHRX */
             //delay();
             }
    }
    
    	
    void rf_init()
            {
    	FRMCTRL0 |= (0x20 | 0x40); /* AUTO_ACK | AUTO_CRC */
            FRMFILT0 = 0x02;
            FRMCTRL1 = 0x00;
    	TXFILTCFG = 0x09;
    	AGCCTRL1 = 0x15;
    	FSCAL1 = 0x00;
    	/* enable RXPKTDONE interrupt */
    	RFIRQM0 |= 0x40;
    	/* enable general RF interrupts */
    	IEN2 |= 0x01;
    	FREQCTRL = 0x0b; /* channel 11 */
    	SHORT_ADDR0 = 0x04;
    	SHORT_ADDR1 = 0x00;
    	PAN_ID0 = 0x22; /* MUST set, or even can't receive broadcast message  */
    	PAN_ID1 = 0x00;
            }
    
    void init_usart()
            {
            CLKCONCMD=CLKCONSTA & 0xB8;
            while(CLKCONSTA & 0x40);
            
    	PERCFG = ~0x01;
    	P0SEL |= 0x0C; // 0011 1100
    	U0CSR |= 0xC0;
            U0UCR |= 0x00;
    	U0GCR |= 0x0B;
    	U0BAUD = 0xD8; // set baudrate 115200
            //IRCON2 |=0x02;
    	//U0CSR |= 0x40;
            //IEN2 |= 0x04; 
            delay();
            }
    
    void uartsend()
            {       
            UTX0IF = 0x00;   
    	U0DBUF =RFD;
            while(!UTX0IF);
            UTX0IF = 0x00;   
            }
    void delay()
            {
            int i,j;
            for(i=0;i<200;i++)
            for(j=0;j<25;j++);
            }
    

  • Meanwhile, could you trace the over-the-air traffic, to see if the packets are corrupted by the transmitter or receiver