Go Down

Topic: Serial Communication and Interrupts (Read 868 times) previous topic - next topic


Does this apply to the hardware serial port only or also to software serial ports (e.g. NewSoftSerial)?

NewSoftSerial uses interrupts, too. So, yes it applies to both.

While sending a byte, does the interrupt get lost or does the ISR automatically get called once the byte has been sent?

As interrupts, of a particular type, they get queued. When interrupts are re-enabled, the interrupt handlers for queued interrupts will be called. The queue can only hold one event of a given type, so if interrupts are disabled for any length of time, interrupts can be lost.


Thanks a lot, that clears it up... ;-)

Location: Berkshire, UK
My Astro and DIY projects website: http://yesyes.info/


I'm having trouble visualising how you're going to use this but I get the impression that you're planning to put control logic remotely and have that send motor demands to an Arduino that controls the motors.

In that case, rather than having all these elements screaming data back and forth, I'd suggest a different protocol consisting of a keepalive which just indicates what the current demands are, which could be sent at quite long intervals, and a 'delta' command telling it when the demand has changed. This fees up a lot of network and processing bandwidth on both sides which means you can afford to do a lot more other stuff, and will probably also be more responsive.
I only provide help via the forum - please do not contact me for private consultancy.


Nov 24, 2011, 11:14 pm Last Edit: Nov 24, 2011, 11:18 pm by dc42 Reason: 1

No. During sending of a character, interrupts are disabled, so that all bits are send together. The are enabled again until the next character needs to be sent. Your interrupt can only fire when interrupts are enabled. It will cause serial data sending to be on hold while your interrupt does it's thing, so you need to make it quick.

True for software serial, but not for hardware serial. When sending serial data via the hardware serial port, interrupts remain enabled; but the hardware handles the bit timing, so interrupts do not affect it.

Interrupt service routines should be kept short and fast. If your ISR take more than one character time to execute, then you could lose incoming characters.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Go Up