Go Down

Topic: Question re: multiple serial streams (Read 1 time) previous topic - next topic

philb

I just started working with a TTL serial device and am wondering how to do what I want to:  how does one manage multiple simultaneous serial streams?  For example, I have the TTL device that transmits at 4.8k (fixed) on digital input 0 and I want to take its output along with various analog and digital readings and feed a stream back out via USB to a monitoring computer but need a much higher data rate than 4.8k which I have to set the serial speed to in order to talk to the TTL device.

My understanding (and experience when trying, and failing, to upload a project while the TTL device was connected) is that the TTL interface is how the Arduino talks to the USB device so I'm wondering how others address this need?

kg4wsv

Quote
My understanding ... is that the TTL interface is how the Arduino talks to the USB device

That is correct.  The UART is hard wired to digital 0/1 and the USB/RS232 adapter.

Quote
I'm wondering how others address this need?

There's a bit-banged "software serial" approach (I'd use this one), or you can step up to the Arduino MEGA which has 4 hardware UARTs.

-j

philb

Quote
There's a bit-banged "software serial" approach (I'd use this one)


Thanks, I'll have to play around with that and see if that will do what I need.  Looks like I've got some reading to do to understand what the limits of what I can do with the base Arduino board are before being forced up to a multi-UART design like the MEGA.

dpharris

You might want to look at http://www.piclist.com/techref/microchip/16F84-rs232-8ch-ba.htm  which is 8-serial channels at 9600 baud on a PIC16F84.  

The algorithm is very clever, and uses a vertical register technique, and you may be able to adapt it to your needs on an AVR.  

Do let us know.

David
Dr. David Harris
OpenLCB Dev Team

emdee

I've been wondering about this myself. With an Arduino MEGA it would make a lot of sense if there was some way of specifying the serial port when doing a Serial.begin(), but the Serial object is predeclared, which would make it impossible to have multiple serial streams on it even if you could point it at different ports... which I guess leaves us with the SoftwareSerial library :-?

mem

Quote
With an Arduino MEGA it would make a lot of sense if there was some way of specifying the serial port when doing a Serial.begin(), but the Serial object is predeclared, which would make it impossible to have multiple serial streams on it even if you could point it at different ports


Hi emdee, what is the problem?  Could you give an example that clarifies what you would like to do.

emdee

Ok,

The ATMega 128 has multiple serial ports: (RX0,TX0),(RX1,TX1),(RX2,TX2)

Serial.begin(9600) sets up serial communication on (RX0,TX0) at 9600 baud.

So now lets say I want bidirectional communication with another Arduino, as well as writing to a serial LCD. Unless I'm totally stupid (ok, maybe I am anyway), the Serial class object won't address communication on the other serial ports: (RX1,TX1), and (RX2,TX2).

Let's call (RX0,TX0) COM1, and the others COM2, and COM3.
If these were some sort of appropriate DEFINEs, and there was access to the predeclared Serial object's class (lets call it SerialClass), then you could conceivably pass the COM port to the Serial class constructor in order to communicate with the desired devices. Perhaps something like:
Code: [Select]

 SerialClass Serial, myLCD, my328;

 Serial.begin(9600,COM1);
 myLCD.begin(9600,COM2);
 my328.begin(9600,COM3);



Hopefully something like the above approach could utilize the hardware capabilities rather than the extra memory overhead of the SofwareSerial library.
Stop me if I'm making any sense... :-?

mem

I presume you mean the ATmega1280 (as used on the mega board, the ATmega128 is the one on the Wiring board an has two uarts)

Does the information in this thread answer your question?

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1241785046/2#2

emdee

Aha, very nice. Now I see that the language reference page has this information too. Doh!

BTW I realized after my last post that the Arduino MEGA (yes the 1280) actually has 4 serial ports, not three.

Thanks

Go Up