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.

CC2510 SPI interface problem

Other Parts Discussed in Thread: CC2510

Hello Texas Instruments!

I am still having problems configuring my SPI communication between the TI CC2510 (master device) and a third party ASIC (slave device).  I need to be able to send a series of commands from the master to slave device to configure the slave device and begin reading data from it.  I would like to step through my code line by line or step through major sections of code and then stop and examine the response I get from the slave device using the development tools within IAR EW v7.60.1 (eg. watch variables, monitor registers).  The problem is that IAR claims that if you are stepping through the code using the debugger, you will not get a serial clock output because the debugger is halting the normal execution of the program.  How do you step through the code using the debugger and still get a serial clock output (from the TI CC2510) so I can examine the response from the slave device and work out any software bugs?  Is there another approach to take to step through the code, still have access to my development tools within IAR, and still have my serial clock running?  My code follows:

__________________________________________________________________________________________________________________________________________

* CONSTANTS*/

// Define size of buffer and number of bytes to send

#define BUFFER_SIZE 0x04

*********** LOCAL VARIABLES*/

// Masters's transmit and receive buffer

static uint8 txBufferMaster[BUFFER_SIZE];

static uint8 rxBufferMaster[BUFFER_SIZE];

static uint8 read_array[BUFFER_SIZE];

static uint8 write_array[0x02];

static uint8 response_from_read;

static uint8 response_from_write;

/********LOCAL FUNCTIONS*/

void read(uint8 ptr_read_array[], uint8 address);

void write(uint8 ptr_write_array[], uint8 address, uint8 response);

void spi_master_receive(uint8 ptr_txBufferMaster[], uint8 ptr_rxBufferMaster[]);

void spi_master_transmit(uint8 ptr_txBufferMaster[], uint8 ptr_rxBufferMaster[]);

void copy_array(uint8 ptr_array_A[], uint8 ptr_array_B[]);

int main(void)

{

                // Configure USART1 for Alternative 2 location => Port P1 (PERCFG.U1CFG = 1)

                PERCFG |= 0x02;    //PERCFG.U1CFG = 1

                P1SEL |= 0xE0;    //P1_7, P1_6, and P1_5 are set up as peripherals

                P1SEL &= ~0x1F;   //P1_4, P1_3, P1_2, P1_1, P1_0 are set up as general purpose I/O

                P1DIR |= 0x1D;    //P1_4 is output, P1_3 is output, P1_2 is output,

                                                 //P1_1 is input, P1_0 is output

                P2SEL |= 0x40;    //Give priority to USART1 over USART0 for port 1 pins

                                                //Give priority to USART1 over Timer 3 for port 1 pins

                                                //Give priority to Timer 1 over Timer 4

                                                 //Give priority to USART0 over Timer 1

                /***************************************************************************

                 * Configure SPI1

                */

  

                SLEEP &= ~SLEEP_OSC_PD;

                while(!(SLEEP & SLEEP_XOSC_S));   //monitor XOSC stable status bit

                CLKCON = 0x00; //select HS crystal oscillator & system clock source to 26 Mhz

                // Set USART to SPI mode and Master mode

  

                U1CSR &= ~0xA0;

                // Set Baud Rate (SCK frequency) equal to 9596 bps for a 26 MHz system clock

                // (high speed crystal oscialltor)

 

                U1BAUD = 0x83;    // BAUD_M = 131

                U1GCR |= 0x08;    // BAUD_E = 8

    

                 // - negative clock polarity (SCK low when idle)

                 // - clock phase for data centered on second edge of SCK period

                 // - bit order for transfers to MSB first

  

                 U1GCR |= 0x60;    // CPOL = 0, CPHA = 1, ORDER = 1

                ***************************************************************************

                * Transfer data

                 */

  

                 do

                 {

read(read_array, 0x02);   // prepare read payload

         copy_array(txBufferMaster, read_array); // copy read payload to txBufferMaster

                  spi_master_receive(txBufferMaster, rxBufferMaster); //read Status1 register (0x02) on slave device

                           response_from_read = rxBufferMaster[3];

                }while(!response_from_read == 0x08);

 

                response_from_read = response_from_read & 0x04;  //modify value using logical operators to clear bit 3 (SW_CC)

                write(write_array, 0x02, response_from_read); // prepare write payload

                copy_array(txBufferMaster, write_array);  // copy write payload to txBufferMaster

  

                do

                 {

spi_master_transmit(txBufferMaster, rxBufferMaster); //write to Status1 register (0x02) on slave device

response_from_write = rxBufferMaster[1];

                }while(!response_from_write == 0xFB);

                  

                return 0;

}

