I have two uC's working together: uC#1's job is to poll its GPIO ports every second or so and then communicate what it sees to uC#2 which is on another PCB about 4' away.
Anyhow, uC#1 needs to communicate 4 bytes of information - over and over again.
My goal is to make this communication as fault tolerant as possible.
I have made this work using two different scenarios:
uC#1 sends four predetermined "key" bytes and then sends the four data bytes over the UART. This process repeats over and over. uC#2, has an interrupt-driven serial port so it always stops everything it's doing to get the latest byte when uC#1 sends it and puts it into a volatile char array of size 8 bytes. I also have a volatile char pointer that is always pointing at the next slot that the next byte will be put into. Of course, I have to check if the pointer is pointing past the 8th byte to reset it back to 1st byte of the array. uC#2 then periodically sorts the circular array to find the four keys which then leads to the location of the first data byte.
uC#1 sends the four data bytes over the UART and then waits 500ms before sending them again. uC#2 has a timer that will overflow during the 500ms pause which triggers an interrupt to take the last four bytes and store them as the data bytes to be used elsewhere in the program. The interupt procedure also moves the pointer to the 4-char array back to the first slot and also resets the number of chars received to zero. I have the number of chars received in a volatile variable to make sure that four bytes were received since the last delay - otherwise a byte was lost or, perhaps, no bytes were sent.
Does anybody have an opinion on this? Is there some easy library that I don't know about to communicate serially with fault tolerance?
Right now I have only a transmit wire from uC1 to uC2. I could add another wire for bi-directional communication if it helps the process.
Any comments welcome.