cancel
Showing results for 
Search instead for 
Did you mean: 

DMA2 never triggers interrupt on ''transfer complete''

marko2
Associate II
Posted on August 04, 2014 at 12:05

Hi all!

I'm trying to configure DMA2 to trigger an interrupt on ''transfer complete'' event. I'm using DMA2 to transfer data from ADCs to memory. However, it seems that DMA2 never triggers an interrupt, but data is transfered to memory! Please find attached my main.c.

Thanks!
9 REPLIES 9
marko2
Associate II
Posted on August 04, 2014 at 13:28

It seems that I did not configure well ADCs and/or DMA2 to operate in parallel. What I want is to ADC1, ADC2 and ADC3 scan 4 channels (each) but in parallel, so that 1st channels of ADC1, ADC2, ADC3 are scanned at the same time, and then 2nd channel etc. After scanning is done, I also want to transfer data into memory using DMA.

Any ideas?

Best,

Marko.

schauer
Associate II
Posted on August 04, 2014 at 13:53

Hello Marko,

as far as I have seen, you start the conversion before even configuring the DMA. Within main() you first call ADC_Configure() in which ADC_SoftwareStartConv is called. Afterwards you call DMA_Configure().

bs

marko2
Associate II
Posted on August 04, 2014 at 14:08

Thanks! I'll move this line after DMA is configured.

However, I want for this ADC sequence to be triggered by timer. Can you please take a look at new main.c that I wrote.

So now I configured:

ADC_Mode =ADC_TripleMode_RegSimult;

DMA_InitStructure.DMA_PeripheralBaseAddr = ((uint32_t)0x40012308); // not sure for this address, I've found it in some example

Since I want for this ADC sequence to be triggered by timer, I'm not sure how to configure that. Should I configure this external trigger only for ADC1?

Thanks!

Best,

Marko.

________________

Attachments :

main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1Gv&d=%2Fa%2F0X0000000bkZ%2F1EZpGwMjexYQ.0h.sEMxoOYCxtt9DjKCvzwRBaTJ594&asPdf=false
marko2
Associate II
Posted on August 04, 2014 at 14:58

I managed to make it work. Thank you for your suggestion to move start of AD conversion!

One can find attached my main.c, maybe it will be of some help for someone.

Best,

Marko

________________

Attachments :

main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1Gq&d=%2Fa%2F0X0000000bka%2FkUrcAUTaN8KzkopcsOtUi_cdwV7znTY0mUJy6Y5JjpU&asPdf=false
Posted on August 04, 2014 at 15:10

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Problem%20with%20ADC%20DMA%20and%20timer&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=1...

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/ADC3%20converting%203%20inputs%20%2B%20display&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=234]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FADC3%20converting%203%20inputs%20%2B%20display&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=234

Might need to tweak the Triple mode used.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 04, 2014 at 15:13

You might want to review your timer settings to get more accurate sample times.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
marko2
Associate II
Posted on August 04, 2014 at 15:58

Hi clive1!

I'm not sure what do you mean by ''might need to tweak the triple mode used'' - I looked for those 2 examples you posted, but I can't find what I have to change.

By ''review your timer settings'' you probably mean to increase time period as much as possible (for 16b timer it is 65536), which will allow me to increase base frequency? In that way I can get time periods with higher resolution.

I noticed strange behavior of AD total conversion time. When following the formula in reference manual: (# cycles + 12 cycles) times (sample time), I calculate conversion time that is twice smaller than actual - actual time was recorded by oscilloscope. I even tested the clock frequency of APB2 using timer and oscilloscope, and it is really 80-84 MHz, and e.g. if I use Div4 on ADC clock (which means frequency of 20 MHz, i.e. time period of 0.05 us), and performing 4 conversion, formula would give: 4 times (3 cycles + 12 cycles) times 0.05 us equals 3 us, but I measure 7.2 us. This happens for all Div's and for all sampling-time-cycles. Do you know maybe why?

Thank you for your help!

Best,

Marko.

Posted on August 04, 2014 at 16:31

So what's your APB clock? 42 MHz

TIM_TimeBaseInitStructure.TIM_Prescaler = 3; // 42 MHz / (3+1) = 10 MHz (0.1 us) TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInitStructure.TIM_Period = 9999; // period: 1000 us = 1 ms TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0x00;

42,000,000 / 40,000 = 1,050 Hz

952.38 ms

So the first sample (1) is paced by the clock, subsequent samples 2-4 depends on the conversion time.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
marko2
Associate II
Posted on August 04, 2014 at 16:45

Its 42 MHz for timers TIM3 and TIM4, whereas TIM4 is only used to trigger AD conversion (every 1 ms). ADCs are on APB2 (with 84 MHz clock), and are configured with Div4 prescaler, which means 20 MHz clock.

I know that 1st sampling is triggered by clock (on TIM4 update, every 1 ms), and the other samples depend on when the prior sampling was finished. But nevertheless, sampling of each channel in sequence should be the same. Therefore, I calculate the total conversion time as:

4 times (# cycles + 12 cycles) times time-period (which is 0.05 us in case of 20 MHz clock). But this gives me total conversion time that is 2 times less than actual. I can't figure out why...