I'm having trying getting UART to work on the mega2560. I am using a uLCD-70DT to send serial data to the mega and I know that the LCD is send the right data becuase I can see it on the oscilloscope. But on the mega side of things it only ever reads FF. It knows it has data waiting in the serial queue but everything I call serial#.read() it returns FF. Both the mega and the LCD have the same UART configuration, 9600 8N1. And the grounds for both devices are connected.
I also tried this for fun. I can read and write to the mega itself perfectly fine.
chiuwe:
everything I call serial#.read() it returns FF.
Serial#.read() returns an int. The value is -1 (0xFFFF) if there is nothing in the buffer. If you store that in an unsigned char it will get truncated to 0xFF.
I do understand that Serial#.read() returns -1 if there's nothing in the buffer but Serial#.available() returns 1 so there is something. and I store it as an int and I'm only reading one byte at a time and read() is return 0x00FF not 0xFFFF.
Arduino Mega:
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
if (Serial1.available()) {
Serial.println(Serial1.read());
}
}
LCD:
#platform "uLCD-70DT"
#inherit "4DGL_16bitColours.fnc"
#constant maxBuff 50
var cutBuffer1[maxBuff];
func main()
var x := 50;
gfx_ScreenMode(LANDSCAPE) ; // change manually if orientation change
touch_Set(TOUCH_ENABLE);
I had it printing in an earlier revision. I could have also had the if statement be Serial#.available() > 0. In either case if there wasn't a byte available it should return -1 not 0x00FF right?
I fixed my problem. The LCD firmware has changed in the pass 3 months. I did updated it without looking at the changes. The function call to set the baud rate now require me to pass in the baud rate/10..