Hardfault on ADC voltage change
Hello,
I have a strange problem on an STM32G071. I get ADC values every 25 ms from ADC1 channel 0 to 3 without DMA as speed is no issue. Strangely when one of the canels reaches about 1.2 V the CPU sometimes goes in a hard fault lock. There is a potentiometer connected to the channels with a voltage divider. The SCB->ICSR value is 0x00422003 (put out over a UART in the default handler). I tried to interpret it via the programming manual but I could not figure out anything.
Here is my ADC function
uint16_t get_adc(uint8_t channel) // 24 µs
{
while((ADC1->CR&ADC_CR_ADSTART)!=0); // wait in case conversion is in progress
ADC1->CHSELR = (1<<channel); // set channel
while((ADC1->ISR&ADC_ISR_CCRDY)==0); // wait for channel changed
while((ADC1->ISR&ADC_ISR_ADRDY)==0); // wait for ADC ready
ADC1->CR |= ADC_CR_ADSTART; // start the conversion
while((ADC1->CR&ADC_CR_ADSTART)!=0); // wait for conversion finished
volatile uint16_t temp = ADC1->DR; // load ADC
return temp;
}The only interrupt that is enabled is TIM7 to generate an interval. What could cause this?
Thanks
Kind regards
