Multiple Serial Port (8 UART – 16 Tx/Rx) Object

Share on facebook
Share on twitter
Share on linkedin
Share on email
Share on print
Table of Contents

The Propeller 2 can manage multiple UARTs simultaneously and be an aggreator of many serial inputs. This driver is useful for interfacing with multiple serial devices (GPS, sensors, etc) functioning in parallel. This application uses smart pins and only one of eight cogs in the Propeller 2.

This example shows how 8 full-duplex UARTs may be configured on the Propeller 2 using 16 I/Os, on any pins 0 to 63. These UARTs may be configured in any combination of transmitters and receivers at any baud. The code provided in these examples runs on PNut, Propeller Tool for Windows, and FlexProp.

The terminal displays above are showing characters received from serial pin 63 and sending-receiving it via pins 3-2-5-4-7-6-9-8-11-10-13-12-15-14 and finally back to pin 63, with Propeller Serial Terminal and FlexProp Terminal, respectively. 

Three demonstrations are provided in the zip code below:

  • One (1) full-duplex serial port (UART) using (2) I/O (mpx_demo2.spin2)
  • Two (2) full-duplex serial ports (UARTs) using (4) I/O (mpx_demo4.spin2)
  • Eight (8) full-duplex serial ports (UARTs) using (16) I/O (mpx_demo16.spin2)

It is possible to modify the driver to support more than 16 I/Os as the P2 could configure all 64 pins to be used as serial UARTs. 

Starting the Driver

The following instruction starts a new cog with the PASM driver code as follows:

@port_control is the pointer to the port control and parameter buffers. To stop the driver cog, execute the following instruction:

The driver continuously scans the port_control buffer to determine which of the 16 possible pins/ports are running UARTs. For those which are, the driver checks to see if it is a transmitter pin/port and if so checks the relevant buffer for a character. If a character is in the buffer it will transmit the character. If the pin/port is a receiver, the driver will check to see if a character is available from the smart pin, and if so it will read it and put it in the relevant buffer.

The smart-pins are started/stopped using the start/openport/closeport methods.

Configuring the Pins/Ports

There are two methods (calls) that can be used to configure the pins/ports. The first configures a single full-duplex port:

The second method (call) configures just a single port at a time. A transmit pin/port and a receive pin/port is possible per object:

The closeport method (call) closes the pin/port:

Methods (calls) Provided

There are additional configuration methods (calls):

The following are the basic methods (calls) for the transmitter pin/port:

The following are the basic methods (calls) for the receiver pin/port:

In addition to the above transmit methods, the following unformatted string methods (calls) are provided:

In addition to the above transmit methods, the following formatted string methods (calls) are provided:

In addition to the above transmit methods, the following methods (calls) to convert values are provided:

Buffers (in hub memory)

The calling program must provide the following contiguous buffers in hub memory:

Programming Language
Tools and Operating System
Document Author
Source Code Author
Table of Contents
5 1 vote
Article Rating
Notify of
Inline Feedbacks
View all comments