AnsweredAssumed Answered

SPI Slave setup?

Question asked by boris on Apr 22, 2015
I'm trying to setup a STM32F429 as a SPI slave. I have another device transmitting SPI data as a master, and it looks good on the scope + logic analyzer. The STM32F4 never seems to raise the RXNE flag. Any thoughts?
SPI Config function:
void SPI_Slave_Config(){
  GPIO_InitTypeDef GPIO_InitStructure;
  SPI_InitTypeDef SPI_InitStruct;
  /* Enable clocks */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
   /* Connect SPI1 pins to AF */ 
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_SPI1);
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1);
  /* Configure pins for SPI1-PinPack1  PA4-NSS, PA5-SCK, PA6-MISO, PA7-MOSI */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_6 | GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //seperate MOSI and MISO lines
  SPI_InitStruct.SPI_Mode = SPI_Mode_Slave;     // slave mode
  SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b; // one packet of data is 8 bits wide
  SPI_InitStruct.SPI_CPOL = SPI_CPOL_High;        // clock is high when idle
  SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;      // data sampled at first edge
  SPI_InitStruct.SPI_NSS = SPI_NSS_Soft; // set the NSS management to internal
  SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; //  not important for Slave?
  SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;// data is transmitted MSB first
  SPI_Init(SPI1, &SPI_InitStruct);
  SPI_Cmd(SPI1, ENABLE); // enable SPI1
  SPI_NSSInternalSoftwareConfig(SPI1, SPI_NSSInternalSoft_Set); // Set the software NSS
 Main function:
int main(void)
  int i;
  int SPIrx;
  /* Configures LEDs */
    if (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == SET){
      STM_EVAL_LEDOn(LED4); // Application never reaches here!
      SPIrx = SPI1->DR;
    if (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == SET){
      SPI1->DR = 0xAA; // Load dummy data into SPI TX buffer