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
if (Serial.available() > 0) { incoming[byteCount] = Serial.read(); byteCount++; }
wherebyteCount
counts the number of bytes received andincoming[..]
stores the received bytes, or something like that? Looks like a protocol that's not very fault-tolerant.