Topic : Problem with SPI_I2S_SendData()

Forum : ARM

Original Post
Post Information Post
February 21, 2012 - 11:26am

I have some troubles programming a STM32F103RBT6 board.
I need to use the SPI to control engines, I initialized the SPI structure, RCC and GPIO regarding examples. When I plug the oscilloscope there is no output signal.

Here is my code :

void main()

while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE)== RESET){} // I saw this loop in different examples
SPI_I2S_SendData(SPI1, 0x4F);

void RCC_Configuration(void)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_SPI1, ENABLE);

void GPIO_Configuration(void)
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure SPI pins: SCK, MISO and MOSI */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(PORT_SPI, &GPIO_InitStructure);

/* Configure SPI pin : NSS */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);

void SPI_Configuration(void)
SPI_InitTypeDef SPI_InitStructure;

// Configuratin du SPI2 pour communiquer avec la carte moteur
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_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;

SPI_Init(SPI2, &SPI_InitStructure);

What is wrong in my program ?

Thank you for your help.

Post Information Post
February 21, 2012 - 2:35pm
Raisonance Support Team

Hi Flavien,

Can you try to debug and check whether you enter the SPI_I2S_SendData(SPI1, 0x4F) function?
If not, you should check what happens in the peripheral configuration, there may be a quirck in your code.

If this still fails, can you experiment with an SPI example from the STM32 Firmware Library from ST? This should work at least.

Let us know how you get through.
Best Regards,

February 22, 2012 - 9:23pm

I finally find my (stupid) mistake. I was plugging the oscilloscope to the wrong pin.
Now it works better.

Thank you for taking time to read me.