STM32 bare metal SPI issue with transmit

Thread Starter

irmanao

Joined Apr 29, 2017
87
I'm trying to transmit ( using stm32f407) two hex numbers just like the datasheet explains (attached picture), but only the second number is being transmitted (checked with logic analyzer). Code is:
Code:
SPI1->CR1 |= (1 << 6); // enable SPI1
SPI1->DR = 0x86;                  // transmit 0x86
while ((SPI1->SR >> 1)==0);  // wait until TXE is set
SPI1->DR = 0x85;     // transmit 0x85
Anything quick that i am missing?
thanks
 

Attachments

MrChips

Joined Oct 2, 2009
30,809
Did you configure the SPI module correctly? Show all your code.

You need to test the TXE bit in SR.
#define SPI_TXE 0x0002

while ( (SPI1->SR & SPI_TXE) == 0);

Do you have an oscilloscope?
 

Thread Starter

irmanao

Joined Apr 29, 2017
87
Yeap, that worked. I thought this: while ((SPI1->SR >> 1)==0);
was doing the same thing.
Thanks, i'll probably start some more threads as i try to make SPI (transmit and receive) to work.
 

MrChips

Joined Oct 2, 2009
30,809
Yeap, that worked. I thought this: while ((SPI1->SR >> 1)==0);
was doing the same thing.
Thanks, i'll probably start some more threads as i try to make SPI (transmit and receive) to work.
while ((SPI1->SR >> 1)==0);

does not take into account that all the other bits could be set.
 
Top