2024-09-23 09:18 PM
Hello everyone,
I am working with the STM32F072RBT6 Discovery board, where the board is configured as an SPI slave while another device acts as the master. I am utilizing DMA to receive and transmit data through two SPI interfaces (SPI1 and SPI2).
Currently, I have successfully implemented data reception and transmission, but I am experiencing a continuous shift in the transmitted and received data. My goal is to achieve simultaneous data reception and transmission using DMA. The communication is initiated by the master when the CS (Chip Select) pin transitions from high to low.
My questions are:
Any insights or solutions would be greatly appreciated!
Thank you!
2024-09-24 06:12 AM
Data gets loaded into SPI before it gets shifted out. If you have the right data loaded when the master starts clocking, it will get sent out.
With DMA, it is constantly loading data. So if you try to change the next byte that will be sent, it is already too late as it's already been sent to the SPI. You can't change it anymore.
If clock rate is slow enough, you can use interrupts instead and respond quickly to change the next byte being sent, but this is difficult at high speeds. Or if you have some agreed-upon delay between transactions, you can get the data ready while the CS line is high and send it to the SPI before the master pulls CS low and starts clocking.