PDA

View Full Version : PIR1.5 interrupt



PlantBob
- 2nd July 2008, 03:22
MeLabs support sent me this code today. It only works once. When I check the state of PIR1.5 before the HSERIN command it is a 1. When I check it after the HSERIN command it is a 0. It seems to reset itself. The problem is that it only interrupts 1 time. I never see the interrupt after the first time it fires. What am I missing? Also, how do I format the HSERIN command to keep reading characters until it sees a CR/LF?

Thanks,
Bob Hiller
Lifts for the Disabled LLC


main:
IF PIR1.5 = 1 THEN GOSUB receive_data 'check the flag


GOTO main


receive_data:
HSERIN [x, y, z] 'get data, flag is cleared automagically
RETURN 'back to business

skimask
- 2nd July 2008, 13:39
Have to reset the interrupt flag. Usually in the PIC's datasheet, there's a little blurb behind the explanation for the interrupt bit that says something like " (Must be cleared by software) "


main:
IF PIR1.5 = 1 THEN
PIR1.5 = 0
GOSUB receive_data 'check the flag
GOTO main
receive_data:
HSERIN [x, y, z] 'get data, flag is cleared automagically
RETURN 'back to business

Bruce
- 2nd July 2008, 15:36
PIR1.5 or RCIF is a read-only bit that gets cleared once the USART RCREG buffer is
empty. The only way to clear RCIF is to empty the buffer by reading it.

My guess would be that you're sending more data than you're receiving in the HSERIN
routine, and this is causing the USART to lock-up. OERR (the over-run bit in RCSTA) gets
set, and this causes the USART to stop responding.

If you include the DEFINE HSER_CLROERR 1 option in the init section of your code, PBP will
automatically clear this condition for you. If not you'll need to do it manually by clearing,
then setting, CREN (bit 4 in RCSTA) register.

RCIF never gets set again once OERR is set because this condition inhibits transfer of data
from the RSR to RCREG register.

skimask
- 2nd July 2008, 15:59
PIR1.5 or RCIF is a read-only bit that gets cleared once the USART RCREG buffer is empty. The only way to clear RCIF is to empty the buffer by reading it.
Absolutely...That's twice today I've caused a 'derrrrr'. My game is off......