Arduino DUE Serial

Hi everybody!

I wanted to know if with the Arduino DUE is possible to send data through serial (like Serial.write) while at the same time keep running other operations in the background. To clarify I would like to constantly read something and in parallel make some calculations and send them through serial.

Thanks for your help.

Yes, it works quite well.

There is a serial buffer of 128 bytes on the Due, so you need to look at the serial port often enough that the buffer doesn't completely fill.

OK great!

Do you know how should I run it as well? Coud a void loop for the readings work? but then how do I run the calclations and sending (and check the buffer) in parallel?

MorganS:
Yes, it works quite well.

There is a serial buffer of 128 bytes on the Due, so you need to look at the serial port often enough that the buffer doesn't completely fill.

MorganS, he did not specificly say he wanted to read the serial constantly, just "something".

SilverRob, what do you want the Due to read?
Is that serial data? Input pins? A good book? :slight_smile:

Usually you use interrupts, serial or input interrupts, to check and run specific code.
While these interrupts don't occur, you can run other code like calculations and sending data.

Actually no, Slider, that's not the way it's usually done in Arduino. I'm not saying you're wrong but the Arduino framework is not intended to allow serial interrupts. It was attempted once. The serialEvent() function was supposed to be an interrupt but it isn't. I don't know exactly why the project was abandoned.

Loop() is supposed to run at a high frequency. That means that each time you enter loop(), you don't do long delay()s and you don't do any time consuming things like waiting for a motor to reach its end stop. The loop should check all the inputs - including serial - do some processing and then set the outputs. If the motor hasn't reached its planned position or the user is still thinking about pushing a button, then you don't wait. That input will become active at some time in the future, so loop() can deal with it in the future.

Serial and SerialUSB DO use interrupts for both send and receive....

Regards,
Ray L.

Yes, but you don't get to put your own ISR into those places, not without breaking the Arduino Serial library or doing some serious rewriting.

MorganS:
Actually no, Slider, that's not the way it's usually done in Arduino. I'm not saying you're wrong but the Arduino framework is not intended to allow serial interrupts. It was attempted once. The serialEvent() function was supposed to be an interrupt but it isn't. I don't know exactly why the project was abandoned.

Loop() is supposed to run at a high frequency. That means that each time you enter loop(), you don't do long delay()s and you don't do any time consuming things like waiting for a motor to reach its end stop. The loop should check all the inputs - including serial - do some processing and then set the outputs. If the motor hasn't reached its planned position or the user is still thinking about pushing a button, then you don't wait. That input will become active at some time in the future, so loop() can deal with it in the future.

You're right indeed, I framed that sentence wrong.

It's not an interrupt, I checked my own projects, I just check if there's data in the buffer, only then call the serial function. And it is in my Loop().