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.

MSP430F5529: SPI Communication with CC2500 - Not receiving proper data

Part Number: MSP430F5529
Other Parts Discussed in Thread: CC2500

Tool/software:

Hello guys im in need of help, im trying to read the chip ID of the CC2500 module (shown bellow) via SPI communication to further down the line use it. 

This is the write and read operations for the CC2500:




This is the code to try and read and write to the CC2500: the P1.0 LED never turns on

#include "intrinsics.h"
#include "msp430f5529.h"
#include <msp430.h>
#include "msp430f5xx_6xxgeneric.h"
#include <stdint.h>

uint8_t Dados = 0x00;

void send();

void read();

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  
  P1DIR |= 0x01;                            // P1.0 output
  P4DIR |= BIT7;                           // P4.7 output

  // LED desligados
  P1OUT &= ~BIT0;
  P4OUT &= ~BIT7;

  // SPI init - UCB0
  UCB0CTL1 |= UCSWRST;

  UCB0CTL0 |= UCMST + UCSYNC + UCMODE_0; // Master mode + Slave enabled - CS low

  UCB0CTL1 |= UCSSEL_3; // SMCLK

  // Bit rate
  UCB0BR0 = 1;
  UCB0BR1 = 0;

  // Port SPI init - 3.0, 3.1, 3.2 e 2.7
  P3SEL |= BIT0 + BIT1 + BIT2;
  P2DIR |= BIT7;
  P2OUT |= BIT7;

  //UCB0IE |= UCTXIE + UCRXIE;
  

  UCB0CTL1 &= ~UCSWRST;

  //__bis_SR_register(GIE);       // enable interrupts
  send();

  while (1)
  {

    read();

    // Verificar leitura do registo - ID do modulo RF
    if (Dados == 0x80)
    {
      P4OUT |= BIT7;
      //__delay_cycles(160000);
    }
    else
    {
      P4OUT &= ~BIT7;
      //__delay_cycles(160000);

    }
  }
}

void send()
{
  P2OUT &= ~BIT7;
  __delay_cycles(50);

  while(!(UCB0IFG & UCTXIFG));
  UCB0TXBUF = 0x30;

  P2OUT |= BIT7;
}

void read()
{
  //UCB0IFG &= ~(UCTXIFG + UCRXIFG);
  
  //UCB0IE |= UCRXIE;

  P2OUT &= ~BIT7;
  __delay_cycles(50);

  while(!(UCB0IFG & UCTXIFG));
  UCB0TXBUF = 0xC0 | 0x30;
  
  while(!(UCB0IFG & UCRXIFG));
  volatile uint8_t dummy = UCB0RXBUF;

  while(!(UCB0IFG & UCTXIFG));
  UCB0TXBUF = 0x00;
  while(!(UCB0IFG & UCRXIFG));
  Dados = UCB0RXBUF;

  P1OUT |= BIT0;

  //__bis_SR_register(GIE);
  //__bis_SR_register(LPM0_bits + GIE);
  //__no_operation();
  P2OUT |= BIT7;
}


This is what i see on the logic analyzer:


If anyone could help me to try and figure out whats wrong i would gladly appreciate it thank you!

  • The CC2500 does SPI msb first. You haven't configured the MSP430 for that.

    Your read code is going to fail because of the set RXIFG left over from send().

    For polled I/O of SPI modes I prefer to use a simple read/write function instead of spreading TXIFG polls throughout my code.It transmits a byte and returns whatever data was received. It is very simple. Write data to TXBUF. (No need to poll TXIFG if this is the only way you access TXBUF.) Wait for RXIFG. Read and return RXBUF.

  • In addition to what David mentioned:

    > UCB0CTL0 |= UCMST + UCSYNC + UCMODE_0; // Master mode + Slave enabled - CS low

    Data sheet (SWRS040C) Fig 7 suggests the CC2500 expects CPHA=0. UCCKPH is defined opposite to CPHA, so try instead:

    > UCB0CTL0 |= UCMST + UCMSB + UCCKPH + UCSYNC + UCMODE_0; // Master mode, MSB first, CPHA=0, (CPOL=0)

  • Thank you David this helped me! I got it working now!

  • Thank you Bruce this also helped me! I got it to work now! Think this was the reason sometimes it got stuck in communication... Thank you very much!

**Attention** This is a public forum