M-Bus Interface Module
MOTOROLA
MC68307 USER’S MANUAL
7-11
2. Update MADR to define its own slave address.
3. Set MEN bit of MBCR to enable the M-bus interface system.
4. Modify the bits of MBCR to select master/slave mode, transmit/receive mode, interrupt
enable or not.
7.4.2 Generation of START
After completion of the initialization procedure, serial data can be transmitted by selecting
the 'master transmitter' mode. If the device is connected to a multi-master bus system, the
state of the M-bus busy bit (MBB) must be tested to check whether the serial bus is free.
If the bus is free (MBB=0), the start condition and the first byte (the slave address) can be
sent. The data written to the data register comprises the slave calling address and the LSB
set to indicate the direction of transfer required from the slave.
The bus free time (i.e. the time between a STOP condition and the following START condi-
tion) is built into the hardware that generates the START cycle. Depending on the relative
frequencies of the system clock and the SCL period it may be necessary to wait until the M-
bus is busy after writing the calling address to the MBDR before proceeding with the follow-
ing instructions. This is illustrated in the following example.
An example of a program which generates the START signal and transmits the first byte of
data (slave address) is shown below:
CHFLAG
BTST.B
#5,MBSR
; CHECK THE MBB BIT OF THE
BNE.S
CHFLAG
; STATUS REGISTER. IF IT IS
; SET, WAIT UNTIL IT IS CLEAR
TXSTART BSET.B
#4,MBCR
; SET TRANSMIT MODE
BSET.B
#5,MBCR
; SET MASTER MODE
; i.e. GENERATE START CONDITION
MOVE.B
CALLING,MBDR
; TRANSMIT THE CALLING
; ADDRESS, D0=R/W
MBFREE
BTST.B
#5,MBSR
; CHECK THE MBB BIT OF THE
BEQ.S
MBFREE
; STATUS REGISTER. IF IT IS
; CLEAR, WAIT UNTIL IT IS SET
7.4.3 Post-Transfer Software Response
Transmission or reception of a byte sets the data transferring bit (MCF) to 1, which indicates
one byte communication is finished. Also the M-bus interrupt bit (MIF) is set, an interrupt is
generated if the interrupt function is enable during initialization by setting the MIEN bit. Soft-
ware must clear the MIF bit in the interrupt routine first. The MCF bit is cleared by reading
from the MBDR in receive mode or writing to MBDR in transmit mode.
Software may service the M-bus I/O in the main program by monitoring the MIF bit if the
interrupt function is disabled. Note that polling should monitor the MIF bit rather than the
MCF bit since their operation is different when arbitration is lost.