2

I need to count the number of bytes appearing in the serial (UART bus) bus, how to count bytes in Arduino with Arduino Serial functions? is this possible?

Application - RS485 communication with multiple boards without slave ID

slave boards will send data to the master board when,

1st 10 bytes = masters send a 10byte message to all slaves

slaves listening to the bus always until it is the turn to send the data

when byte count is 10, slave 1 sends data 5 bytes to master

when byte count is 15 (10+5), slave 2 sends data 5 bytes to master

when byte count is 20 (15+5), slave 3 sends data 5 bytes to master

max count is 25 known value

1 Answers1

1

Serial.available() returns the number of bytes available for reading in the buffer.

int nBytes=Serial.available();
if (nBytes > x) {
............
............
............
}
Mat
  • 464
  • 1
  • 4
  • 8