Welcome to the forum.
Here's a few suggestions you may find useful for synchronizing serial communications, and shrinking your code size in the process.
1. Try using the STR modifier with HSEROUT/HSERIN to send/receive strings of data rather than using multiple HSEROUT/HSERIN lines to send/receive.
2. Use some type of synchronization character to lock onto the first byte or "synch up" with the 1st character.
Note: This is just a simple example. Change whatever you need to like the TimeOut value, label, array size, baud rate, etc,,.Use a terminal program to send A369621 to your PIC. If all's well, you'll see;Code:DEFINE OSC 20 DEFINE HSER_BAUD 9600 ' Use 9600 baud DEFINE HSER_CLROERR 1 ' Auto clear over-run errors RCSTA = $90 ' SPEN & CREN = 1 TXSTA = $24 ' TXEN & BRGH = 1 TimeDate VAR BYTE[6] Main HSERIN 5000,TimeOut,[WAIT("A"),STR TimeDate\6] HSEROUT ["Rcvd string: ", STR TimeDate\6,13,10] GOTO Main TimeOut: HSEROUT ["Nada",13,10] GOTO Main
Rcvd string: 369621
If all's not well, you'll see;
Nada
This will save you a TON of code space, and it's much easier to manage.




Bookmarks