
Originally Posted by
Alberto
So if somebody has a code snippet that shows how to set DT interrupt for the second uart and is willing to post it, I will appreciate it very much!
Alberto
Code:
DEFINE OSC 32
DEFINE HSER1_RCSTA 90h ;OBD
DEFINE HSER1_TXSTA 24h
DEFINE HSER1_BAUD 57600
DEFINE HSER1_CLROERR 1
DEFINE HSER2_RCSTA 90h ;Master
DEFINE HSER2_TXSTA 24h
DEFINE HSER2_BAUD 57600
DEFINE HSER2_CLROERR 1
INCLUDE "DT_INTS-18.pbp"
INCLUDE "ReEnterPBP-18.bas"
;Interrupt Processor:
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT1_INT, _OK, PBP, yes ;USART2 (Main) CS
INT_Handler RX1_INT, _Grab_ELM, PBP, yes ;USART1 (ELM) Transmission Received
INT_Handler RX2_INT, _Grab_Main, PBP, yes ;USART2 (MAIN) Transmission Received
endm
INT_CREATE ;Creates the interrupt processor
ENDASM
; -=- *** USART SFRs *** -----------------------------------------------------------------------------------------------
TXSTA1 = %00100100 ;24h, Yields 57,600 Baud, ELM327
RCSTA1 = %10010000 ;90h
BAUDCON1 = %01000000
SPBRG1 = 34 ;57,600 Baud @ 48MHz, 0.16%
PIE3.5 = 1 ;RC1IE
PIE3.4 = 0 ;TX1IE
TXSTA2 = %00100100 ;24h, Master Controller
RCSTA2 = %10010000 ;90h
SPBRG2 = 34 ;57,600 Baud @ 48MHz, 0.16%
BAUDCON2 = %01000000
PIE3.7 = 1 ;RC2IE
PIE3.6 = 0 ;TX2IE
; -=- *** Interrupt Related SFRs *** -----------------------------------------------------------------------------------
INTCON = %01000000 ;.7 = GIE, .1 = INT1 Falling Edge
PIE0.1 = 1 ;INT1IE
Start:
INTCON.7 = 1 ;Enable Global Interrupts
@ INT_ENABLE RX1_INT
@ INT_ENABLE RX2_INT
MainLoop:
DO
PAUSE 10
LOOP
; -=-=-=- RX1 Interrupt Handler -=-=-=-
Grab_ELM:
Ebyt0 = REREG1
ElmCt = ElmCt + 1
@ INT_RETURN
; -=-=-=- RX2 Interrupt Handler -=-=-=-
Grab_Main:
IF Mbit = 0 THEN
Byt0 = RCREG2
GOTO Grab_Main2
ELSEIF Mbit = 1 THEN
Byt1 = RCREG2
ENDIF
@ INT_RETURN
I have a project I originally designed around the PIC18F26K22 that does some work, communicates with an ELM327 OBD-II Interpreter, and reports back to a Master PIC18F25K50 connected to USB. It uses both UART Functions along with SPI for a digital pot. I recently changed over to the PIC18F27K40. Here is the code you requested.
Bookmarks