2020-05-07 08:15 AM
I've been trying to use SPI on the STM32F103C8T6 for a project I've been working on for a while now. I still can't figure out how to buffer data using SPI to an array in a continuous stream.
This stream is continuous because there is no pause or break between 8-bit data transmissions/receptions like there are on USART. The data speed is ~4MHz. I also want it to use DMA (like the HAL_SPI_Receive_DMA function) because I don't want it to interrupt other critical code being executed.
I read the reference manual and ST says the max SPI speed is 18MHz, so unless the HAL library isn't built for continuous data streams, it shouldn't be a problem.
Continuous data stream output would also be useful for someone who wants to use SPI as a crude DAC via pulse density modulation (instead of using PWM.)
2020-05-07 08:19 AM
You did not tell us, master or slave.
Regardless, you simply set up the DMA channel respective to given SPI Rx or Tx, as circular, set the pointers, size, enable half-complete and complete interrupt of DMA, and start it. Everything needed is in the DMA (and SPI) chapters of RM.
Since then, it's just matter of whether your software can source/sink fresh data to/from the memory buffers, fast enough.
JW
2020-05-07 02:15 PM
Thank you for clarification of the setup- I definitely missed one of those steps. I assumed I could just use the HAL function as-is without setting up the DMA in its respective STMCubeIDE category (I'm inexperienced with it still.)
I am using SPI as slave (external clock,) but I think regardless if master/slave configuration will be similar.