2021-05-22 07:13 PM
I'm using both ADC's in continuous / interrupt mode on some micro's in the STM32F103 family and it's working properly and fills my needs nicely.
The core components which are commonly presented in the online tutorials are...
Calibration:
HAL_ADCEx_Calibration_Start(&hadc1);
HAL_ADCEx_Calibration_Start(&hadc2);
Starting the ADC's in continuous interrupt mode
HAL_ADC_Start_IT(&hadc1);
HAL_ADC_Start_IT(&hadc2);
The Callback routine
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
if( hadc->Instance == ADC1)
{
ADC1_Reading = HAL_ADC_GetValue(&hadc1);
}
else if( hadc->Instance == ADC2)
{
ADC2_Thermistor = HAL_ADC_GetValue(&hadc2);
}
}
But the ADCs cannot operate in continuous interrupt mode without one critical component that is basically undocumented and almost none of the tutorials mention it.
ADC_IRQHandler()
I noted one post in this board that mentioned it and based on that I added ...
void ADC_IRQHandler()
{
HAL_ADC_IRQHandler(&hadc1);
HAL_ADC_IRQHandler(&hadc2);
}
After adding that it started working but I'm unable to find any documentation on it nor how to use it properly.
I'm hoping someone here can direct me to documentation regarding it. The RM0008 Reference manual for the STM32F1x family has no mention of it.
Edit (after waclawek's response): And neither does the "HAL and lower layer drivers" manual.
Solved! Go to Solution.
2021-05-23 05:45 AM
The RM0008 does have an interrupt/exception table. The vector naming for a given chip (value, medium, xl or whatever) can be found in the startup.s file and this controls the linkage.
In addition to the DM and RM
2021-05-23 01:33 AM
The RM documents the hardware, not software.
The ADC chapter in RM documents, under which circumstances is the interrupt invoked (ADC interrupts subchapter and description of ADC_CR1 (the xxxIE bits) and ADC_SR registers), and the interrupt chapter lists the interrupt vectors' position.
The name for interrupt service routine (ISR), i.e. ADC_IRQHandler() is given the by software (usually it's defined in the startup file, usually supplied by the toolchain you are using), and you can use anything for it if you want, as long as you insert it into the proper position in the interrupt vector table - except that there's no reason to do this.
The rest of it is entirely matter of Cube/HAL "library", so refer to the documentation of that.
JW
2021-05-23 05:45 AM
The RM0008 does have an interrupt/exception table. The vector naming for a given chip (value, medium, xl or whatever) can be found in the startup.s file and this controls the linkage.
In addition to the DM and RM
2021-05-23 09:47 PM
Thanks.
So looking at RM0008 The interrupt acronym in my instance is actually ADC1_2
Then looking at
C:\Users\Administrator\STM32Cube\Repository\STM32Cube_FW_F1_V1.8.3\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\arm\startup_stm32f103xb.s
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
DCD ADC1_2_IRQHandler ; ADC1_2
DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX
It appears that ADC1_2_IRQHandler is the defined function in the CubeMX templates
Going deeper still in my CubeIDE project it is defined as
void ADC1_2_IRQHandler(void)
{
/* USER CODE BEGIN ADC1_2_IRQn 0 */
/* USER CODE END ADC1_2_IRQn 0 */
HAL_ADC_IRQHandler(&hadc1);
HAL_ADC_IRQHandler(&hadc2);
/* USER CODE BEGIN ADC1_2_IRQn 1 */
/* USER CODE END ADC1_2_IRQn 1 */
}
Which leaves egg on my face because my addition of ADC_IRQHandler() actually did nothing it seems... I've just removed it and everything still works. :flushed_face: