cancel
Showing results for 
Search instead for 
Did you mean: 

while(HAL_IS_BIT_SET(ADC->CR, ADC_CR_ADCAL)); make STM32f303 reset

mli.11
Associate

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?

2 REPLIES 2
Danish1
Lead II

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

Piranha
Chief II

Look for ADC_CR_ADVREGEN bits and read carefully how to manage those.