2016-10-08 10:06 PM
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 : and here is the data after adding some delay before SS goes back HIGH: 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-!stm32f42016-10-09 07:56 AM
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.