Why Serial1.available() always true

Are you sure that you mean Serial1.available() and not Serial1.read() ?

Serial1.read() will return 0xFF if there is nothing to read

while (Serial1.available()>0) {
	uart_rec_buf[uart_rec_buf_index] = Serial1.read();
	uart_rec_buf_index++;
	dataReceived = 1;
}

if (dataReceived) {,,,,

Hi, dear UKHeliBob,
i checked first Serial1.available() then read and set flag "dataReceived". i got "dataReceived" true because the statement afterwards was executed.

i disconnected my level sensor and now keep receiving "FF134FFFFEBABF558", refer to screen shot attached below.

"134FFFFEBABF558" seems good, however, where came "FF" from?

Regardless of how many bytes you receive you print 10 bytes from the uart_rec_buf array. Is that deliberate ?

actually, i expect 9 bytes. i just want to be confident all the data are received and printed when i debug my code.

the thing incredible is that i keep receiving "134FFFFEBABF558" now even i already disconnected everything from the MAX485 connected to Serial1.

make a very simple passthrough sketch.
Just read from Serial1 and print what you get on Serial1 to Serial

Show your sketch.
Show the results.

Crossed serial connections?

The labeling on your diagram is correct, but it's reversed top to bottom. Are the physical connections correct??

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.