STM32F0 Analog Window Watchdog (AWD) firing all the time
I try to use the Analog Window Watchdog of a STM32F030F4. For starting I wanted to keep it as simple as possible therefore I started with a single channel conversion in continous mode. The window when an interrupt should be triggered is from 3.0V to 3.3V. The ADC is working as expected and holds the correct values, but the AWD ISR is getting triggered all the time, it seems to be a ISR loop. I can't understand why cause the levels are in the correct order and threshold values are also correct. After clearing the interrupt flag and leaving the ISR the programm jumps imediately back into the ISR, grrr!!! This happens even when I connect GND to the Input Pin (AN0 --> Channel0), I can read zero in the ADC result inside the ISR, but why is getting the ISR fired because 0V is not between the analog window specified???
Very appreshiate every help on this!!!!!!
uint8_t ISR_Bit = 0;
int main(void){ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file *//* GPIOC Periph clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); GPIO_DeInit(GPIOA);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure);/* Configure PC8 and PC9 in output pushpull mode*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOA, &GPIO_InitStructure);/* To achieve GPIO toggling maximum frequency, the following sequence is mandatory.
You can monitor PC8 and PC9 on the scope to measure the output signal. If you need to fine tune this frequency, you can add more GPIO set/reset cycles to minimize more the infinite loop timing. This code needs to be compiled with high speed optimization option. */uint32_t ADC1ConvertedValue = 0, ADC1ConvertedVoltage= 0;
uint32_t voltage; /* Configure ADC1 Channel 11 */ ADC_Config();while (1)
{/* Compute the voltage */
ADC1ConvertedVoltage = (ADC1ConvertedValue *3300U); ADC1ConvertedVoltage >>= 12; /* ADC_StartOfConversion(ADC1); while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)); //ADC1ConvertedValue = ADC_GetConversionValue(ADC1); //Read ADC value //ADC_ClearFlag(ADC1, ADC_FLAG_EOC); //Clear EOC flag/* will contain the temperature in degrees Celsius
voltage = (3300 * ADC1ConvertedValue ); voltage >>= 12; // 1751 is the factory stored setting for 30°C */if(ISR_Bit == 1)
{ GPIO_SetBits(GPIOA, GPIO_Pin_3); } else { GPIO_ResetBits(GPIOA, GPIO_Pin_3); } }}void ADC1_COMP_IRQHandler(void)
{ uint16_t Result = 0;if(ADC_GetITStatus(ADC1, ADC_IT_AWD) != RESET)
{ /* Clear ADC1 AWD pending interrupt bit */ ADC_ClearITPendingBit(ADC1, ADC_IT_AWD); Result = ADC_GetConversionValue(ADC1); //Read ADC valueISR_Bit = 0x01;
}}