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.

CC2420 Data Transmit problem

Other Parts Discussed in Thread: CC2420, Z-STACK

Hi, I'm using CC2420DB that consists of CC2420 and ATmega128L.

I want to transmit data which is read from temparature sensor.

I made a very simple test program refered to the SamleApp source in Z-Stack.

SPI communications work well and confirmed by the oscilloscope.

But packets are not detected by packet sniffer.

I transmited command strobes in procedure like below.

1. SXOSCON

2. STXCAL

3. STXON

Is there another command required?

Here is my code. (I used WinAVR compiler and AVR Studio 4)

 

#include <avr/io.h>
#include <avr/interrupt.h>

#define TurnOn_Crystal 0x01 // Command Strobe : SXOSCON
#define Enable_FrequencySynthesizer 0x02 // Command Strobe : STXCAL
#define Enable_TX 0x04 // Command Strobe : STXON
#define Disable_RX_TX_FrequencySynthesizer 0x06 // Command Strobe : SRFOFF
#define TurnOff_Crystal 0x07 // Command Strobe : SXOSCOFF
#define Flush_TXFIFO_Register 0x09 // Command Strobe : SFLUSHTX

#define TXFIFO 0x3E // address of TXFIFO

void TransmitData(unsigned char, unsigned char); // data transmit

void TransmitCommand(unsigned char); // command transmit

int main(void) {
MCUCR = 0x00;

DDRB = 0b11100111;
PORTB = 0b00100001; // VREG_EN = 1, CSn = 1

DDRD = 0b00000000;

SPCR = 0b11010000;
SPSR = 0b10000001;
TransmitCommand(TurnOn_Crystal);


TransmitCommand(Enable_FrequencySynthesizer);


TransmitCommand(Enable_TX);



while(1) {

TransmitData(TXFIFO, 0x55); // for only test

// 0x55 is not detected by packet sniffer (Channel is 2,405 MHz)
}

return 0;
}

void TransmitData(unsigned char Address, unsigned char Data) {
PORTB &= 0b11111110; // CSn = 0
SPDR = Address;
while(!(SPSR & 0x80));
SPDR = Data;
while(!(SPSR & 0x80));
PORTB |= 0b00000001; // CSn = 1
}

void TransmitCommand(unsigned char Address) {
PORTB &= 0b11111110; // CSn = 0
SPDR = Address;
while(!(SPSR & 0x80));

PORTB |= 0b00000001; // CSn = 1
}

