cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 discovery SPI issue

Osama.Ahmed
Associate
Posted on October 09, 2016 at 07:06

Hello,

        - I am using STM32F4 discovery board to send data via SPI. i have got it working but there is a small issue. the SS pin goes high before the the mcu finishes sending data.

i am using SPI1, and used PB0 as SS.

there is my code for sending one byte:

 GPIOB->ODR &= ~(1 << PIN0); // SS is LOW

  SPI1->DR = data;

  while(! (SPI1->SR & (1 << TXE))); // wait until TX buffer is empty

  GPIOB->ODR |= (1 << PIN0); // SS is HIGH

and here is the data :

0690X00000605c9QAA.png

and here is the data after adding some delay before SS goes back HIGH:

0690X00000605cAQAQ.png

Any one please know what could cause this to happen?

is it because of the TXE buffer flag goes back high before the data transmission complete?(''This is what i saw in the debugger '') and why? it is supposed to go high when there is no data in the buffer.

#!spi-!stm32f4
1 REPLY 1
Posted on October 09, 2016 at 16:56

There are two registers at play here, a holding register that flags the TXE, and a shift-register that outputs the data. TXE will flags as the first bit hits the wire, you want to know when the last bit does. You'd want to clear and look at the RXNE flag, as this asserts after the last returning bit is captured in the shift register, and moved to the receiving hold register.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..