I'm trying to send serial data from a Mega 2560 to an Uno. When I send data from the Mega to the Uno via the Mega's RX0 and TX0, the message gets across, but when I use RX/TX1, RX/TX2, RX/TX3, or SoftwareSerial, it fails.
Receiver (Uno): Waits for an incoming byte, displays it on an array of 8 LEDs.
#include "mj_bitwise.h" // byteToLEDs(int byte, int startingPin)
void setup () {
Serial.begin(9600);
}
void loop () {
if (Serial.available() > 0){
char data = Serial.read();
byteToLEDs((int) data, 2); // function from mj_bitwise
}
}
Sender (Mega): I include calls to three different serials, even mixing up the order, and somehow, only Serial goes through.
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
Serial2.begin(9600);
}
void loop() {
Serial1.write(7); // TX1
Serial.write(8); // TX0
Serial2.write(9); // TX2
}
My pins: When trying an alternative serial connection, e.g. the Mega's RX1 and TX1, I connect Uno:RX to Mega:TX1 and Mega:RX1 to Uno:TX. With the foregoing code running, I can switch the pins from one serial to the next, resetting the boards or not, and no matter what, only the TX0-transmission succeeds.
TMI: My desire is to send data to the Mega from a computer on RX0, then send that data to the Uno through TX1, for debugging purposes.
Oddly, the byte displayed on the Uno's LEDs is correct only about half the time. The other half the time, it's consistently the same, wrong number. E.g. sending 144 gives me either 144 (10010000) or 6 (00000110); sending 129 gives me either 129 (10000001) or 96 (01100000). Any idea why this happens?