Please reply to the question as soon as possible. Thanks.

  • It doesn't look like you are waiting for the crystal oscillator to stabilize before enabling the frequency synthesizer.  Note in section 13.4 of the spec sheet, the second paragraph tells you to wait for the crystal oscillator to stabilize before any other commands can be sent.  You do this by sending the SNOP command and checking the status byte returned for the XOSC16M_STABLE bit to go high.

    Jim Noxon

  • Hi, Noxon.

    Thank you for replying me.

    As you mentioned, I added delay functions after SXOSCON command, like this.

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

    #include <avr/io.h>
    #include <avr/interrupt.h>

    #define SNOP  0x00 // No operation
    #define SXOSCON  0x01 // Turn on crystal
    #define STXCAL  0x02 // Enable frequency synthesizer
    #define SRXON  0x03 // Enable RX
    #define STXON  0x04 // Enable TX

    #define TXFIFO  0x3E // TX Register
    #define RXFIFO  0x3F // RX Register

    void TransmitData(unsigned char, unsigned int); 
    void TransmitCommand(unsigned char);  
    void InitializeSPI(); 

    unsigned char StatusByte; 
                        
    int main(void) {
        MCUCR = 0x00;

        DDRB   = 0b11110111;
        PORTB  = 0b00100001;       // VREG_EN = 1, CSn = 1

        DDRD = 0b00000000;

        DDRE = 0b00011000;

        InitializeSPI();
        delay_ms(5000);       // Delay for starting-up Regulator (0.6ms required)

        LED(YELLOW, ON); 

        TransmitCommand(SXOSCON);
        delay_ms(5000);      // Delay for starting-up Crystal (1.0ms required)

        TransmitCommand(SNOP);
        StatusByte = SPDR;
        while(SPDR & 0b01000000);    // Check whether if XOSC16M_STABLE bit is high

        LED(YELLOW, OFF);

        LED(GREEN, ON);     // Because the green LED turns on, I think the oscillator is stable. 

        TransmitCommand(STXCAL);
        delay_ms(100);

        TransmitCommand(STXON);
        delay_ms(100);

        while(1) {
            TransmitData(TXFIFO, 0x55);     // But the data isn't still detected by Packet Sniffer.
            delay_ms(100);
        }

        return 0;
    }

    void TransmitCommand(unsigned char Address) {
        PORTB &= 0b11111110;       // CSn = 0;

        SPDR = Address; 
        while(!(SPSR & 0x80));

        PORTB |= 0b00000001;       // CSn = 1;
    }

    void TransmitData(unsigned char Address, unsigned int Data) {
        PORTB &= 0b11111110;       // CSn = 0;

        SPDR = Address;       
        while(!(SPSR & 0x80));

        SPDR = Data;
        while(!(SPSR & 0x80));

        PORTB |= 0b00000001;       // CSn = 1
    }

    void InitializeSPI(void) {
     PORTB |= 0b00000001;       // CSn = 1

     SPCR  = 0b01010000;   // SPE = 1, MSTR = 1

     SPSR  = 0b00000001;  // SPI2X = 1
    }

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

    But I can't still transmit data. :-(

    I think that the delay is enough to stablize oscillator. (I read the manual of CC2420 and found Crystal oscillator start-up time in Page 12 of 89. It is just 1.0 ms)

    I trasmitted SNOP command and checked status byte by using LEDs. XOSC16M_STABLE bit was high.

    But the data isn't still detected by Packet Sniffer.

    Did I something else wrong?

    Regards,

    Young-hwan Joo.

  • Here is an example of a CC2420 halRfInit.c:

    uint8 halRfInit(void)
    {
        // Make sure that the voltage regulator is on, and that the reset pin is inactive
        SET_VREG_ACTIVE();
        halMcuWaitUs(VREG_SETTLE_TIME_USECS);
        SET_RESET_ACTIVE();
        halMcuWaitUs(100);
        SET_RESET_INACTIVE();
        halMcuWaitUs(RESET_RELEASE_SETTLE_TIME_USECS);

        // Register modifications
        cc2420Strobe(CC2420_SXOSCOFF);
        cc2420Strobe(CC2420_SXOSCON);

        cc2420WriteReg(CC2420_MDMCTRL0, 0x0AF2); // Turn on automatic packet acknowledgment
        cc2420WriteReg(CC2420_MDMCTRL1, 0x0500); // Set the correlation threshold = 20
        cc2420WriteReg(CC2420_IOCFG0,   0x007F); // Set the FIFOP threshold to maximum
        cc2420WriteReg(CC2420_SECCTRL0, 0x01C4); // Turn off "Security enable"

        // Wait for XOSC stable to be announced on the MISO pin
        if (halRfWaitRadioReady()==FAILED)
            return FAILED;

        return SUCCESS;;
    }

    Here are some macros for MSP430:


    // The CC2420 VREGen pin
    #define SET_VREG_ACTIVE()               CC2420_VREG_EN_OPIN(1)
    #define SET_VREG_INACTIVE()             CC2420_VREG_EN_OPIN(0)

    // The CC2420 reset pin
    #define SET_RESET_INACTIVE()            CC2420_RESET_OPIN(1)
    #define SET_RESET_ACTIVE()              CC2420_RESET_OPIN(0)

    void cc2420Strobe(uint8 s)
    {
        CC2420_SPI_BEGIN();
        _CC2420_SPI_TX(s);
        CC2420_SPI_END();
    }

    // SPI register definitions
    #define CC2420_SPI_TX_REG               (U1TXBUF)
    #define CC2420_SPI_RX_REG               (U1RXBUF)
    #define CC2420_SPI_RX_IS_READY()        (IFG2 & URXIFG1)
    #define CC2420_SPI_RX_NOT_READY()       (IFG2 &= ~URXIFG1)
    #define CC2420_SPI_TX_IS_READY()        (IFG2 & UTXIFG1)
    #define CC2420_SPI_TX_NOT_READY()       (IFG2 &= ~UTXIFG1)

    // SPI access macros
    #define CC2420_SPI_BEGIN()              st( CC2420_CSN_OPIN(0); )
    #define CC2420_SPI_TX(x)                st( IFG2 &= ~URXIFG1; U1TXBUF= x;)
    #define CC2420_SPI_RX()                 (U1RXBUF)
    #define CC2420_SPI_WAIT_RXRDY()         st( while (!CC2420_SPI_RX_IS_READY()); )
    #define CC2420_SPI_END()                st( CC2420_CSN_OPIN(1); )

    #define SPI_ENABLE()                    CC2420_SPI_BEGIN()    // ENABLE CSn (active low)
    #define SPI_DISABLE()                 CC2420_SPI_END()      // DISABLE CSn (active low)

    #define SPI_WAITFOREOTx()             st( while (!CC2420_SPI_TX_IS_READY()); ) // USART1 Tx buffer ready?
    #define SPI_WAITFOREORx()             CC2420_SPI_WAIT_RXRDY()  // USART1 Rx buffer ready?

    I hope this helps.

    LPRF Rocks the World

  • Hi ,

    Could u please help me to make point to point communication using cc2420MSP430ZDK. I also need z-stack for cc2420+MSP430. I appreciate your kind help.