So I've been playing with the my code and I am seeing some weird stuff which I would be grateful if somebody could explain to me what going on!!! it's driving me crazy!!!
So this is the code I'm using:
#include <SoftwareSerial.h>
#define BAUD 9600
SoftwareSerial mySerial(3, 4); // RX, TX
uint8_t n=0;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(BAUD);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial1.begin(BAUD,true);
// set the data rate for the SoftwareSerial port
mySerial.begin(BAUD);
Serial.println("READY!");
}
void loop() {
uint16_t indata=0;
Serial.print("SS TX = ");
if(n<=15) Serial.print("0x0");
else Serial.print("0x");
Serial.print(n,HEX);
Serial.print(", ");
mySerial.write(n);
delay(500);
n = (n+1)%256;
Serial.print(Serial1.available());
Serial.print(", S1 RX = ");
while(Serial1.available()>0){
Serial.print((int)Serial1.read(),HEX);
}
Serial.println("");
}
and this is the output I am seeing:
READY!
SS TX = 0x00, 1, S1 RX = 0 //expecting 100
SS TX = 0x01, 1, S1 RX = 1 //expecting 101
SS TX = 0x02, 1, S1 RX = 2 //expecting 102
SS TX = 0x03, 1, S1 RX = 3 //expecting 103
SS TX = 0x04, 1, S1 RX = 4 //expecting 104
SS TX = 0x05, 1, S1 RX = 5 //expecting 105
SS TX = 0x06, 1, S1 RX = 6 //expecting 106
SS TX = 0x07, 1, S1 RX = 7 //expecting 107
SS TX = 0x08, 1, S1 RX = 8 //expecting 108
SS TX = 0x09, 1, S1 RX = 9 //expecting 109
SS TX = 0x0A, 1, S1 RX = A //expecting 10A
SS TX = 0x0B, 1, S1 RX = B //expecting 10B
SS TX = 0x0C, 1, S1 RX = C //expecting 10C
SS TX = 0x0D, 1, S1 RX = D //expecting 10D
SS TX = 0x0E, 1, S1 RX = E //expecting 10E
SS TX = 0x0F, 1, S1 RX = F //expecting 10F
SS TX = 0x10, 1, S1 RX = 10 //expecting 110
SS TX = 0x11, 1, S1 RX = 11 //expecting 111
SS TX = 0x12, 1, S1 RX = 12 //expecting 112
SS TX = 0x13, 1, S1 RX = 13 //expecting 113
SS TX = 0x14, 1, S1 RX = 14 //expecting 114
SS TX = 0x15, 1, S1 RX = 15 //expecting 115
SS TX = 0x16, 1, S1 RX = 16 //expecting 116
SS TX = 0x17, 1, S1 RX = 17 //expecting 117
SS TX = 0x18, 1, S1 RX = 18 //expecting 118
SS TX = 0x19, 1, S1 RX = 19 //expecting 119
SS TX = 0x1A, 1, S1 RX = 1A //expecting 11A
SS TX = 0x1B, 1, S1 RX = 1B //expecting 11B
SS TX = 0x1C, 1, S1 RX = 1C //expecting 11C
SS TX = 0x1D, 1, S1 RX = 1D //expecting 11D
SS TX = 0x1E, 1, S1 RX = 1E //expecting 11E
SS TX = 0x1F, 1, S1 RX = 1F //expecting 11F
SS TX = 0x20, 1, S1 RX = 0 //WATS GOING ON HERE!!!! expecting 120
SS TX = 0x21, 2, S1 RX = 1E1 //SHOULD BE ONLY ONE DATA AVAILABLE NOT 2!!! OUTPUTING 2 BYTES 0X01 AND 0XE1. expecting 121
SS TX = 0x22, 2, S1 RX = 1E2 //??
SS TX = 0x23, 2, S1 RX = 1E3 //??
SS TX = 0x24, 2, S1 RX = 1E4 //??
SS TX = 0x25, 2, S1 RX = 1E5 //??
SS TX = 0x26, 2, S1 RX = 1E6 //??
SS TX = 0x27, 2, S1 RX = 1E7 //??
//WIERD BEGAVIOUR CARRIES ON TO 0XFF. DATA READ BACK ON SERIAL1 NOT COHERENT WITH TX!?
the really weird thing is that it does not matter whether I set "Serial1.begin(BAUD,true);" to TRUE or FALSE; i'm getting the same output!
As mentioned in my first post I've replace the hardware serial files in the arduino folder with those provided by Nick for 9 bit serial communication.
Any help understanding this problem is most welcomed!