cancel
Showing results for 
Search instead for 
Did you mean: 

Beginner with ADC3_DMA, ADC3ConvertedValue constant

joneyvindur
Associate II
Posted on June 28, 2012 at 01:21

using gcc 4.5.2, st-util 4242, stm32f4discovery, ADC3_DMA peripheral examples from STM32F4-Discovery_FW_V1.1.0, ld file from TrueStudio, startup file from CMSIS. 

When I run the program in the debugger the ADC value does not change. 

If I connect PC2 to VDD then I get ADCConvertedValue=4089. 

It stays the same until I unplug the USB and start over, then it is 4092. 

If I connect PC2 to GND then ADCConvertedValue=0. 

In any case it does not change during the power cycle. 

(I don't know if this matters, but while I am stepping through the code, it never enters an interrupt routine, it just stays in the main while loop copying the data from ADCValue to ADCVoltage.)

Please let me know if you have any ideas on how to get the ADCValues to update. 

Thanks. 

#adc-stm32-discovery
6 REPLIES 6
raptorhal2
Lead
Posted on June 28, 2012 at 04:44

Is Continuous Conversion Mode disabled ?

If that doesn't help, post your code.

Cheers, Hal

frankmeyer9
Associate II
Posted on June 28, 2012 at 08:46

The values sound reasonable.

How do you trigger the ADC, and when ?

If you do not have continuous mode configured, you need to trigger the ADC regularly..

(I don't know if this matters, but while I am stepping through the code, it never enters an interrupt routine, it just stays in the main while loop copying the data from ADCValue to ADCVoltage.)

 

I guess you set a breakpoint into the interrupt code. The debugger does not just follow interrupts.

Is your ADC interrupt correctly initialized, and enabled ? You should be able to check the ADC interrupt status flag anytime in single-step mode.

joneyvindur
Associate II
Posted on June 28, 2012 at 20:24

It is example code which is available to anyone, for example from here:

https://github.com/nabilt/STM32F4-Discovery-Firmware/tree/master/Project/Peripheral_Examples/ADC3_DMA

129 ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

130 ADC_InitStructure.ADC_ScanConvMode = DISABLE;

131 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

132 ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

133 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

134 ADC_InitStructure.ADC_NbrOfConversion = 1;

135 ADC_Init(ADC3, &ADC_InitStructure);

the makefile which I use is attached.

________________

Attachments :

Makefile.ADC3_DMA : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006qbAJ&d=%2Fa%2F0X0000000bpE%2F1BwLCxvd.MgdqUx3.okC2bO0fgCaP0UteB73XzUYa6I&asPdf=false
joneyvindur
Associate II
Posted on June 28, 2012 at 20:47

I am not triggering the ADC explicitly, I haven't looked into any of the interrupt flags.  

I added this line:

ADC_InitStructure.ADC_ExternalTrigConv = 0;

and it worked once but then it stopped working again. 

It must be something to do with how I am booting the device. 

I have one window which I type st-util 4242 usb and another window with

gdb:

file ADC3_DMA.elf

target extended localhost:4242

load

break main

cont

joneyvindur
Associate II
Posted on June 29, 2012 at 01:32

The ADC works if I reset the device with the black reset button. 

(in the debugger info reg shows that everything is zeroed.)

So the problem is solved. 

I am a little mystified over why there is different behavior when you 1) reset with the reset button and when you unplug/plug the usb or 2) when you reset in the debugger for that matter. 

Thanks for the help. 

frankmeyer9
Associate II
Posted on June 29, 2012 at 09:21

It might have been an issue with the debugger.

The example you compiled does not use interrupts.

It configures the ADC in continuous mode, with SW trigger, and then configures the DMA to move the result continuously from the ADC->DR into your variable.

It starts the conversion once before entering an endless loop, where it only reads the result.

This way, you are not bothered with interrupts, the ADC/DMA chain permanently delivers the new conversion result, without further notification.

At least, it is not the example I would have started with...