while(HAL_IS_BIT_SET(ADC->CR, ADC_CR_ADCAL)); make STM32f303 reset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-08-08 7:05 PM
when make ADC calibration, using while(HAL_IS_BIT_SET(adc->CR, ADC_CR_ADCAL)); makes system reset.
CLEAR_BIT(adc->CR, ADC_CR_ADCALDIF);//single end
SET_BIT(adc->CR, ADC_CR_ADCAL);
while(HAL_IS_BIT_SET(adc->CR, ADC_CR_ADCAL)); //make system reset
//works after replacing with following
tickstart = HAL_GetTick();
while(HAL_IS_BIT_SET(adc->CR, ADC_CR_ADCAL))
{
if((HAL_GetTick() - tickstart) > 5)
{
return;
}
}
Why? Similar happens to other command and status bit check? if these happen to you?
- Labels:
-
ADC
-
STM32Cube MCU Packages
-
STM32F3 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-08-08 8:44 PM
Your second version that doesn’t “make reset�? gives up waiting after a short time if calibration doesn’t complete. But you don’t say if the ADC calibration completes successfully with that code or if it gives up waiting.
If it does give up, you don’t know if the ADC is calibrated and it might not be usable. So you might be advised to “do something drastic�? such as reset the ADC completely or stop with an error code.
Your first code would wait forever if calibration doesn’t complete. So that would be a crash - the stm32 would stop responding - unless you had a watchdog running to trigger reset under such circumstances.
Why might calibration never complete? I don’t know stm32f3, but for some of them the ADC regulator must be enabled but ADON must be OFF. Have you checked your Reference Manual for how to calibrate the ADC?
Hope this helps,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-08-08 11:18 PM
Look for ADC_CR_ADVREGEN bits and read carefully how to manage those.
