AnsweredAssumed Answered

SPI_I2S_FLAG_TXE flag doesn't clear, SPI init done right?

Question asked by beidler.geoff on Sep 13, 2012
Latest reply on Sep 14, 2012 by waclawek.jan
I'm tring to set up SPI2 as a master SPI device to communicate with another device.  After configuring the clocks, GPIO and SPI device, I wait for SPI_I2S_FLAG_TXE to clear before writing.  But the flag never clears, so I'm stuck.  I took this code as close as possible from the examples included with the peripheral library.  I'm not sure if I'm missing any other setup steps.

static void InitSPI( void )
   GPIO_InitTypeDef GPIO_InitStructure;
   SPI_InitTypeDef  SPI_InitStructure;
   // PCLK2 = HCLK / 2
   // Enable GPIO clock for SPI2
   RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
   RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE );

   //Allocate GPIO pins to SPI interface

   //Initialize GPIO config struct
   //Pins B13 and B15
   GPIO_InitStructure.GPIO_Pin = ( GPIO_Pin_13 | GPIO_Pin_15 );
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

   //Pins B14
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

   //Configure SPI bus
   //Initialize SPI config struct

   //Set SPI config struct
   SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
   SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
   SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
   SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; // idle logic low
   SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // capture on falling edge
   SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
   SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
   SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
   SPI_InitStructure.SPI_CRCPolynomial = 7;
   SPI_Init(SPI2, &SPI_InitStructure);

   // Enable SPI_MASTER NSS output for master mode
   SPI_SSOutputCmd(SPI2, ENABLE);
   // Enable SPI_MASTER

The problem occurs just before the read:

  //Wait for SPI2 Tx buffer empty
   while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
   //Send first byte to start read