2018-05-03 09:39 AM
I am working with CubeMx and the HAL Driver on Nucleo H7 (STM32H743ZI) Board. Now i want to implement a SPI Rx communication with an external ADC. The data from the ADC is 32bit wide. The SPI reception should happen without much CPU intervention.
My idea was to set up a timer (~100kHz) which triggers a DMA request. The DMA triggers the SPI Rx process and transfers the Data to a specific value in D2 RAM. After the DMA transfer an interrupt should be generated: the data that was transfered by DMA, is simply sumed up and a counter-value is up counted.
The Idea is to sum up the ADC data over a specific time and calculate the average value of the result afterwards.
I tried nearly every setting in CubeMX to sync the DMA transfer with the timer but non of my attempts worked. Also the examples from the Cube_FW_H7 doesn't give me a clue.
The only way i managed the problem was set up a new DMA transfer in timer-elapsed callback. But this uses much of CPU time which i maybe need for other tasks.
Does anyone has a workaround for my problem?
Is there also a possibility to sync the SPI rx process to a timer without DMA?
Thanks for you answer.
#spi #timer #hal #h7 #sync #dma-spi #dma2018-05-03 10:55 PM
A clicky inevitably covers only a limited subset of all possible usage scenarios, so you may need to do some real programming.
Set the SPI to bidirectional (you don't need to enable MOSI at the GPIO level, if you don't need it). Set up the timer so that it regularly provides a trigger (e.g. from the Update event) for the DMA and set the respective stream of DMA to write into the SPI's transmit data register (you don't care about the actual value written, on the memory side it can read from any address, make it nonincrementing and point it to some arbitrary variable in a memory accessible by that DMA). That will start a SPI transfer, SPI will now issue the needed number of clocks and read in the data from MISO into its shift register.
Set up the SPI to trigger DMA upon RX and in DMA set the respective stream to pick data from the receive data register of SPI and store it into memory where you want to see them.
JW