I'm trying to read and write data to a LIN Bus, which is a single wire bus. As such, only one "module" (my PIC is a module in a network) is allowed to talk at a time. I'm using an MCP2004 LIN transceiver, and my device is a slave on the network. I'm unsure what hardware the master and other slaves utilize.
The problem I'm running into is that sometimes, a byte is pushed onto the Bus at the same time I'm pushing one out, which results in a frame error.
In my firmware, I have an interrupt service routine for RX from that Bus, and it has the highest ISR priority set (7). The problem is that as the program continues to execute, it's not always possible for me to tell if there's data thats been received.
Right now, I check my RX buffer size prior to transmission, but sometimes the byte is received after that conditional, but right before I actually write data to the bus. I'm also checking UxSTA, but I doubt that helps, since if there's data on the hardware buffer, the program would be in the ISR, and not my main code.
It may be worthy to note that I'm not transmitting in an ISR.
What's the best way for me to handle this contention? Is it advisable to keep the program in the ISR for the entirety of the data reception? The protocol does contain a message length byte and a checksum.