Skip to main content
Graduate II
March 28, 2024
Solved

ADC "volatile uint16_t" data

  • March 28, 2024
  • 2 replies
  • 2309 views

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)

 

    This topic has been closed for replies.
    Best answer by Pavel A.

    >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.

     

     

    2 replies

    Graduate II
    March 28, 2024

    >>I don't understand why this happens

    Are you sure the project completely rebuilt properly?

     

    Pavel A.Answer
    Super User
    March 28, 2024

    >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.

     

     

    luke514Author
    Graduate II
    March 28, 2024

    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!