2019-06-21 05:57 AM
Hello.
I have a Nucleo board with stm32f302r8. I want to set a state variable for voltage window:
state = STATE_OK if higher threshold > current voltage > lower threshold
state = STATE_AWD if higher threshold < current voltage or lower threshold > current voltage.
I set up a ADC1 with AWD1 and enable interrupt for AWD1 and EOS flags.
My handler:
void ADC1_IRQHandler(void)
{
// debug_send(NVIC_GetPendingIRQ(ADC1_IRQn)); //simple uart sender
if (ADC1->ISR & ADC_ISR_AWD1) {
// Exclude the cause of the interrupt
ADC1->ISR |= ADC_ISR_AWD1;
state = STATE_AWD;
} else {
state = STATE_OK;
}
ADC1->ISR |= ADC_ISR_EOS; // Exclude the cause of the interrupt
debug_send(state); // simple uart sender
}
If current voltage has a permissible value then generated only one interrupt.
If current voltage has not a permissible value then generated TWO interrupt:
I try to read ISPR register (using CMSIS function NVIC_GetPendingIRQ()) and problem disappeared: always generated only one interrupt.
Why?
Solved! Go to Solution.
2019-06-25 12:23 AM
I understood.
I have a three ADC conversion:
I have a two flag which generates interrupt:
AWD flag is generated at the same time as the EOC flag. Timing diagram:
Because is generated two interrupts.
Conversion:
ADC Handler:
void ADC1_IRQHandler(void)
{
if (ADC1->ISR & ADC_ISR_AWD1) {
ADC1->ISR |= ADC_ISR_AWD1; // Clear flag
state = STATE_AWD;
} else {
state = STATE_OK;
}
ADC1->ISR |= ADC_ISR_EOS; // Exclude the cause of the interrupt
debug_send(state); // uart sender
}
2019-06-25 12:23 AM
I understood.
I have a three ADC conversion:
I have a two flag which generates interrupt:
AWD flag is generated at the same time as the EOC flag. Timing diagram:
Because is generated two interrupts.
Conversion:
ADC Handler:
void ADC1_IRQHandler(void)
{
if (ADC1->ISR & ADC_ISR_AWD1) {
ADC1->ISR |= ADC_ISR_AWD1; // Clear flag
state = STATE_AWD;
} else {
state = STATE_OK;
}
ADC1->ISR |= ADC_ISR_EOS; // Exclude the cause of the interrupt
debug_send(state); // uart sender
}