I'm working on a project where I have to send some setup data from my computer (C#) to my Arduino Mega 2560. I'm focussing on the communication part now. I wrote this piece of test code. The purpose is: I send a byte with C#, the Arduino receives it, waits a second and sends it back. This is to check if I receive the same as I send.:
const int ledPin = 13;
while(!Serial.available()) // wait until data is received
input1 = Serial.read();
if (input1 <128) // just a check that I don't receive random crap
Serial.write(input1); // send the data back to check
My problem: when I set the serial speed to 4800 or 9600, everything works fine, but when I set it to a higher value (28800 or 115200) the delay(1000); takes 5 seconds! How is this possible?
The problem must be in the Arduino, because first the RX led blinks, then 5 seconds nothing happens, and then the TX led blinks.