PDA

View Full Version : Grabbing word from UART buffer



Macgman2000
- 11th August 2008, 16:08
Hello,

I wrote a snippet a while back (3yrs) and have recently picked it back up for reuse. I have a UART packing a variable and incrementing a counter before jumping out of an ASM interrupt routine. I want to pick up 2 bytes (1 word ) from the UART receive buffer. At this time I have the code working on grabbing 1 byte. How do i grab 2 bytes from the UART with one interrupt? Is there a special ASM designation to command a double byte transfer from the RCREG buffer into a variable? My application is to receive a manchester encoded word and decode it to a byte.

Nick

Darrel Taylor
- 11th August 2008, 23:06
How do i grab 2 bytes from the UART with one interrupt? Is there a special ASM designation to command a double byte transfer from the RCREG buffer into a variable?

Typically, it's not a good idea to get both with the same interrupt.

As soon as the first byte is received, you'll get an interrupt. It jumps to the handler, get's the first byte, than has to sit around twiddling it's thumbs while it waits for the second byte to come in very slowly over RS232. If there are other interrupts involved, they will be blocked until the second byte is in.

Instead, you should only grab 1 byte at a time. Have the handler keep track of whether it's the first or second byte, and after it's received both bytes, set a flag or run the required routine in the handler.

But to answer the original question...
When you get to the Handler, grab the first byte, then wait for RCIF to become 1 again. Now you can grab the second byte and have the whole word.