2024-02-06 11:15 AM
Hi everyone,
I have a STM32F042F6P6 chip. I want to read 9 analog channels on it.
I guess there are at least 2 options: configure a scan mode with DMA, and staying in polling mode.
I decided to stay in polling mode to avoid a potential problem due to DMA config.
I defined 1 adc handle and did channel configurations (8 first channels are gpios, the 9th is internal temp)
It seems that when calling those 2 methods repeatedly, the ADC auto-increments and read each channel starting from the lowest ID.
Let's say now that I want to have a method that reads only the internal temperature, how do I manage to tell to HAL_ADC_PollConversion to point on the internal temperature channel only ?
I have had an idea but it is quite radical:
- create other channel config structure, with only the Temp channel defined, and each time I call a conversion method, before that I call HAL_ADC_ConfigChannel with the good channel config structure.
Also, I have 2 questions:
- What is the rank of an ADC channel, and what is it used for ? I see sometimes people defining several channel but with the same rank, I don't understand why.
- Does someone have a breve explanation of multichannel conversion in DMA mode ? I do not find clear information for newbie in embedded systems like me.
Thank you very much,
Arthur
Solved! Go to Solution.
2024-02-06 12:09 PM
HAL_ADC_PollConversion always returns the last conversion. You need to manage internally what channel that is. Have an internal variable that increments by 1 for each conversion. Use that to know what channel is being returned.
Doing multi-channel without DMA isn't recommended as you can easily run into overruns.
On the F0, rank and channel number are the same thing. Rank 0 is channel 0, etc. On other families rank determines which order channels are converted.
See "13.5.5 Managing converted data using the DMA" in the reference manual for an explanation of DMA. Also should be examples you can follow in the CubeMX repository.
2024-02-06 12:09 PM
HAL_ADC_PollConversion always returns the last conversion. You need to manage internally what channel that is. Have an internal variable that increments by 1 for each conversion. Use that to know what channel is being returned.
Doing multi-channel without DMA isn't recommended as you can easily run into overruns.
On the F0, rank and channel number are the same thing. Rank 0 is channel 0, etc. On other families rank determines which order channels are converted.
See "13.5.5 Managing converted data using the DMA" in the reference manual for an explanation of DMA. Also should be examples you can follow in the CubeMX repository.
2024-07-29 04:26 PM
@TDK wrote: Doing multi-channel without DMA isn't recommended as you can easily run into overruns.
What do you mean by overruns in this case? Do you mean that the calling code will not call HAL_ADC_PollForConversion() and HAL_ADC_GetValue() fast enough, and the sample will get overwritten or corrupted?
2024-07-29 06:10 PM
Effectively, yes. Particularly when the conversions are continuously generated and it's just a question of calling HAL_ADC_GetValue fast enough.
The various STM32 families have different ADC peripherals. Most of them do not "wait" for you to read the value before converting the next channel.