2019-09-18 05:53 AM
I'd like to convert voltages on 2 channels of ADC1 on STM32F334R8 with no external triggering (no timer) and no DMA. I'd like to use software triggered conversion and I'd like to execute the following code in an infinite loop:
---- Rank 1
---- Rank 2
Two cases:
-------- Code 1 -- Continuous-time conversion enabled ---------
HAL_ADC_Start(&hadc1);
while (1){
// Rank 1 (?)
if (HAL_ADC_PollForConversion(&hadc1, 1000) == HAL_OK){
int x = HAL_ADC_GetValue(&hadc1);
}
// Rank 2 (?)
if (HAL_ADC_PollForConversion(&hadc1, 1000) == HAL_OK){
int y = HAL_ADC_GetValue(&hadc1);
}
// some other code is here
}
// the pb here is that HAL_ADC_GetValue() returns conversion of either Rank1 or Rank2. How to figure out which rank has been converted? Or how to force conversion of a given rank?
-------- Code 2 -- Continuous-time conversion disabled ---------
while (1){
HAL_ADC_Start(&hadc1);
// Rank 1 (?)
if (HAL_ADC_PollForConversion(&hadc1, 1000) == HAL_OK){
int x = HAL_ADC_GetValue(&hadc1);
}
// Rank 2 (?)
if (HAL_ADC_PollForConversion(&hadc1, 1000) == HAL_OK){
int y = HAL_ADC_GetValue(&hadc1);
}
HAL_ADC_Stop(&hadc1);
// some other code is here
}
// the pb here appears when the sampling is as low as 1.5 cycles for both ranks. The same value is returned at every execution of HAL_ADC_GetValue(). When the sampling is 19.5 or higher, the conversion of both ranks works fine.
Please find below the configuration of STM32CubeMX.
------- STM32 CubeMC - Configuration -------
ADC Settings
ADC_Regular_Conversion_Mode
Rank 1 :
Rank 2