cancel
Showing results for 
Search instead for 
Did you mean: 

ADC "volatile uint16_t" data

luke514
Senior

I am using STM32F407G.

I am attaching a main.c (that use DMA) that reads simultaneously the voltage coming from 3 potentiometers connected to 3 channels of ADC.

In the code, if you try to change "volatile uint16_t adc_value[3]" to "volatile uint32_t adc_value[3]" this is what happens:

errore.png

Huge values (above the upper limit 2^n with n = num bits) are displayed.

I don't understand why this happens.

"adc_value" is the number read by the ADC while "adc_CH1_value_volt" is converted to volt (of the 1° channel)

 

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

>I don't understand why this happens.

Because the ADC values are moved by the DMA, and the setup code for the DMA is not shown. That code defines the bit size of the values. So DMA does not know that you've changed the values type to 32 bit.

 

 

View solution in original post

3 REPLIES 3

>>I don't understand why this happens

Are you sure the project completely rebuilt properly?

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

>I don't understand why this happens.

Because the ADC values are moved by the DMA, and the setup code for the DMA is not shown. That code defines the bit size of the values. So DMA does not know that you've changed the values type to 32 bit.

 

 

You are right! Now that I think about it, in the .ioc file in the dma settings I selected Half Word ... I'll try changing it to word and it should also work with 32 bit!