
MOTOROLA
7-12
MC68HC05BD3
M-BUS SERIAL INTERFACE
7
MIF bit in the interrupt routine first. The MCF bit can be cleared by reading the M-Bus Data I/O
Register (MDR) in receive mode or writing to the MDR in transmit mode. Software may serve the
M-Bus I/O in the main program by monitoring the MIF bit if the interrupt is disabled. The following
is an example of a software response by a master in transmit mode in the interrupt routine (see
Figure 7-4).
ISR
BCLR
BRCLR
1,MSR
5,MCR,SLAVE
; CLEAR THE MIF FLAG
; CHECK THE MSTA FLAG,
; BRANCH IF SLAVE MODE
BRCLR
4,MCR,RECEIVE ; CHECK THE MODE FLAG,
; BRANCH IF IN RECEIVE MODE
0,MSR,END
; CHECK ACK FROM RECEIVER
; IF NO ACK, END OF
; TRANSMISSION
DATABUF
; GET THE NEXT BYTE OF DATA
MDR
; TRANSMIT THE DATA
BRSET
TRANSMIT
LDA
STA
7.4.4
Generation of the STOP Signal
A data transfer ends with a STOP signal generated by the master device. A master in transmit
mode can simply generate a STOP signal after all the data have been transmitted. The following
is an example showing how a STOP condition is generated by a master in transmit mode.
MASTX
BRSET
LDA
0,MSR,END
TXCNT
; IF NO ACK, BRANCH TO END
; GET VALUE FROM THE
; TRANSMITTING COUNTER
; IF NO MORE DATA, BRANCH TO
; END
; GET NEXT BYTE OF DATA
; TRANSMIT THE DATA
; DECREASE THE TXCNT
; EXIT
; GENERATE A STOP CONDITION
; RETURN FROM INTERRUPT
BEQ
END
LDA
STA
DEC
BRA
BCLR
DATABUF
MDR
TXCNT
EMASTX
5,MCR
END
EMASTX RTI
If a master receiver wants to terminate a data transfer, it must inform the slave transmitter by not
acknowledging the last byte of data. This can be achieved by setting the transmit acknowledge bit
(TXAK) before reading the 2nd last byte of data. Before reading the last byte of data, a STOP
signal must be generated first. The following is an example showing how a STOP signal is
generated by a master in receive mode.
MASR
DEC
BEQ
LDA
DECA
BNE
RXCNT
ENMASR
RXCNT
; LAST BYTE TO BE READ
; CHECK LAST 2ND BYTE TO BE READ
; NOT LAST ONE OR LAST SECOND
NXMAR
TPG