• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Low Power RF & Wireless Connectivity » Low Power RF Hardware & Tools Forum » CC2510 SPI interface problem
Share
Low Power RF & Wireless Connectivity
  • Forums
  • Announcements
  • Files
  • E2E Wiki
Options
  • Subscribe via RSS

CC2510 SPI interface problem

CC2510 SPI interface problem

This question is answered
LJT
Posted by LJT
on May 15 2012 18:07 PM
Prodigy145 points

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];

  }

}

CC2510 SPI CLOCK debugger IAR EW C programming SCK master slave step through development tools
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • LJT
    Posted by LJT
    on May 31 2012 18:10 PM
    Verified Answer
    Verified by LJT
    Prodigy145 points

    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

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Agie Agie
    Posted by Agie Agie
    on Dec 03 2012 20:58 PM
    Prodigy25 points

    Hi LJT!

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

    Thanks

    Agie

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use