Hardware Reference
In-Depth Information
movb
#$F7,CAN1IDMR5
; check IDE bit only (0 for standard identifier)
clr
CAN1IDMR6
; acceptance mask for P
movb #$F7,CAN1IDMR7
; check IDE bit only (must be 0)
bclr CAN1CTL0,INITRQ
; exit initialization mode
bclr CAN1CTL0,SLPRQ
; exit sleep mode
13.13 Data Transmission and Reception in MSCAN
When the application has only a small amount of data to be transmitted every now and
then, it would be easy to find empty transmit buffers to send the message. There is no need
to use interrupt in this case. However, if the application has many messages to be sent out at
one time, then it may not be able to find an empty transmit buffer to hold the message to be
transmitted at some point. In this situation, the designer should consider using the interrupt-
driven approach to control the transmission of messages to allow the CPU to perform other
operations.
For a received message, the application would take action on the basis of the identifier of
the message. If the message arrival time is unpredictable, then it is more convenient to use
the interrupt-driven approach. If the arrival times of messages are more predictable, then the
designer can consider using either the polling or the interrupt-driven approach.
13.13.1 MSCAN Data Transmission Programming
To prepare data for transmission, there are two options.
1. Identify an empty transmit buffer and place data directly on the available transmit
buffer.
2. Store data in a buffer and copy the buffer to the first available transmit buffer that is
identified.
The first method can be used in the polling method. The second method involves more
overhead. However, it is suitable for both the polling and interrupt-driven approaches.
Example 13.5
Write a function to send out the message stored at a buffer pointed to by index register X
from the CAN1 module. The function should find an available buffer to hold the message to be
sent out.
Solution:
tbuf
equ
0
; tbuf offset from top of stack
snd2can1
pshy
pshb
leas
2 1,sp
; allocate 1 byte for local variable
sloop1
brset
CAN1TFLG,$01,tb0
; is transmit buffer 0 empty?
brset
CAN1TFLG,$02,tb1
; is transmit buffer 1 empty?
brset
CAN1TFLG,$04,tb2
; is transmit buffer 2 empty?
bra
sloop1
; if necessary wait until one buffer is empty
 
Search WWH ::




Custom Search