STM32L0 ADC "Latches" Data Using DMA
Hello,
I am using an STM32L031G6U6 device. (28-UQFN)
Summary: There are 6 ADC channels configured for DMA. After having a nominal voltage (2.9V or less) applied to Channel 0 / ADC_IN0 / Pin 6, and then removing the source, the value remains in the register.
Description:
It is configured using HAL. It uses channels 0,1,2,4,5,6. I am using a DMA transfer, word size, circular mode, along with 8x oversampling. Some data fields are voltage scaled, a couple sources use a buffer, but in each channel voltage data is correct and verified. Pin 5, VDDA, is at 3V0 and filtered using a 4.7u + 100n cap. The 3V0 supply is relatively noise free.
After booting up and beginning execution, every 10 secs a string of values is printed out, starting at channel 0. I apply a voltage of 2.9V or less to ADC0. The value is correct. All other channels are correct. Then I completely remove the voltage source from Channel 0. It continues to print out a voltage value (or ADC counts if you prefer) that are somewhat less, typically anywhere from 0.8V to 1.5V less. I can leave it for an hour and the value will remain relatively stable. here is what I have tried to "flush" and reset the ADC after a read, and before the next one. Note: all buffers and values are cleared between reads.
1 - HALT the DMA using HAL_ADC_Stop_DMA(&hadc);
2 - De initialize the ADC peripheral using HAL_ADC_MspDeInit(&hadc); (also stops clock)
At the end of the 10 second period, I then:
1 - HAL_ADC_MspInit(&hadc);
2 - HAL_Delay(5);
//recal ADC
3 - HAL_ADCEx_Calibration_Start(&hadc, ADC_SINGLE_ENDED);
//start ADC
4 - HAL_ADC_Start_DMA(&hadc, (uint32_t*)adcDMABuffer, DMA_SIZE);
And the peripheral starts up, all values are correct and as expected, EXCEPT for ADC0, which continues on with the same value it had before performing all the above. Something's not getting cleared!
I have discovered one thing that will clear it. I use a serial port to send commands to the device, so I added a command to perform a soft reset using NVIC_SystemReset(). When it comes out of reset, the system resumes updating every 10 seconds, and the value that was on ADC0 is gone. I apply a voltage and voltage appears and is correct. I remove the source and value remains...repeat...same thing.
I have scoured through the peripheral libraries to see if there's any addition function that can be used to reset the ADC after shutting it down, but seemingly nothing more than what I have tried. So the question is this:
What does the RESET/RESTART do to the ADC peripheral that "HAL_ADC_MspDeInit(&hadc)" does not?
Is there a bit in one of the registers I can set to clear ADC0 from latching this value, or fully resetting the peripheral? I've been fighting with this for the last couple of days but really spinning the wheels.
Thanks for any suggestions on this!
