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.

SPI Communication between msp430 and cc2531 zigbee

Other Parts Discussed in Thread: CC2531, MSP430I2041

am trying tom implement spi communication between msp430i2041 and cc2531 zigbee controller. when iam trying to send a data (suppose 10) from cc2531 to msp am getting values like 5,10,20,40,80 etc instead of excact 10. What may be the possibile reason for this error?? Thanks in advance

  • Hi,

    I would suggest taking a look at the SPI examples provided for the MSP430I2041 in order to troubleshoot your problem.

    dev.ti.com/.../

    Sincerely,
    Sean
  •  i tried with those examples and still d problem exist

  • Hi Ashraf,

    Are you still having issues regarding this? If so, could you please provide us with more details regarding the issue? Are you just sending one byte containing the value 10?

    Perhaps the code you are using to transmit and receive the SPI data would be useful.

    Regards,
    Akash Patel
  • Yes, Iam still facing the issue.. i tried my best but couldn't rectify..actually i am trying to send an 8 bit data from cc2531(master) to msp430(slave).  When i send 0x00 or 0xff i could successfully read at the slave slave, but when i send any other 8 bit value, the bits are getting shifted  at the slave so unable to read it properly.

    Following are the codes of master and slave

     

     

    Master

    void Delay_ms(uint);

    void halLcdSpiInit();

    char Txdata[5];

    void spi_send_data (unsigned char tx_data);

    unsigned char spi_recieve_data(void);

     

    void main(void)
    {

    halLcdSpiInit();

    while(1)
    {

    spi_send_data(0x01);

    }

    }

    void halLcdSpiInit(void)
    {

    PERCFG = 0x00;//usart0, alternate 1
    P0SEL |= 0x2C; // P0_5, P0_4, P0_3, and P0_2 are peripherals

    U0CSR  = 0x00;      // SPI mode, master.

    U0GCR = 0x26;
    U0BAUD = 52;

    }

    void spi_send_data(unsigned char snd_data)
    {

    U0DBUF = snd_data;

    while((U0CSR & (1<<0) )==0);

    }

     

     

    SLAVE

    #include "msp430.h"
    #include <math.h>


    #include "variables.h"

    unsigned char spi_recieve_data(void);

    void spi_send_data(unsigned char tx_data);
    void main(void)

    {

    WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

    /*------------------ Clock-----------------*/

    CSCTL0 = DCOR; // External Resistor
    CSCTL1 = DIVM__1 | DIVS__1; //MCLK = DCO/2, SMCLK = DCO/2

    /*---------------- I/O Ports----------------*/

    P2DIR |= BIT1 + BIT2; // Set P1.4 as output

    P1SEL0 |= BIT5 | BIT6 | BIT7; // eUSCI_B0 Pin Function
    P1SEL1 &= ~(BIT5 | BIT6 | BIT7);
    UCB0CTLW0 = UCSWRST; // **Put state machine in reset**

    UCB0CTLW0 |= UCSYNC | UCMSB | UCMODE_0 | UCSTEM;
    UCB0CTLW0 |= UCSSEL_2; // SMCLK
    UCB0BR0 = 0xaa; // /2


    UCB0BR1 = 0x1a; //

    UCB0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**

    UCB0IE |= UCRXIE;
    UCB0IE |= UCTXIE;

    while(1)
    {

    z = spi_recieve_data();

    }

    unsigned char spi_recieve_data(void)
    {


    unsigned char rcv_data;

    while((UCB0STATW & UCBUSY)==0);

    rcv_data = UCB0RXBUF;

    return rcv_data;

    }

     

  • Hi Ashraf,

    Thanks for providing your code, would you be able to provide any scope shots showing the SPI data lines?

    Regards,
    Akash Patel
  • Please find the attached files. iam sending data from master to slave only. So i have data only in the MOSI Pin

    Thank you

  • Hi Ashraf,

    It appears that your data is transmitting properly from the master. Your clock seems to be high when inactive so you will want the UCCKPL bit (in register UCB0CTLW0) to be high. Therefore, in your slave code you want to add that in there. Please give this a try and let me know what happens.

     // Configure eUSCI_B0 for SPI operation
        UCB0CTLW0 = UCSWRST;                    // **Put state machine in reset**
        UCB0CTLW0 |= UCSYNC | UCCKPL | UCMSB;   // 3-pin, 8-bit SPI slave
                                                // Clock polarity high, MSB

    Regards,

    Akash Patel

  • Hi Ashraf,

    We haven't heard from you in a couple weeks. I will be closing the thread, feel free to reply if you have any additional questions regarding this and I will reopen the thread; otherwise, please hit "Verify Answer" if your problem was solved.

    Regards,
    Akash Patel
  • still its not working. but its working fine when i send the data with some time delay in between (aroung 25ms) instead of sending it continuously.

  • Hi Ashraf,

    What frequency are you running your SPI CLK? What happens if you try to reduce the speed, are you still getting issues?

    Regards,
    Akash Patel
  • Iam running at the lowest speed. 2.4KHz (2400 Baud rate)

  • Hi Ashraf,

    Instead of the char spi_recieve_data(void) function, try using an ISR to receive the data into your z variable.

    Here is an example of that: dev.ti.com/.../

    Regards,
    Akash Patel

**Attention** This is a public forum