Hi Mike,
I’ve made some progress with the USART comms between two 16F877 PICs, though I must admit it was a struggle.
I managed to resurrect my serial comms test board that’s been knocking about in a draw for four years and, surprisingly, it still worked!
I added the USART wires (blue and yellow in the photo) and loaded both PICs with the same display code that I use for the Control and Display Unit (CDU, the grey box).
I modified both codes, connected my PICOSCOPE oscilloscope and, relatively easily, managed to start transmitting 7 bytes of data from the CDU’s PIC.
The PIC code, that would be in the boat, was modified to receive the data and display on the LEDs. That PIC code was then changed to successfully transmit 63 bytes of data, but……….
All was going well until I tried to write the receiving interrupt code in the CDU’s PIC. I literally went around in circles with transmit, receive, transmit, receive - not being able to tell which bit of code was causing problems. I finally had to cut the yellow wire to break the loop and found it was the receiving code in the CDU’s PIC that was playing up.
Finally after five days of serious contemplation, I found that the servicing order of the receive and transmit interrupts was crucial. Unlike most interrupts the transmit interrupt flag TXIF cannot be cleared in code and has to rely on the transmit register TXREG being empty to clear the TXIF flag in hardware.
In the CDU’s code, the Transmit interrupt was serviced first and then the Receive interrupt. Well, apparently, the Transmit interrupt flag TXIF was not being cleared preventing the receive interrupt from being serviced and causing total chaos in the complete loop. By servicing the receive interrupt first solved the problem. This hadn’t occurred in the “boat’s” PIC code because I had written the receive interrupt code first.
The photos show the USART test rig, the transmitted 7 bytes (notation incorrectly states 8 ) with the Raise Steam Temp. Trip bit being sent and the 7 raise/lower bytes transmitted and 63 data bytes received.
I hope this will save you many days (weeks?) of frustration.
Now to order the XBEEs……….
A Merry Christmas to All…
Ian