This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SPI Init SPI_NSS compiler error

I'm using the Keil MCBSTM32 (STM32F103RBT6) and Keil uVision 4.21.0.0. The startup file is "startup_stm32f10x_md.s". I'm trying to setup SPI1 and I'm getting a compiler error on the line "SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;":

error: #134: expected a field name

If I comment that line, there are no errors. I've used this code in the past for a different project and didn't have any problems (with older versions of uVision and the STM32 peripheral library). Any ideas?

#define SPI_NSS         GPIO_Pin_4      // SPI nSS
#define SPI_SCK         GPIO_Pin_5      // SPI Clock
#define SPI_MISO        GPIO_Pin_6      // SPI MISO
#define SPI_MOSI        GPIO_Pin_7      // SPI MOSI


void SetupMEMS(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        SPI_InitTypeDef SPI_InitStructure;

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE);     // enable peripheral clocks

        GPIO_InitStructure.GPIO_Pin = SPI_SCK | SPI_MISO | SPI_MOSI;    // Configure SCK, MISO, MOSI
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;               // 2/10/50 MHz
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;                 // AF (Alternate Function)for SPI use
        GPIO_Init(GPIOA, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin = SPI_NSS;                  // Configure NSS as Output push-pull
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;       // 2/10/50 MHz
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_Init(GPIOA, &GPIO_InitStructure);

        // SPI configuration
        SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;      // send/recv simul
        SPI_InitStructure.SPI_Mode = SPI_Mode_Master;                           // we are master
        SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;                      // 16-bit xfers
        SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
        SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
        SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;                               // compiler error #134 ???
        SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;      // 9 MHz
        SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
        SPI_InitStructure.SPI_CRCPolynomial = 7;
        SPI_Init(SPI1, &SPI_InitStructure);         // Init SPI
        SPI_Cmd(SPI1, ENABLE);                          // Enable SPI
}

0