2020-07-10 02:55 PM
Hello,
I'm using cubeIDE for the whole setup and I'm trying to read a voltage from 2 different pins now when using:
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
ADCPin1Val = HAL_ADC_GetValue(&hadc1);
where hadc1 pointer refers to the first pin I set.
But how do you set the reading channel to be from another pin lets say A2?
2020-07-10 04:00 PM
Here is one example for reading multiple channels with the LL library:
Similar examples exists in that repository for other boards using the HAL library. You'll need to use DMA.
2020-07-11 02:33 AM
I can't see where it is used to read 2 channels and what is the deal with LL in comparison to HAL why'd you need to use DMA to read more than 1 adc input channel?
2020-07-11 03:28 AM
There are 3 channels and the data are stored in a aADCxConvertedData array. You can do the same with HAL also.
P.S. Well HAL doesn't work reliably at all for any peripheral and LL is useless, but that's another story...
2020-07-11 08:31 AM
adc has usually injected and normal channels. simpler way is to run a continuous conversion sequence on injected channels, this way you can directly read in debug mode each channel adc register and no need to setup dma.
2020-07-11 08:45 AM
The mechanics on most STM32 is that the ADC scan quickly, more quickly than you want to service.
So you create a scan-list, have an array those go into, use standard DMA to execute that, and have an IRQ for EOC of the list.
You can pace capture with a TIM
If you need multi samples at the same instant, use multiple ADC, in dual or triple mode, which can use the same DMA method into a 2D array
2020-07-12 03:19 AM
Well I've basically followed this tutorial on how to get it with continues conversion being off sins using it with DMA and RTOS corrupts the software and it just puts the all the values from each channel in a single DMA buffer so what you read off A1 pin say goes into ADCBuffer[0] and A2 pin reading to ADCBuffer[1] and so on using an ADCRead task in RTOS with:
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
To refresh the reading.
Look fine and working to me but makes life a little hard for multi sampling and averaging on application that need stable reading.
2021-01-31 04:15 AM
It is easy possible to use polling for more than one ADC Inputs! If you using CubeMX to generate code, you are not able to use all enabled channels because of a bug in CubeMX!!
Read my answer here: