Skip to main content
RoKsPy
Associate II
July 5, 2021
Question

STM32L496 SPI 16 clock cycles instead of 8

  • July 5, 2021
  • 3 replies
  • 1645 views

So I have configured the SPI peripheral with a data frame of 8 bits. However, in the scope, there are 16 cycles in total. The first byte is okay, and outputs the loaded byte, however after the first 8 cycles, there are additional 8 cycles. The issue can be that these unwanted 8 cycles provide some additional, unexpected configuration to the slave.

So I think that the issue is that the SPI is disabled only after the next round of cycles have started because I'm waiting for the transmission level (FTLVL) and busy flag (Status Register BIT7) to clear. The reason I'm thinking of this is that, when I remove the waiting step, SPI runs for the 8 cycles as expected, but also becomes unpredictable at times.

Update: So it wants to send 16 bits regardless if I get it to do 8cycles. For example, I load the buffer with a single byte and manage to output the byte within the 8 cycles after which transmission is stopped. However, the next time I want to send something, there are 8 zeros in front of the next byte, so it will send 8 zeros, and only then it will send the the required byte.

I also tried reducing the baud rate, however, that did not help....

Any ideas?

Many thanks in advance.

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
July 5, 2021

Do an 8 bit write to the data register ​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
RoKsPy
RoKsPyAuthor
Associate II
July 5, 2021

I'm already writing it with the uint8_t data type

TDK
Super User
July 5, 2021
"If you feel a post has answered your question, please click ""Accept as Solution""."
PMish.1
Visitor II
December 30, 2021

This worked for me.

However "&" is missing in this comment. It should be something like (as in the link provided)

*((__IO uint8_t *)&SPIx->DR) = value;

waclawek.jan
Super User
July 5, 2021

Write a minimal but complete compilable example exhibiting the problem, and post.

JW