Go Down

Topic: Bit by SoftwareSerial (Read 4 times) previous topic - next topic

drjiohnsmith

I would make a few comments.

software serial was made I understand to add extra serial ports to a device that had not sufficient.
  I certainly used it to provide a 5th port on the mega when the design called for one.


I have also used it to give me multiple outputs on a design I needed, wit h no inputs. the -1 was added about that time, may be a year or so ago me thinks, but could be out there.

I think software serial was around before the mega, so was not as such designed for it, or not for it.
   its there if needed.


Paul Stoffregen

Have you tried my AltSoftSerial library?

http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html

It only supports a single instance, and requires specific pins, and uses a timer.... but it creates much less interrupt latency than normal SoftwareSerial.  In some cases (with carefully chosen baud rates), it can even be used together with AltSoftSerial and SoftwareSerial in the same project, for 3 serial ports on an Arduino Uno.

Of course, if you're using Mega, Due, Teensy3 or any other board that has multiple real hardware serial, you should always use the hardware serial before resorting to software serial.

liudr

Thanks Paul. I'll take a look. I am using MEGA with 4 serial devices and the main serial a means of debug print and future plan to send data so I ran out of 4 serials pretty quickly.

Rob and drjohnsmith, I'll remember to use -1 in the future for any software serial that only needs one pin.

Paul Stoffregen

#13
Mar 06, 2013, 01:08 pm Last Edit: Mar 06, 2013, 01:10 pm by Paul Stoffregen Reason: 1
On Arduino Mega, if you really need 6 serial ports, and 2 of them could run at relatively slow baud rates (eg, 9600 or maybe even 19200 baud)... you probably could use 2 copies of AltSoftSerial.  You'd need to make another copy of the library, change the name to something like AltOtherSerial, and edit its copy of config/known_boards.h to use the other timer.

Mega actually has 4 of those timers, so in theory it would be possible to have 4 copies of AltSoftSerial working simultaneously (at slower baud rates), for 8 serial ports working simultaneously.  Unfortunately, 2 of those 4 timers can't be used, because the input capture pin for those timers is not brought out to any location on the board.  However, if you only wanted to transmit and never receive, you could make modified copies of AltSoftSerial that only transmit.  It's the receive pins that aren't available on Mega's PCB layout.

afremont


Have you tried my AltSoftSerial library?

http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html

It only supports a single instance, and requires specific pins, and uses a timer.... but it creates much less interrupt latency than normal SoftwareSerial.  In some cases (with carefully chosen baud rates), it can even be used together with AltSoftSerial and SoftwareSerial in the same project, for 3 serial ports on an Arduino Uno.

Of course, if you're using Mega, Due, Teensy3 or any other board that has multiple real hardware serial, you should always use the hardware serial before resorting to software serial.


I wan't to second this.  I was using SoftwareSerial to talk to a serial LCD that is currently locked at 9600 baud (no documentation available).  It seriously interfered with the stuff on Timer0 (millis() and delay()) and was causing my clock project to lose massive amounts of time due to lost Timer0 interrupts.  I switched it to Paul's stuff here and it works perfectly now.  There are no more lost interrupts and no more code running for more than 1mS with interrupts disabled (gag).  His stuff works perfectly so far, but I"m not doing simultaneous send and receive.  Since he uses interrupts and apparently the PWM feature for output, I expect it to have no trouble in that situation.
Experience, it's what you get when you were expecting something else.

Go Up