Hi JosueCas,
Thanks! Nice to know it's working!
I'm still trying to write up a good explanation of how it all works. That's why the thread is still closed. Hopefully I can answer most of the questions there.
But in your case, the RX interrupt works a little different. It's Flag bit gets reset by hardware whenever you read from the RCREG register, and can't be reset by software.
So inside a RX interrupt routine you MUST read from RCREG, or you'll end up in an Continuous Interrupt Loop.
Also, the HSER defines only work if you are using PBP's HSERIN/OUT, so the USART must be set up manually. OR, you can use this macro...
Code:
'--[ Initialize USART for specified baud rate at current OSC speed ]------------
ASM
USART_Init macro Baud
CHK?RP TXSTA
clrf TXSTA
_SPBRG = (OSC * 1000000) / 16 / Baud - 1 ; calc SPBRG @ High baud rate
if _SPBRG > 255 ; if SPBRG is too high
_SPBRG = (OSC * 1000000) / 64 / Baud - 1 ; calc for Low baud rate
bcf TXSTA, BRGH ; Set BRGH to Low Speed
if _SPBRG > 255
_SPBRG = 255
endif
else
bsf TXSTA, BRGH ; Set BRGH to High Speed
endif
bsf TXSTA, TXEN ; Set Transmit Enable bit
movlw _SPBRG
CHK?RP SPBRG
movwf SPBRG ; load the calulated SPBRG
movlw B'10010000' ; enable USART
CHK?RP RCSTA
movwf RCSTA
endm
ENDASM
Then to initialize the USART, just do this...With this macro you can also change the baud rate at any time. Unlike the Define's.
<br>
Bookmarks