SPI transmission with DMA and a timer sending the DMA request
- February 23, 2022
- 12 replies
- 5045 views
Hello,
I would be glad to doublecheck with you how to implement the following operation with the STM32L476RG uC:
I would like to transmit a set of data to a DAC (AD5541) with SPI and the SPI data shall be moved from meomory to the SPI peripheral with the DMA. A timer sends the DMA request in order to set the output data rate with the timer threshold value.
I am not sure about a couple of things....so I recap here a todo list to review the procedure:
1) check the system architecture to see which channel of the DMA can receive the request from a timer and which DMA is connected to the different SPIs (If using Cube to init I think this is unnecessary... ).
2) set the Clock, the SPI1 and the Timer1 CH1 with cube to have the initialization code. First question: In cube configuration, shall I add DMA in the SPI tab or in the TIM tab? I think in the timer tab since it sends the request but I would like to be sure
3) then set the DMA registers:
a) DMA1_Channel3 -> CNDTR1 = 0x00000001; // one sample each transfer
b) DMA1 -> CPAR1 = (uint32_t)&SPI1->DR; // set SPI data register as destination
c) DMA1 -> CMAR1= (uint32_t)data; // set the data to transmit as source
4) finally set the TIM register:
a) TIM1 -> CR2 |= 0<<3 // set CCDS=0 to send a DMA when compare event occurs
b) TIM1 -> DIER |= 1<<9 // enable the DMA request when compared
c) not sure how to manage TIM1_CNT and TIM1_CCR1 to set the value be compared. Can you clarify this issue?
I think all the other registers of the SPI, Timer and DMA are written by the cube and/or are not relevant for my purpose. Do you agree?
Can we doublecheck together if am in the right direction? :)
Attached you can find a section of the manual that I found useful.
Regards
