2019-05-28 02:23 AM
I'm reading ADC1 and ADC2 in Dual Regular Simultaneous mode using DMA on a F334R8 nucleo board, as per instructions in UM1786 section 6.2.2 "Execution of ADC conversions":
void readADCs(void) {
// enable ADC slave
if (HAL_ADC_Start(&hadc2) != HAL_OK) {
_print("can't start slave ADC\n");
}
// enable ADC master
if (HAL_ADCEx_MultiModeStart_DMA(
&hadc1,
(uint32_t *)aADCDualConvertedValues,
ADCCONVERTEDVALUES_BUFFER_SIZE
) != HAL_OK) {
_print("can't start master ADC\n");
}
}
The first reading works fine; I've checked the values and they're good. After reading finishes, I stop the ADC:
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc) {
if (HAL_ADCEx_MultiModeStop_DMA(&hadc1) != HAL_OK) {
_print("can't stop ADC\n");
}
if (HAL_ADC_Stop_IT(&hadc2) != HAL_OK) {
_print("can't stop slave ADC\n");
}
}
I've checked with a print statement to verify the callback completes successfully. However, next call (after 2s delay) to readADCs fails (PRECISERR) on the first call to HAL_ADC_Start.
Here's the line that falis from stm32f3xx_hal_adc_ex.c:
HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc) {
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
/* Perform ADC enable and conversion start if no conversion is on going */
if (ADC_IS_CONVERSION_ONGOING_REGULAR(hadc) == RESET)
// ABOVE LINE FAILS WITH FAULT
Clearly I'm not stopping and starting the ADCs in the correct way (despite having read some stmcubef3 examples). What am I doing wrong?
Bonus question: I only have to auto-calibrate the ADCs once per power cycle, right? (i.e. not once per read cycle?)
EDIT: I've realised that I only get the fault inside a freeRTOS thread, not when calling readADCs from main. I don't know why this would be.