2023-04-21 06:03 AM - edited 2023-11-20 07:28 AM
Dear everyone, I am using an STM32F429ZI Nucleo board and using the ADC_RegularConversion_DMA example on STMCubeIDE 1.10.1
I must say on a first point of fiew, the example seems to work fine, there are some analog data in the variable:
__IO uint32_t uhADCxConvertedValue
But as I am a suspicious guy and want to be sure that this code works perfectly. My aim is to check that for ALL conversion of ADC, converted result is saved in memory after DMA transfer.
For that I looked at function:
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* AdcHandle)
There, if I understand correctly, it is called each time a conversion on ADC1 channel 10 is finished.
But the limitation is that DMA transfer will always "push" ADC result into the same memory address (pointed at uhADCxConvertedValue). So it will overwrite last ADC conversion value saved there if I don't copy it elsewhere.
Fine, thank you DMA you did great job, I will take it from there and save uhADCxConvertedValue in an array I will process in my application:
My HAL ADC conversion complete callback function now looks like:
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* AdcHandle)
{
previousADCxConvertedValue1[counter] = uhADCxConvertedValue;
counter++;
if(SAVE_BUFFER_SIZE == counter)
{
counter = 0;
}
/* Turn LED1 on: Transfer process is correct */
BSP_LED_On(LED1);
}
With previousADCxConvertedValue1, a global variable array of size: SAVE_BUFFER_SIZE
And again, I am indeed a suspicious guy, I want to be sure that each converted value are saved in this array, not that some values are missing.
I will be surely discarded for what I did, but: I added a breakpoint on BSP_LED_On() to check that each time a conversion + DMA transfer is done, value is saved.
But it does not...
There values are totally different... maybe like there are a couple of other ADC conversion + DMA transfer which do not trigger this callback. I made 5 iteration (5 times resumed program after breakpoint hit) and got the following evolution of my array:
Here, we may confirm that values in array do look like value coming out from the ADC (it is linked to +3V3 with a 10k resistor) BUT they are not equal to value transferred with DMA.
Anyway, I am pretty confident, there is something I missed or making wrong. But I am questionning this example, because I met this problem first when I adaptated it with to scan mode, with 3 channels on ADC1 (channels 10, 11 and 13).
Willing to check what I wrote for code is right, I tried approximately the same, but I also got random value and not a clean sequential save of my converted values.
How may I do it the right way? How may I check that all my ADC values are cleanly saved somewhere after DMA transfer and I can add some processing on it?
Best regards and thank you for your help
PS: there is actually something that may be changed in this code example: uhADCxConvertedValue is declared as uint16_t, but DMA transfer is configured for WORD and not HALFWORD:
In main.c:
__IO uint32_t uhADCxConvertedValue = 0;
In stm32f4xx_hal_msp.c
hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
Which may lead to some strange behavior.