Multiple interrupts

Hi All,

I have a program written in Arduino101 that uses CurieTimerOne.start(5000, &SensorReading) interrupt to read a sensor every 5 ms. In addition, I would like to use attachInterrupt(digitalPinToInterrupt(2),A1, FALLING) to run a short code in the ISR with a higher priority based on falling Pin2.
As a result, I don’t receive all of the external interrupts when Pin2 falls down. Instead, I receive all the first interrupts in time!

From this link: uart - How to set interrupt priorities in Arduino? - Stack Overflow, I see that the external interrupts should have higher priority than the timer interrupts. However, I cannot see this in practice! Anybody can recommend what to do to receive all the second interrupts while the first interrupt (currie…) works in the meantime?

Thanks a lot for any help.

Anybody can recommend what to do to receive all the second interrupts while the first interrupt (currie...) works in the meantime?

You didn't post any code, but I'm going to guess that you are doing too much in the interrupt handlers, making them take too long. The solution is quite simple. Don't do that.

I just have a very simple code to see if the external interrupt occurs as follows:

void A1()
{
Serial.print(F("\n...Interrupt...\n"));
}

mebab:
I just have a very simple code to see if the external interrupt occurs as follows:

void A1()
{
Serial.print(F("\n...Interrupt...\n"));
}

That clearly indicates that you do now know what you can, and can not do, in an interrupt service routine.

Serial.print() relies on interrupts to make room in the outgoing buffer. Interrupts are disabled during an ISR. So, when called from an ISR, print() may have a LOT more work to do to force all the stuff that should happen "in the background" to happen now.

Do NOT call Serial.print() in an ISR.

A1 is a dumb name for an interrupt handler. There is not a clue in the name as to what the function does. Why would you use such a name?

Thanks, PaulS! even with removing 'Serial.print()', I have the same problem. I replaced it with the following:

void A1()
{
ww++;
}

and I print 'ww' outside A1(), during my main loop (main loop time is 10 sec). However, no improvement yet!
About the name (A1), the exact name in my code is Req_Synch1(). I just used 'A1' to shorten my question.

Make sure you don't post your actual code, whatever you do!

evanmars:
Make sure you don't post your actual code, whatever you do!

And, do not tell us whether that is supposed to be the external interrupt handler or the timer interrupt handler.

the exact name in my code is different and meaningful. I just used 'A1' to simplify my question.

Why did you think that necessary?

Thanks, PaulS!

Sorry! I didn't get your point! Do you need anything else to be added to my given question? The ISR related to the external interrupt is just what I wrote previously. The ISR based on CurieTimerOne handler for 'SensorReading' is in the following:

void SensorReading()
{
F_ReadyforComp = 0;

Ut=Ut+1+5.0*random(0.1,5);
if (Ut >= 250)
{
Ut = 0;
}

double Yt =Ut; // For test

in[C_Input] = (int)(Yt);

Yt1 = Yt;

++C_Input;

if (C_Input >= in_len)
{
F_ReadyforComp = 1;
C_Input = 0;
}
}

@mebab, if you really want help then post a complete program that illustrates the problem and tell us in detail what actually happens when you run the program and what you want it to do that is different.

...R

Agree with you that sometimes looking at all the code is required. I thought maybe diving into my long code of 2500 lines which works together with several shields (in receiver and transmitter sides) will be boring and won't execute in your side without my developed shields. That's why tried to shorten my problem.

Fortunately, I could find the root cause of the problem of interrupt that was due to not properly activating the Pin2 of Arduino. The Arduino Pin2 is connected to DIO0 of a LoRa module and it is something that I need to focus on. When I give enough time to wait for receiving a packet, interrupt works fine. Otherwise, it doesn't.

Let me work on this issue while I have all the hardware and software required and tell you if I could solve it.

Thank you for all your comments.