
Originally Posted by
The Master
What i meant is that the interrupt would copy the byte from RCREG into a temp variable. Then the code in the main loop would need a way of knowing when a byte has been received to process it (possibly a bit variable). What im saying is why not just check PIR1.5 instead of having another variable to say serial data has arrived and why not use RCREG directly in the main program loop instead of having another byte variable. It would mean the serial interrupt completes much quicker because it doesnt do anything.
Well, if you're receiving serial data in packets, the main loop should know when a full 'packet' has been placed into the 'buffer' and the main loop can clear the 'buffer' once it's done with it so the interrupt can start loading it again.
Code:
'4 byte buffer
Int: buf[3] = buf[2] : buf[2]=buf[1] : buf[1] = buf[0] : buf[0] = RCREG
RESUME
Everything in the receive 'buffer' got shifted up one, and the newest byte is in the lowest buffer position...
Now the main loop looks at all four bytes, decides it's a good packet, copies the packet and clears it so the interrupt can reload it.
Should i be removing the byte from RCREG in the interrupt? If it doesnt matter as long as i do it before the next one arrives then doing it in the main program loop looks like a better way of doing it
Problem with that is 'feature creep'... You never know what you're going to put into the main loop later on. You say you won't add that much...but who knows how many 'not that much's are going to creep in later on. If the interrupt handles it, it's handled, 'nuff said.
Bookmarks