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.

ez430-rf2500 spi interface

Other Parts Discussed in Thread: CC2500, SIMPLICITI, CC1100, MSP430F2274

Dear all, 

I am a final year student  of undergraduation.  my project involves setting up of a Wireless sensor network . For this i am using the EZ430-RF2500 kit.
I have been using it now for almost a week and i am facing a few problems regarding the SPI interface, I tried to write my own code to interface  msp4302274 and cc2500. i have extensively searched for help in the internet and the e2e community but havent got my problem solved yet. But it would be helpful, if someone could help me with it. 
with the following code, i am able to write data into cc2500(i am not sure of that either but am able to see the signals in the oscilloscopeand the values change in the registers window when i debug the code in ccsv4) and i am also getting back some values in the UCSB0RXBUF, but the values were initially 0x0f, which is a valid status signal.... but now it is giving me erratic values. Also i have no success in reading back even a single registers value. 
Pls help me.
#include "msp430x22x4.h"
//#include "CC2500.h"
unsigned int data[10];
unsigned int n= 0;
void main(void)
{
volatile unsigned int i = 0;
volatile unsigned int j = 0;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x03; // P1.0 output for LED
P2DIR |= 0x00; // P2.6,7 are inputs gdo0,gdo2
P3SEL |= 0x0e; // P3.0,1,2,3 USCI_B0 option select
UCB0CTL0 = 0x29; // Phase = 0, Pulse is inactive low, MSB first, 8-bit, Master mode, 4 pin SPI, SPI sync
UCB0CTL1 = 0x81; // Use SMCLK and stop the USCI
UCB0BR0 = 0x02; // Clock divide low byte
UCB0BR1 = 0x00; // Clock divide high byte
UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
P1OUT = 0x01;//SWITCH ON LED 
P3OUT = 0x01; // CSn HIGH
for (i = 0; i < 0xFFFF; i ++); // wait
P3OUT = 0x00; // CSN LOW TO START OPERATION
while (!(IFG2 & UCB0TXIFG)); //Check to see if the send buffer is empty
UCB0TXBUF = 0x30; //send the command -- TO RESET CC2500
while (!(IFG2 & UCB0TXIFG)); //Check to see if the send buffer is empty
P3OUT = 0x01; // CSN HIGH 
P3OUT = 0x00; // CSN LOW  NEXT CYCLE 
while (!(IFG2 & UCB0TXIFG)); //Check to see if the send buffer is empty
UCB0TXBUF = 0x09; //send the command -- TRYING TO write addr register JUST SET
while (!(IFG2 & UCB0TXIFG)); //Check to see if the send buffer is empty
UCB0TXBUF = 0x05; //send the command -- TRYING TO write into addr REGISTER
while (!(IFG2 & UCB0TXIFG)); //Check to see if the send buffer is empty 
P3OUT = 0x01; // CSN HIGH
P3OUT = 0x00; // CSN low
while (!(IFG2 & UCB0TXIFG)); //Check to see if the send buffer is empty
UCB0TXBUF = 0x89; //send the command -- TRYING TO READ addr REGISTER JUST SET
while (!(IFG2 & UCB0RXIFG));
data[n++]= UCB0RXBUF;
//while (!(IFG2 & UCB0TXIFG)); //Check to see if the send buffer is empty
//UCB0TXBUF = 0x3d; //send the command snop--- no operation should i use this ppiece of code ?? 
//while (!(IFG2 & UCB0RXIFG));
//data[n++]= UCB0RXBUF ;
for (i = 0; i < 0xFFFF; i ++); // wait FOR TRANSMISSION TO COMPLETE AND RXBUF TO RECIEVE
P3OUT = 0x01; // CSN HIGH
P1OUT |= 0x00; // Turn LED on
while (1) ; //Stop for review
}
I have also tried modelling reception as interrupts but in still am not able to read register value.Pls tell me whr i am going wrong 
Also pls tell me whr i can get some simple sample codes  for radio link testing. I went through slaa325.zip, simpliciTI and another packages but they seem to be a littile fussy for a beginner.My project in the end involves implementation of a simple multihop routing protocol. so it would be really helpful if i could get some sample programs for radio link testing. 
 

  • An additional resource for sample code for SPI and CC2500 register access is to look at "AN049 - Software for CC1100/CC2500 and MSP430 - Examples and function library" (swra141 -- read abstract here). It is not written for the eZ430-RF2500, but you should be able to re-use the code and port it to your MSP430F2274 without too much work.

  • One general thing about SPI: checking for the TXIFG flag only indicates that the transmit buffer is ready for a new data byte. It does not mean that the last byte has been sent. It is still in the oputput shift register and being sent when TXIFG is flagged.

    You should check for RXIFG coming up, as this happens when the last bit a synchroneously incoming byte has been received and therefore the last bit of the outgoing shift register has been sent. If you deselect the slave CD line, you disable its receiver before it got the last byte. Unfortunately stuffing the TX register and getting RXIFG flagged overlaps (as there is always one more byte in the queue). So either you wait until you received a byte after stuffing TXBUF, which wastes some time as the sending chain is interrupted for some MCLK cycles, or you have to disable interrupts and carefully align the process. But this is only necessary if you have to transfer large amounts of data and/or running the SPI at maximum clock (>=MCLK)

    The question 'should I send the NOP' can only be answered with a clear YES. If you're not sending anything, you don't receive anything. SPI is synchroneous. One bit sent is one bit received. And one bit to receive requires one bit sent. By sending a dummy byte (such as a NOP code) you're at the same time receiving the answer to your last command. Also, keep in mind that teh bytes you receive are the bytes requested by the previous command. It's not a 'send a command and receive an answer' but rather 'send a command and simultaneously receive the answer to the previous'. This is completely different to the UART mode, where you send something and will eventually receive something. Or the I2C mode, where sending and receiving is controlled by the addressing mode and only one or the other is happening at the same time in a controlled order.

    P.s.: you can also check for UCxySTAT&UCBUSY if you want to know whether sending (and receiving) is actually finished in master mode.

     

     

  • Hi ever one

    i am final year student ,i doing my final year project "Remote Monitoring Systems " .i am using AD7763 and eZ430-Rf2500T,i am try to communicate wth SPI..

     

    i am finding  difficult write code for spi..is there any chance to help me out in this..i used the sample code but still not geting any answer.

    AD7763 is got 4 spi 

     

    thankx

  • SPI is quite simple (as long as you're master) and straightforward. Once you understood how SPI works.

    The mistake most newbies make is that SPI work quid pro quo. That means, to get a byte you have to send a byte. Even if it is a dummy. And when you send a byte, you'll get a byte (even if it is a dummy). if you don't send something, you will never get something.

    The second problem most people have is to understand when what happens. Caused by the double-buffering inside the SPI hardware. When you write a byte, it is moved from the TX buffer into the output shift register and the TX buffer is immediately free again. So the write side is always up to 2 bytes ahead of the receiving side.

    Third cornerstone is the addressing of the slave. You'll need a separate IO line to address msot slaves. This line resets the protocol, synchronizes the byte transfers (there are not startbits or stopbits as on RS232) and ends the protocol (or even interrupts it).

    The rest (inlcuding the SPI setup ) is easy:

    • setup the hardware (port pins, baudrate, if necessary the clock polarity and the idle line level)
    • select the slave using the I/O pin
    • start sending and receiving
    • wait for the last byte being sent/received
    • deselect the slave

    Implementing the slaves data protocol, hopwever, might prove a bit more difficult (e.g. talking to an SD card)

**Attention** This is a public forum