That is why you need to use the hardware serial port! If you use SERINx you have to sit and wait for the first transition of the start bit of the first char to come in. If you use HSERIN instead, you could simply test for PIR1.5 (at least that is what it is in the 18Fs). It gets set AFTER the whole byte is received, so in just a few instructions, you can tell if the first byte came in. If that bit isn't set, move on. If it is set, then you know there is a char in the receive buffer, so then you can issue the command HSERIN [dummy]. If Dummy = $55 then you can continue to grab chars. Virtually no overhead, and as long as you give it a
little thought, you don't even need interrupts. It will NEVER lose the first character.
Although I always advocate using interrupts, if you didn't want to mess with them, you could:
Figure out the loop time of your slave device. Then you could do the following:
Main:
GotChars = 0
If PIR1.5 then
Hserin [FirstByte] ;------------ You don't need a timeout here because you already know you have a char
if FirstByte = $55 then
HSERIN 50,NotValid, [STR receivebuffer \numbytes]
GotChars = 1
endif
endif
NotValid:
....rest of program here....
goto main
;------------------------------------------------------------------------------------
And your master -
.....
HSEROUT [$55]
pause (this should equal the length of the slave's program loop + a few mSec)
HSEROUT [whatever you want to send]
.......
Bookmarks