/* read() definition */

void read(uint8 ptr_read_array[], uint8 address)

{

  ptr_read_array[0] = 0xA0 | address;

  ptr_read_array[1] = 0xFB;

  ptr_read_array[2] = 0xFB;

  ptr_read_array[3] = 0xFB;

}

/* write() definition */

void write(uint8 ptr_write_array[], uint8 address, uint8 response)

{

  ptr_write_array[0] = 0x80 | address;

  ptr_write_array[1] = response;

}

    

/* spi_master_transmit() definition */

void spi_master_transmit(uint8 ptr_txBufferMaster[], uint8 ptr_rxBufferMaster[])

{

  // Set SSN to active low

  P1_4 = 0;

  int i;

  for (i = 0; i < BUFFER_SIZE/2; i++)

  {

       // Write byte to USART1 buffer (transmit data)

       U1DBUF = ptr_txBufferMaster[i];

       // Check if byte is transmitted (and a byte is recieved)

       while(!(U1CSR & U1CSR_TX_BYTE)) { asm("NOP");}

       // Clear transmit byte status

       U1CSR &= ~U1CSR_TX_BYTE;

       // Write received byte to buffer

       ptr_rxBufferMaster[i] = U1DBUF;

  }

  // Set SSN to active high

  P1_4 = 1;

  // When finished transmitting, set green LED

  P1_0 = 0;   // Set SRF04EB LED1

}

/* spi_master_receive() definition */

void spi_master_receive(uint8 ptr_txBufferMaster[], uint8 ptr_rxBufferMaster[])

{

  // Set SSN to active low

  P1_4 = 0;

  int i;

  for (i = 0; i< BUFFER_SIZE; i++)

  {

       // Write byte to USART1 buffer (transmit data)

       U1DBUF = ptr_txBufferMaster[i];

       // Check if byte is transmitted (and a byte is recieved)

       while(!(U1CSR & U1CSR_TX_BYTE)) { asm("NOP");}

       // Clear transmit byte status

       U1CSR &= ~U1CSR_TX_BYTE;

       // Write received byte to buffer

       ptr_rxBufferMaster[i] = U1DBUF;

  }

  // Set SSN to active high

  P1_4 = 1;

  // When finished transmitting, set green LED

  P1_0 = 0;   // Set SRF04EB LED1

}

/* copy_array() definition */

void copy_array(uint8 ptr_array_A[], uint8 ptr_array_B[])

{

  int i;

  for (i = 0; i< BUFFER_SIZE; i++)

  {

      ptr_array_A[i] = ptr_array_B[i];

  }

}

  • Hi TI Community!

    The solution that worked for me was to 'step over' the subroutines that were transferring data via SPI protocol.  The 'step over' command in IAR EW v7.60 will execute all the instructions in the subroutine without halting the program clock.  It then brings you to the next statement after the subroutine was called and then halts the program clock.  This allowed the master device to provide the 8 bits of SCK data necessary to clock the slave and receive a response.  I was then able to monitor the response back from the slave using the watch window in IAR EW. 

    Happy programming,

    LJT

  • Hi LJT!

    Could you please share your working SPI code. I need to use SPI to read Invensense MPU6000 IMU by CC2510.

    Thanks

    Agie