Reading from multiple HW and SW serial streams

Status
Not open for further replies.
I'm attempting to read from a number of different sources as serial streams using a Teensy 3.1, and output a combined serial stream to a a linux board (Odroid C1). It has grown so that there are 4 input streams. I've dedicated one HW UART for output, leaving two HW UARTs for input, plus two planned SW UARTs. The HW ports were working. I added 1 SW port and got no data on my full system.

I set up a test with two Teensys directly connected from UART to UART. at 230400 baud, it worked immediately. When I switched to a software serial for receive, I got no data. I confirmed with a scope that it was sending. I added a print from SW side, and saw that there was a signal on the software Serial send as well.

Tried changing from the SoftwareSerial lib to AltSoftwareSerial lib. The code below tries to read the ports and echo each char to console.

Questions:
Is is reasonable to expect 3 HW and 2 SW comms to work on a T3.1?
Is 230400 too fast for SW serial? (With re-wiring, I could swap the fast and slow sources)?

Thanks.

Teensy_Comm.PNG

Code:
// get data from 4 UARTS, write to 5th UART; echo to LINUX UART and serial console
// for T3.1
// 4/3/2015

// reference code: www.pjrc.com/teensy/td_uart.html
// https://forum.pjrc.com/threads/28183-Is-there-a-quot-line-receiver-quot-library-for-e-g-the-serial-ports
//
// https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
// Need AltSoftSerial library for multiple instances? Is 230400 baud way too fast?

#define RF_SERIAL Serial3     // 1: rx=0, tx=1  3: rx=7, tx=8  2: rx=9, tx=10
#define ODROID    Serial2     // 1: rx=0, tx=1  3: rx=7, tx=8  2: rx=9, tx=10
#define TEENSY    Serial1     // 1: rx=0, tx=1  3: rx=7, tx=8  2: rx=9, tx=10
#define RF_SERIAL_BAUD  9600
#define ODROID_BAUD     115200
#define TEENSY_BAUD     115200
#define SOFTSERIAL_BAUD 230400

//#include <SoftwareSerial.h>
#include <AltSoftSerial.h>  // swapt out for this lib...

const int softRxPinA = 3;
const int softTxPinA = 4;
const int softRxPinB = 5;
const int softTxPinB = 6;

AltSoftSerial softSerialA(softRxPinA,softTxPinA); // RX, TX
AltSoftSerial softSerialB(softRxPinB,softTxPinB); // RX, TX

const byte ardLEDpin = 13;   // port pin location of on-board LED T3.1

char inChar0;
char inChar1;
char inChar2;
char inChar3;

void setup() {
  pinMode(ardLEDpin, OUTPUT);     

  // required?
  pinMode(softRxPinA, INPUT);
  pinMode(softTxPinA, OUTPUT);
  pinMode(softRxPinB, INPUT);
  pinMode(softTxPinB, OUTPUT);

  //startup indicator on LED
  for (int i=0; i<4; i++) {
    digitalWrite(ardLEDpin,1);
    delay(40); 
    digitalWrite(ardLEDpin,0);
    delay(240);
  }
  // initialize comm ports
  RF_SERIAL.begin(RF_SERIAL_BAUD, SERIAL_8N1); // configure Teensy HW UART serial port
  delay(1);

  TEENSY.begin(TEENSY_BAUD, SERIAL_8N1); // configure Teensy HW UART serial port
  delay(1);

  softSerialA.begin(SOFTSERIAL_BAUD);
  delay(1);

  /*  
   softSerialB.begin(SOFTSERIAL_BAUD);
   delay(1);
   */

  ODROID.begin(ODROID_BAUD, SERIAL_8N1); // configure Teensy HW UART serial port
  delay(1);

  int t0 = millis();
  Serial.begin(115200); // set rate doesn't matter for teensy 3
  while (!Serial && (millis() - t0 < 1000)) {  // continues if the monitor window is never opened
    ; // wait for serial port to connect. Needed for Leonardo & Teensyduino 3
  }
}

void loop() {
  // read from each serial input port and stream to UART output port (and console for testing)
  if (Serial.available() > 0) {
    inChar0 = Serial.read();    // read in character
    // echo back values to both ports
    Serial.print(inChar0);
    ODROID.print(inChar0);
  }
  if (RF_SERIAL.available() > 0) {
    inChar1 = RF_SERIAL.read();  
    // convert to ascii
    Serial.print(inChar1);
    ODROID.print(inChar1);
  }

  if (TEENSY.available() > 0) {
    inChar2 = TEENSY.read();  
    // convert to ascii
    Serial.print(inChar2);
    ODROID.print(inChar2);
  }

  if (softSerialA.available() > 0) {
    inChar3 = softSerialA.read();  
    Serial.print(inChar3);
    ODROID.print(inChar3);
  }
  /*
  if (softSerialB.available() > 0) {
   inChar3 = softSerialB.read();  
   Serial.print(inChar3);
   ODROID.print(inChar3);
   }
   */
  delay(1);
}
 
Status
Not open for further replies.
Back
Top