Problem with 2 interrupts at the same time

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello,

   

I have a problem with my interrupts. First of them appears every 30 seconds (it's interrupt on timer), and the second appears when there is a "1" on one of the pins. The problem is that both of them triggers the same function, so I would like to have some kind of protection to be sure that when one of the interrupt already triggered this action, the other won't do that, because it's pointless and it causes troubles. How can I achieve that? I tried with :

   

if((flag_interruptclock == 1) && (flag_pir == 1)){
            flag_conflict = 1;
        }
        for (i = 0; i < CMD_BUFF_LEN; i++) buffer = 0;   
        if ((flag_interruptclock == 1) || (flag_pir == 1))
        {
            if(flag_conflict == 0){
            WIFI_SEND();
            flag_interruptclock = 0;
            flag_pir = 0;
            }
        }

   

but now it never triggers WIFI_SEND. I'm not sure what am I doing wrong. I'm attaching my whole project. Could anyone give me a hand?

0 Likes
3 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

With 30 sec isr interval, the problem seems artificial. If isr2 occurred while isr1 is still running, you can ClearPending all interrupts at the end of isr code. But what if isr2 was fired, say, 100us after isr1 has completed? Some  timing logic with "dead time" is necessary.   

0 Likes
Anonymous
Not applicable

As @Odissey1 said above, the real solution to a software problem like this would be more software; You will need to add code to handle an "off-time" between triggers of the said interrupt function. That way, it will prevent both interrupts triggering the function within x amount of time of each other (Possibly 30s?)

0 Likes
Anonymous
Not applicable

Ok thanks for Your advices 🙂

0 Likes