Most Common HAL Functions to use in STM32
ADCs
1. HAL_ADC_Start(&hadc1)
- Enables ADC and starts conversion of the regular channels. Replace &hadc1 with whatever ADC you are using
2. HAL_ADC_PollForConversion(&hadc1,100)
Polls for regular conversion complete. 100 is the timeout in ms. beyond this time the function will timeout
3. ADC_Val = HAL_ADC_GetValue(&hadc1)
Gets the data from ADC Data Register. Should be called after Polling
4. HAL_ADC_Stop(&hadc1)
Disables ADC and stop conversion of regular channels.
5. HAL_ADC_Start_IT(&hadc1)
-Enables the interrupt and starts ADC conversion of regular channels
6. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
Tips: Sometimes you need to slow down the clock of ADC by using maximum prescaler because the ADC runs into overrun issues(when CPU is presented with more samples than the CPU can process)
Also you may need to start ADC again HAL_ADC_Start_IT(&hadc1) at the end of the callback function
Sometimes you need to clear the Overflow Flag before starting ADC again
//Check for Overrun and clear it if it exists
if (__HAL_ADC_GET_FLAG(&hadc1, ADC_FLAG_OVR))
{
__HAL_ADC_CLEAR_FLAG(&hadc1, ADC_FLAG_OVR);
}
7. You can find all HAL Functions of ADC in Debug > Drivers > STM32xxx_HAL_Driver > Src
8. To get continuous data from adc watchdog setting
Comments
Post a Comment