2020-07-28 01:24 PM
Hi All,
I am trying to use SPI+DMA in stm32f401 nucleo 64.
SPI + DMA is working successfully on both transmit and receive data. I configured spi + dma in software cs since I have multiple slaves, but that means I have to pull the gpio up and down for every transmission.
I am not sure if I did/understood it correct, this way, gpio would not pull up and down by itself while the processer is running other code, so I will have to call spi + dma with gpio inside a while loop. It feels to me that does not make any difference than using polling.
Is there a way to get pass this ? or am i doing this correctly?
Thanks in advance!
2020-07-28 02:31 PM
> Is there a way to get pass this ? or am i doing this correctly?
A better solution would be to implement the transfer complete routine to pull up CS. That way you don't need to worry about it and your CPU can do other things. The transfer complete function is called before the state is set to ready. Your main loop can just poll the status to see when it's ready for another transfer.
2020-07-28 02:36 PM
If you are SPI master and have SPI and DMA active, you need only from main loop to trigger the transaction(s).
If you want the SPI to run in the background with RTOS or bare metal implementation, I can suggest my past implementation as Interrupt based state machine. Say you have 3 slaves with sequentially 3 transactions queued and you want 10usec delay between each of them:
This is a very simplified scheme, you can have a queue of transfers to reenable this smart SPI and you can disable it when the queue is empty.
All these transactions will run with brief interrupt routines while the main loop does something else.
This scheme can work with multiple SPIs running in the background, where multiple HW SPI gets full use of them instead of time multiplexing them...
2020-07-28 02:38 PM
Note: Such implementation can't be found in HAL examples.
2020-07-28 07:52 PM
What hardware are you talking too that expects CS to bang up/down for *every* byte?
ST's implementation really doesn't function helpfully for you.
I don't think DMA is going to help you here.
If you really have to deal with this hardware you might consider generating a pattern buffer you can DMA to GPIO pins.
2020-07-29 11:53 AM
Warning: don't use DMA transfer complete interrupt, to change slave selection. Use SPI transfer complete interrupt instead.
Also be aware of assertion/de-assertion times before and after transfer. some slaves need a few time after assertion of CS pin to receive your data and after your transfer completes. check slave datasheet for required timing.