cancel
Showing results for 
Search instead for 
Did you mean: 

SPI transmission with DMA and a timer sending the DMA request

Tommino
Senior

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

12 REPLIES 12
Tommino
Senior

It means I don't see waveforms on the SPI1 pins.

I am sorry but I am not able to find how to check the content of the registers. I found a couple of thread about this but I haven't understood yet how to do it.

Can you show me how to do it? The tab on the right of the IDE shows registers with weird names :D

Thanks a lot

Sorry but this is a basic skill when working with microcontrollers. Maybe you should start with taking some course or talking to some more experienced friend - this forum is not exactly the place to convey basic information.

The IDE you are using (I don't know which one) surely has some way to display them under "special function registers", "SFR", "peripheral registers" or similar. Maybe what you see are the core registers of processor, I don't know, I don't use any IDE.

JW

[EDIT] and you could also search in this forum, this thread came up upon simple search: https://community.st.com/s/question/0D53W00000IWo8fSAD/how-does-one-observe-peripheral-registers-with-cubeide

Tommino
Senior

Hi Jan,

Thanks to your help I have been able to check the SPI register and see that the SPI enable bit was not 1 (cube init function does not enable SPI1).

I added this in the code

SPI1 -> CR1|= (1<<6); // Enable SPI1

I think I am able to understand all this stuff but as you have realized by yourself it is my firs project in embedded programming. Now I see why many stm32 programmer avoid HAL and prefer registers.

I really appreciated your help