Problems with regular simultaneous dual ADC conversion with DMA transfer
robca Tue Nov 24, 2015 5:06 pm
EDIT: I finally solved this, please see http://www.stm32duino.com/viewtopic.php … 8474#p8474 for more info
I’m at the end of my wits
I have read the ADC and DMA docs at least 5 times each. Looked at the RegSimul_DualMode example from ST (and that was fun enough, since it uses completely different conventions than the Arduino/Maple libraries but in the end I understand what it does)… and I still can’t make it work… help, please.
Problem statement: on a Maple Mini, using STM32duino, convert 4 analog channels (connected to pins D3-D6, i.e. IN8-5, respectively) and transfer the data in memory using DMA (I need fast and predictable timing).
I basically would need to combine “dual simultaneous mode” with “continuous scan”, in order to capture ~2000 samples from each channel. But I fear it might not be possible, and the only mention I found is here (no reply, though) https://my.st.com/public/STe2ecommuniti … x?tags=adc
The code below sets a sequence for each ADC: in SQR1 sequence length is 1 (i.e. 2 conversions), and I set the SQR2 registers to have ADC1 convert IN8 while ADC2 converts IN7, then ADC1 convert IN6 while ADC2 converts IN5. I set regular (not injected) SW triggers.
After setting the ADC1 and ADC2 registers and the DMA1 Channel 1, in theory setting ADC1->regs->CR2 |= ADC_CR2_SWSTART; should start the conversion for the master ADC1 and slave ADC2 and in parallel start the DMA (one 32 bit DMA transfer for each conversion: in dual mode the ADC1 SR register holds both the values for ADC1 and ADC2).
What I noticed, though, is that when ADC_CR2_CONT is enabled, the ADC continuously scans, and the DMA keeps sending data to my buffer. What that means is the the order of the odd and even channels in the buffer can be off. Basically, when ADC_CR2_CONT is enabled, the ADC keeps scanning all the time, and that triggers DMA transfers in a random order.
If I don’t use ADC_CR2_CONT, I can only sequence a limited number of channels (and even if I repeat the sequence, I can only still do 16 conversions per ADC max (using SQR1-3). Or I can convert 2 channels (one on ADC1, one on ADC2) continuously in parallel…
But there seems no way to do scan and dual simultaneous at the same time… am I missing something? Any suggestion? If this doesn’t work, I can use two Maple Mini synchronized to capture 4 channels, but it makes everything harder to code (one as a master, one as a slave, with the conversion triggered at the same time, and transferring data)
Here’s my non-working code (if you uncomment the delay() statement you will see the problem)
EDIT: removed non-working code, see http://www.stm32duino.com/viewtopic.php?f=3&t=757&p=8474#p8474 for working code
