Background: I have two Teensy 3's with RF serial transceivers attached to each to communicate back and forth. One of them REQUIRES the serial communication to use pins 7 and 8 (Serial3 device as indicated on the pinout card).
Problem: Teensy A (using Serial 1) Can send data to Teensy B (using Serial 3) and Teensy B receives it fine. Teensy B (using Serial 3) can NOT send data to Teensy A (using Serial 1). However, if I switch Teensy B RF device to use Serial 1 instead of Serial 3, it works as intended.
Earlier Trials: On a single Teensy, I can communicate from Serial 1 to 3 just fine, but not from Serial 3 to Serial 1.
Code:
Teensy A:
Teensy B:
Problem: Teensy A (using Serial 1) Can send data to Teensy B (using Serial 3) and Teensy B receives it fine. Teensy B (using Serial 3) can NOT send data to Teensy A (using Serial 1). However, if I switch Teensy B RF device to use Serial 1 instead of Serial 3, it works as intended.
Earlier Trials: On a single Teensy, I can communicate from Serial 1 to 3 just fine, but not from Serial 3 to Serial 1.
Code:
Teensy A:
Code:
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
}
void loop()
{
String stringRead;
char incomingByte;
if( Serial1.available() > 0 )
{
incomingByte = Serial1.read();
Serial.print(incomingByte);
}
while (Serial.available()) {
char c = Serial.read();
stringRead += c;
}
if( stringRead.length() > 0 )
{
Serial1.print( "Daniel: " );
Serial1.print( stringRead );
Serial.print( "Me: " );
Serial.print( stringRead );
}
}
Teensy B:
Code:
void setup()
{
Serial.begin(9600);
Serial3.begin(9600);
}
void loop()
{
String stringRead;
stringRead = gatherRFData(); //Read data from RF communication
processRFData( stringRead ); //Do something with it
stringRead = gatherLocalData(); //Read data from local Serial (testing)
processLocalData( stringRead ); //Do something with it
}
String gatherRFData()
{
String result;
char c;
while( Serial3.available() )
{
c = Serial3.read();
result += c;
}
return result;
}
void processRFData( String rfData )
{
if( rfData.length() )
{
Serial.print( rfData );
}
}
String gatherLocalData()
{
String result;
while( Serial.available() )
{
char c = Serial.read();
result += c;
}
return result;
}
void processLocalData( String localData )
{
if( localData.length() > 0 )
{
Serial3.print( "Serial 3: " );
Serial3.print( localData );
Serial.print( "Me: " );
Serial.print( localData );
}
}