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.

MSP430F2013 IAR Embedded Workbench Problem



Hello,

I am trying to compile the msp430x20x3_usi_05.c, but I keep getting errors with the CS variable. I am using the latest kickstart IAR embedded workbench

 
IAR C/C++ Compiler for MSP430
5.20.1 [Kickstart] (5.20.1.30214)

 

Error[Pe020]: identifier "CS" is undefined

//******************************************************************************
//  MSP430F20x2/3 Demo - USI SPI Interface to TLC549 8-bit ADC
//
//   Description: This program demonstrates the USI in SPI mode interface to a
//   TLC549 8-bit ADC. If AIN > 0.5(REF+ - REF-), P1.0 set, else reset.
//   ACLK = n/a, MCLK = SMCLK = default DCO, UCICLK = SMCLK/4
//   //** VCC must be at least 3v for TLC549 **//
//
//                          MSP430F20x2/3
//                       -----------------
//                   /|\|              XIN|-
//        TLC549      | |                 |
//    -------------   --|RST          XOUT|-
//   |           CS|<---|P1.1             |
//   |      DATAOUT|--->|P1.7/SOMI    P1.0|-->LED
// ~>|AIN   I/O CLK|<---|P1.5/SCLK        |
//
//  M. Buccini / L. Westlund
//  Texas Instruments Inc.
//  October 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.40A
//******************************************************************************

#include <msp430x20x3.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P1OUT = 0;
  P1DIR |= 0x03;
  USICTL0 |= USIPE7 + USIPE5 + USIMST + USIOE; // Port, SPI master
  USICTL1 |= USIIE;                         // Counter interrupt, flag remains set
  USICKCTL = USIDIV_2 + USISSEL_2;          // /4 SMCLK
  USICTL0 &= ~USISWRST;                     // USI released for operation
  USICNT = 8;                               // init-load counter
  _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0 w/ interrupt

  
    char value;
   
    P1OUT &= ~CS;                    //Enable slave
    USISRL = RDSR;                    //Load transmit buffer with op code
                                    //for reading status register
    USICTL1 &= ~USIIFG;                 //Clear the interrupt flag
    USICNT=0x08;                    //Tx the data

    while((USICTL1 & USIIFG) != 0x01);        //Wait for Tx completion

    USICTL1        &=    ~USIIFG;         //Clear the interrupt flag
    USISRL = 0xFF;
    USICNT=0x08;                    //Read 8 bits
    while((USICTL1 & USIIFG) != 0x01);        //Wait for Rx completion
   
    value = USISRL;
   
    return value;
}

  • Hi Steven,

    The problem is that in your code file the symbol "CS" is not defined and the compiler can't use it.  In the diagram in the file comments the CS of the slave is driven from the MSP pin P1.1 so you should define the symbol CS as BIT1:

    #include <msp430x20x3.h>

    #define CS BIT1

    void main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    P1OUT = 0;
    P1DIR |= 0x03;

    .... the rest of the code .....

    P1OUT &= ~CS;

    .... the rest of the code .....
    }

    Now the code should compile ok (although declaring the char value halfway through the code and returning a value from a void function might throw warnings/problems).

     

    Regards,

    Chris

  • Another thing worth mentioning:

    Unless you have changed the ISR from the sample code, the extra code you have added may not actually ever be executed.  The command "_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt" will enter low power mode 0 but unless the ISR forces exiting the low power mode none of the later commands will ever be executed.  Adding "LPM0_EXIT" to the end of the ISR and should resolve this.

     

    Regards,

    Chris.

  • Chris,

    Thank you very much! This is my first time working with TI products. You actually anticipated my next question with the LMP0, while debugging I would stop there in the code.

    Thanks for the help. I will fix the errors.

    -Steven

**Attention** This is a public forum