Arduino as RS-232 Multiplexer

Hi all!. I need to write some code to multiplex my PC rs-232 Port.

So what i'm thinking is use my Arduino to do this, but not using internar USART(pin 2;3). My idea is create some software's serial ports on arduino, buffer the receiver data and send it to the same RS-232 port or to a SPI bus, including a byte to identify the incoming data's port.

Can this Arduino do this?, with 3-4 ports i'm ready.

Best Regards !! Frank

Funny you should mention this; I’ve got a couple of shield prototypes ready for software development. One is a MAX3110 SPI interfaced UART, the other is an ATmega8 interfaced via I2C. The ATmega model should be stackable (to 127 units, theoretically, but I suspect there will be power and structural problems before I get that far :slight_smile: ); the MAX3110 will need a different SS line for each device and I didn’t allow for that on my PCB.

I haven’t started on any software yet, so there’s really nothing useful so far. I have located a protocol, and have an idea how to handle the host side for my unix boxes.

How do you plan to demux it on the windows side?

-j

A Ham Radio to here!.

My protocol it's easy, to any string incomming for some port, add a number in the begining to tell to the PC what is the channel who is sending data. For send data from PC to serial the same idea, include one char like header to mux the port and let the data to that port. Of course this char must be erased in the Mega.

My B plan is use 4 Mega8, one like master and the others like slaves, polling them via SPI, and using the same logic to switch the port/to know what's the incomming port. Other idea is use some I/O to tell to master device who of this Mega8 have data, similar to a INT3,4 from PC.

But i realy want to use only one device, to keep my board small, i'm gonna to test this using Arduino software's serial ports, i must read all the inputs pins on the same loop, and adjust the delays, RAM this device have a lot so buffer of 128 bits can be handled.

The problem with software is what happends when two devices are sending data, this devices only have Rx and Tx, i don't have RTS so i can't tell to the device Wait! to send data.

Other idea is use a 16625 from PC, but i don't want to use specifics IC because them are hard to buy here in my country.

I have build one of this, but this is a switch, if the device must be pooled is great because i switch the port, i have one working with for serials, i use the DTR and RTS to switch them, and works Great!. But now the idea is build a real port and not a switch! :o

For Rs-232 write/read in PC i always use the MSCOMM from VB6, in fact i have writed a Class in VB who hide the Mscomm.lib and keep private for all the software, i can write a DLL who expose only the functions i need, looks like a DLL with protocol inside, and it open/close the port, set speed and pharse the data/binary etc. Similar to a driver.

Best Regards Frank

Via I2C isn't a good idea, i test some time ago write a 24C16 with a F84 mcu, and for this you must have a buffer, this I2C port it's very slow, SPI run more or less than 8 Mhz, SPI less than 100Khz.

Adding a note only!

Best Regards Frank

I think I2C runs at 400kHz (“fast mode”), but even 100kHz (“standard mode”) would work since my application is 1200 baud packet and 4800 baud NMEA. I think I2C can keep up; hopefully I won’t find out later I’m wrong. The uplink port will run at 19.2k and higher.

Rather than some generic RS232 data multiplexing, I may use MKISS, since it’s packet data anyway…

The problem with your software serial test model is that software serial is blocking - once you start a read, it blocks until a timer expires, or a byte is read. This will cause you to miss data on other software serial ports. Reading from more than one software serial port is extremely limited.

-j

The best idea is use more than only one Mega and is ready. The USART from this chips work great and them are realy cheap.

I'm gonna to write some code to get/let data from serial and send it to the SPI ports, but what i realy want to do is something like an int to know what is the IC with data and too a RTS signal and a CTS to connect the serial device on the MCu.

The maxim IC are expensive and hard to find so i must keep with this. what i do not remember is if the rs232 use NRZ to mark the 0 and 1 signals, i'm think this port is fully unsyncronized and the 1 and 0 singnals are defind reading the wire in time intervals.

Best Regards Frank

So they can work? http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1201476854/5#5

The CPU from this PAD is an ATMEGA168?, and them are connected via I2C, one master and two slaves? Nice!, now what i'm thinking what are the I/O they are using!.

Im starting to play with this!!

Best Regards Frank

My hardware is this, an ARM7 CPU and two AtMega 8 all connected via I2C. :o
Both Atmega with diferent Id, and a function mix in this I2C lib to Get and Retreive data from the Rs-232 to I2C and viceversa.

here is my ugly code:

#include <Wire.h>

void setup()
{
Wire.begin(1);
Serial.begin(9600);
Serial.println(“Inicio”);

Wire.onRequest(requestEvent);
Wire.onReceive(receiveEvent);

}

void loop()
{
delay(20);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany){

char c = Wire.receive();
Serial.print(c);

while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.receive();
Serial.print(c);
}}

void requestEvent()
{
Wire.send(“1234567890”);
}

Now on requestEvent the data is sent to the I2C, but the other part get data and print it only one time, but keeping send data onrequestevent.

So what event i must kill when i need print the data incomming to the AtMega from the ARM port?

It’s a HandShake problem!!! :stuck_out_tongue:

Ideas?

Best Regards
Frank