Interrupt double firing can't be fixed
Hello all,
I am using the ADC on my STM32L431 with both DMA and interruption. Everything works fine, except that the ISR is often entered with none of the enabled interrupt flag being set.
Initial code:
void ADC1_IRQHandler()
{
if(LL_ADC_IsActiveFlag_JEOC(ADC1))
{
inj_buf[BL - DMA1_Channel1->CNDTR] = ADC1->JDR1;
}
else if(LL_ADC_IsActiveFlag_OVR(ADC1))
{
LL_ADC_ClearFlag_OVR(ADC1);
}
else
{
__NOP(); //A breakpoint is set here and it is reached quite often
}
}In the last post, @Community member suggested that this is caused by the program exiting ISR too soon, therefore the interrupt flag is not yet cleared, then the program would enter ISR again.
Since then, I tried to fixed it by doing the following:
1.
void ADC1_IRQHandler()
{
if(LL_ADC_IsActiveFlag_JEOC(ADC1))
{
inj_buf[BL - DMA1_Channel1->CNDTR] = ADC1->JDR1;
__DSB();
}
else if(LL_ADC_IsActiveFlag_OVR(ADC1))
{
LL_ADC_ClearFlag_OVR(ADC1);
__DSB();
}
else
{
__NOP();
}
}2.
void ADC1_IRQHandler()
{
if(LL_ADC_IsActiveFlag_JEOC(ADC1))
{
inj_buf[BL - DMA1_Channel1->CNDTR] = ADC1->JDR1;
loop_cnt++; //Read - Modify - Write
if(loop_cnt >= 1024) loop_cnt = 0;
}
else if(LL_ADC_IsActiveFlag_OVR(ADC1))
{
LL_ADC_ClearFlag_OVR(ADC1);
loop_cnt++;
loop_cnt--;
}
else
{
__NOP();
}
}According to this article by ARM
3.
void ADC1_IRQHandler()
{
if(LL_ADC_IsActiveFlag_JEOC(ADC1))
{
inj_buf[BL - DMA1_Channel1->CNDTR] = ADC1->JDR1;
temp_isr = ADC1->ISR & 0x7FF; //Read immediately after write
}
else if(LL_ADC_IsActiveFlag_OVR(ADC1))
{
LL_ADC_ClearFlag_OVR(ADC1);
temp_isr = ADC1->ISR & 0x7FF;
}
else
{
__NOP();
}
}According to this post on a different forum
But none of them solved the issue.
Please help! Thank you in advance!