Skip to main content
Konami
Senior
November 21, 2017
Question

SPI Slave RX data shifted

  • November 21, 2017
  • 1 reply
  • 712 views
Posted on November 21, 2017 at 17:02

I'm having an issue with the LL SPI driver on the STM32L4 configured as SPI slave. My Tx buffer contains {01, 02, 03, 04, 05, 06, 07... }. When I read 7 bytes repeatedly from the slave using the Aardvark SPI master I get the following responses:

01 02 03 04 05 06 07

08 09 0A 01 02 03 04

05 06 07 01 02 03 04

05 06 07 01 02 03 04

05 06 07 01 02 03 04

...

Resetting the master doesn't change anything. Resetting the STM32 slave will start the pattern over. It seems like the STM32 is trying to sent 10 bytes instead of the 7 the master is reading and the last 3 bytes are persisting in the TX buffer. Is this possible? How do I fix this?

#stm32l4-spi
This topic has been closed for replies.

1 reply

Konami
KonamiAuthor
Senior
November 21, 2017
Posted on November 21, 2017 at 17:45

Okay, I've discovered that when I call the LL_SPI_Enable function it actually triggers the SPI2_IRQHandler 3 times with the  LL_SPI_IsActiveFlag_TXE flag set. This is causing me to to send 3 bytes that weren't actually requested by the master.

Any ideas as to why or if this is expected?

S.Ma
Principal
November 21, 2017
Posted on November 21, 2017 at 18:17

Make sure that if you use bytes, you read/write the SPI DR as a 8 bit write bus access.

The SPI has I think a 32 bit TX fifo: you can write 4 bytes one shot if configured like this.

All this to avoid dead time between byte transfer when using interrupt (non DMA) based systems.

Konami
KonamiAuthor
Senior
November 21, 2017
Posted on November 21, 2017 at 19:40

I am using it interrupt mode rather than DMA actually, but I think I'm doing the R/W with the correct functions:

LL_SPI_ReceiveData8()

LL_SPI_TransmitData8()