I would like to use multiple (three) serial ports on an Arduino Due. Instead of polling the ports continuously, I would like to use a Serial.Event function for each of the ports. These handler functions will read out the incoming string from the port and parse the string (i.e. check for a pre-defined command and call a corresponding sub-routine).

I was wondering what is going to happen when serial data arrives at the same time at two different ports? For example, if the program is in the process of handling/parsing the first serial message, will it interrupt/abandon this process as soon as another SerialEvent on another port is triggered? Or will it complete the first SerialEvent routine before going to the second one?

2 Answers 2


The built in serialEvent() function on arduino only responds to serial port 0, called just "Serial" in the code. To respond to messages on "Serial1", use serialEvent1() on the Arduino Due there also exists serialEvent2() and so on.

EDIT: the serialEvent() handlers are not on interrupts; they run sequentially in-between loops. If the loop is blocking they do not get run, and they do not interrupt eachother.

  • I am aware of that. I meant that I intend to monitor the different serial ports with their respective SerialEventX instruction. But the same question remains: what is going to happen when, say, the SerialEvent1 function is being handled while on Serial2 a message arrives and SerialEvent2 is triggered?
    – hobie
    Commented Jun 16, 2014 at 21:42
  • They are not on interrupts, so nothing special happens. Commented Jun 16, 2014 at 21:51

That should be fairly simple to implement.

Each serial port has TX and RX interrupts. You just need to tie into the various interrupts.

Here is an example for a mbed, but it should be similar (both use ARM NVIC interrupt controllers).

To be clear, this wouldn't involve touching the serialEvent() function stuff at all, but rather implementing what it does using your own code.

If you set up your own interrupt handlers, you also get the benefit of being able to control interrupt priority yourself. The ATSAM3X has 16 interrupt priority levels, and a interrupt of a higher priority can pre-empt a lower-level interrupt.

I Strongly suggest you read the ATSAM3X datasheet. It describes the interrupt controller, as well as the rest of the processor peripherals.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.