Hardware Reference
In-Depth Information
13.13.2 MSCAN Data Reception Programming
Incoming CAN bus messages are sent by other nodes and their arrival times are unpredict-
able. Therefore, it would be more efficient to use the interrupt-driven approach to handle data
reception on the CAN bus. After setting up acceptance filters, one can enable the reception in-
terrupt and wait for the incoming messages to arrive while performing other operations.
Example 13.7
Assuming that the CAN1 receiver has been set up to accept messages with extended iden-
tifiers T1 and V1, filter 0 is set up to accept the identifier started with T1, whereas filter 1 is
set up to accept the identifier started with V1. Write the interrupt handling routine for the RXF
interrupt. If the acceptance is caused by filter 0, the RXF service routine would display the fol-
lowing message on a 20
×
2 LCD:
Temperature is
xxx.y°F
If the acceptance of the message is caused by filter 1, the RXF interrupt service routine
would display the following message:
Voltage is
x.y V
Solution: The service routine will check the RXF bit of the CAN1RFLG register to make sure
that the interrupt is caused by the RXF flag. If not, it returns. This routine also ignores the
remote transfer request. The assembly language version of the service routine is as follows:
; ****************************************************************************
; The following function is the service routine for the RXF interrupt. It only services hit 0 and
; hit 1. It ignores the RTR.
; ****************************************************************************
can1Rx_ISR
brset
CAN1RFLG,RXF,RxfSet
; is the RXF flag set to 1?
rti
; if not, do nothing
RxfSet
ldaa
#$80
; set cursor to row 0 column 0
jsr
cmd2LCD
ldab
CAN1IDAC
; check into IDHIT bits
andb
#$07
; mask out higher 5 bits
beq
hit0
; filter 0 hit?
cmpb
#1
; filter 1 hit?
beq
hit1
rti
; not hit 0 or hit 1, do thing
hit0
ldab
CAN1RDLR
; get the byte count of incoming data
beq
rxfDone
; byte count 0, return
ldx
#t1_line1
; output “Temperature is”
jsr
puts2lcd
;
ldaa
#$C4
; set cursor to row 2 column 4
jsr
cmd2LCD
;
ldx
#CAN1RDSR0
outLoop1
ldaa
1,x 1
; output 1 byte at a time
jsr
putc2lcd
;
dbne
b,outLoop1
;
rti
 
Search WWH ::




Custom Search