M-Bus Interface Module
7-12
MC68307 USER’S MANUAL
MOTOROLA
Note that when an interrupt occurs at the end of the address cycle the master is always in
transmit mode, i.e. the address is transmitted. If master receive mode is required, indicated
by R/W bit in MBDR, then the MTX bit should be toggled at this stage.
During slave mode address cycles (MAAS=1) the SRW bit in the status register is read to
determine the direction of the subsequent transfer and the MTX bit is programmed accord-
ingly. For slave mode data cycles (MAAS=0) the SRW bit is not valid, the MTX bit in the con-
trol register should be read to determine the direction of the current transfer.
The following is an example of a software response by a 'master transmitter' in the interrupt
ISR
BCLR.B
#1,MBSR
; CLEAR THE MIF FLAG
BTST.B
#5,MBCR
; CHECK THE MSTA FLAG,
BEQ.S
SLAVE
; BRANCH IF SLAVE MODE
BTST.B
#4,MBCR
; CHECK THE MODE FLAG,
BEQ.S
RECEIVE
; BRANCH IF IN RECEIVE MODE
BTST.B
#0,MBSR
; CHECK ACK FROM RECEIVER
BNE.B
END
; IF NO ACK, END OF TRANSMISSION
TRANSMIT
MOVE.B
DATABUF,MBDR
; TRANSMIT NEXT BYTE OF DATA
7.4.4 Generation of STOP
A data transfer ends with a STOP signal generated by the master device. A master trans-
mitter can simply generate a STOP signal after all the data has been transmitted. The fol-
lowing is an example showing how a stop condition is generated by a master transmitter.
MASTX
BTST.B
#0,MBSR
; IF NO ACK, BRANCH TO END
BNE.B
END
MOVE.B
TXCNT,D0
; GET VALUE FROM THE
; TRANSMITTING COUNTER
BEQ.S
END
; IF NO MORE DATA, BRANCH TO
; END
MOVE.B
DATABUF,MBDR
; TRANSMIT NEXT BYTE OF DATA
SUBI.B
#1,TXCNT
; DECREASE THE TXCNT
BRA.S
EMASTX
; EXIT
END
BCLR
#5,MBCR
; GENERATE A STOP CONDITION
EMASTX
RTE
; RETURN FROM INTERRUPT
If a master receiver wants to terminate a data transfer, it must inform the slave transmitter
by not acknowledging the last byte of data which can be done 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 receiver.
MASR
SUBI.B
#1,RXCNT
BEQ.S
ENMASR
; LAST BYTE TO BE READ
MOVE.B
RXCNT,D1
; CHECK SECOND LAST BYTE
SUBI.B
#1,D1
; TO BE READ
BNE.S
NXMAR
; NOT LAST ONE OR SECOND LAST
LAMAR
BSET.B
#3,MBCR
; SECOND LAST, DISABLE ACK
; TRANSMITTING
BRA
NXMAR