How can 2 interrupts be handled in the same code? I understand that the cli command is activated when you enter a interrupt but i am doing a interrupt blinking a led at a 1 Hz frequency, and i am trying to trigger a second external interrupt whenever a button is pressed .What approach do you suggest that i should do in order to work? Thanks!
@drmattmarshall65454 жыл бұрын
It's possible to call sei() in an interrupt service routine (ISR) and thereby enable nested interrupts. Otherwise, if the button gets pressed during the LED ISR then the button interrupt will just get handled as soon as the LED ISR finishes.
@SteaM9924 жыл бұрын
@@drmattmarshall6545 I tried also your sugestion but still, the ISR for blinking a led is executed when the button is pressed (when PD2 is tied to ground). Otherwise, the led is in sort of a bouncing effect, similiar to not having pull up resitors( is either on, or off, or it flickers..its weird). github.com/tandrei96/Interrupts-Atmega328p_personal-projects/blob/main/double_interrupts/double_interrupts.c .I appreciate the help !
@drmattmarshall65454 жыл бұрын
@@SteaM992 Your code looks nice, IMO. There's nothing I see that might cause weird behavior. I should think that nested interrupts would be unnecessary since your ISRs are so short that even if the button-press routine has to wait for the LED-blink routine the performance should be fine. My only suggestion right now is to declare cnt as a volatile variable but I'm pretty sure that's not causing any problems for you.
@SteaM9924 жыл бұрын
@@drmattmarshall6545 yup, is ok even though is not initialized as volatile... would be cool a future video that tackles 2 or 3 different interrupts, maybe you get the same error as me haha:) Cheers!