Go Down

Topic: Open Source MULTIUART Project, Add more UART Serial Ports to your projects (Read 106 times) previous topic - next topic

RowlandTechnology

If you're a fan of electronics then you like me will often find it annoying on the lack of hardware serial ports on modern devices. Many modules like the Wifi ESP8266 and the Bluetooth HC-06 are available for peanuts but they each require a UART based serial peripheral on your controller to work effectively. In fact a huge range of external electronics can be added to your system via a serial UART connection: GPS, GSM (mobile phone), RFID, RS232, LIN, Ethernet, Zigbee, Modbus, DMX, 4D systems graphical LCDs to name a few more.

Most modern microcontrollers and devices like the Raspberry Pi have at least one serial UART peripheral so you can do a lot with these devices. However now and then you need to combine several communications style modules together into a single design. A recent project I undertook was a mobile alarm system which used Bluetooth proximity to arm / disarm the system, GPS to track the location, Accelerometer to track movement and GSM based SMS messages to inform the owner where their item is.

The Arduino Mega 2560 offers four serial UART peripherals but what if that is not enough or you need something more affordable for mass production. To move to a different chip may mean rewriting your entire code so is there an easier way?

These modern microcontrollers commonly also feature a peripheral named SPI which is typically a lot faster then a UART based serial peripheral and can be used to talk to multiple devices by use of individual chip select signals from the controller. If the controller does not have an SPI peripheral then it can simply be driven using a bit banged software approach using standard I/O pins with no major downfalls. By using the SPI interface and my design you can communicate with up to four serial UART peripherals simultaneously.

Here is my open source project to create a SPI to 4 UART bridge code name MULTIUART or SPI2UART.
Instructables - SPI-to-4-x-UART-Bridge-MULTIUART

I have now created an Arduino library to drive the hardware.
Github - MULTIUART


Included in the library is a test program I created to test the MULTIUART boards using an Arduino Uno and transmitting data back to the PC using the serial library.


If you're interested then a small number of boards are currently available on sale on eBay.

Many thanks and enjoy!

/dev

So, that's a 16-bit PIC on a board, acting like a peripheral to an 8-bit AVR?  Alrighty then.

Quote
If  your  you're  a fan...
Fixt.

Quote
The Arduino Mega 2560 offers  two  four  serial UART peripherals
Fixt.

Quote
I have now created an Arduino library
You should find a way to leverage the Stream class (which leverages the Print class).  I would suggest a grouping class that contains an array of 4 instances derived from Stream.  Those instances could be used by any code or library that expects the Stream (or Print)class.  It would look just like the current HardwareSerial usage:

Code: [Select]
class MultiUART;

class MultiUARTPort : public Stream
{
    uint8_t    id;
    MultiUART *group;
    friend class MultiUART;

  public:
    // Serial port controls
    begin( uint32_t baud ... );
         ...

    // Override all pure virtual methods of Print and Stream...
    virtual size_t write( uint8_t c ) { group->TransmitByte( id, c ); return 1; }
    virtual int available() { return group->CheckRx( id ); }
         ...
};

class MultiUART
{
    MultiUARTPort port[4];
  public:

    MultiUART()
      {
        for (uint8_t i=0; i<NUM_PORTS; i++) {
          port[i].id = i;
          port.group = this;
        }
      }

    MultiUARTPort& operator []( uint8_t i ) { return port[i]; }
      ...
};

MultiUART mu;

void setup()
{
  Serial.begin( 9600 );
  mu[0].begin( 9600 );
}

void loop()
{
  if (mu[0].available())
    Serial.write( mu[0].read() );
}

You should also find a way to get rid of the 50us delays.  The above loop will delay 250us for each character.  This will limit the baud rate to 38400.

I would also recommend using SPI transactions to avoid conflicts with other SPI devices, and perhaps concurrent transfers (reading and writing with one transaction).

Cheers,
/dev

RowlandTechnology

Some great info there, thanks.

I'll have a play with the library and see if I can improve things as per your suggestions.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy