cancel
Showing results for 
Search instead for 
Did you mean: 

HAL SPI function writes wrong values into reciver Buffer

RCsak.1
Associate II

0693W00000JMWfQQAX.pngHello, I am not an embedded systems guy, so please bear with me.

I have an issue reading data to my STM32G071 nucleo board from an external device via SPI using DMA.

To do this I used code from an ST example project.

I suspect the issue lies within the HAL_SPI_TransmitReceive_DMA function.

I would appreciate any suggestions on how to fix it / things I could try.

I can send commands etc. to the external device, interrupts are triggered as expected etc.

Dozens of shorter reads / writes are sent to the device without any issue beforehand. The device actually reacats accordingly to commands sent.

But for a longer readout sequence I oberserve very weird behaviour:

- I send 26 16bit words to the device

- On my osciloscope I can see everything behaves as expected

- in particular the 26 responses observed on the osciloscope are also as expected

But wrong values get written into the reciever buffer

I have attached 2 images.

image1 shows the final words on my osciloscope.

image2 is the reciever buffer memory after the the dma finishes.

- For the last 3 response Bytes I expect 2CFF , 3500 , 0000

- The osiciloscope shows that they are indeed 2CFF , 3500 , 0000 (attached image 1)

- But where I would expect 3500 I get (seemingly out of nowhere) 2C00 in the response buffer

- 3500 and all following answers are shifted 2 Byte "downward" (attached image 2)

additional information

- the issue is consistently reproducable after restarts,..

- before the HAL function is called, the reciever buffer is infact empty (memory set to 00 00)

- the reciever buffer is not manipulated any more before looking into it and taking attached image 2

- the last response does actually get cut off. If I send a different sequence (where the final reply is not 0000), the final reply does not get written into memory.

- the error allways seems to be on the 25th 16bit word, when i lengthen the transmission the same issue happens on the 25th response, 2C00 appears seemingly out of nowhere, the consecutive responses are shifted 16bit backwards and the last one is cut off

- all 26 16 bit words are sent with a single call of HAL_SPI_TransmitReceive_DMA, and for the first 24 responses everything seems fine,

 e.g. you can see the 2C52 response on the images matches what I observe on the osciloscope.

- the HAL_SPI_TransmitReceive_DMA function function is called with the buffer adresses and length 52 (26*16bit = 52Byte)

I am happy to provide further information & would appreciate any suggestions on solutions / what to try etc.

kind regards

Roger

0693W00000JMWf6QAH.png

11 REPLIES 11
Might be in the HAL manual, but it’s definitely in the source code. Look at how the NDTR register gets loaded. I won’t be at a computer for a while or I’d find it for you.
If you feel a post has answered your question, please click "Accept as Solution".
RCsak.1
Associate II

Okay thank you for the help, I'lll try to fix my configuration. I must have made some error, as it works with double wordcount..