Inter-IC Bus
68HC(9)12DG128 Rev 1.0
268
Inter-IC Bus
MOTOROLA
Post-Transfer
Software
Response
Transmission or reception of a byte will set the data transferring bit
(TCF) to 1, which indicates one byte communication is finished. The IIC
Bus interrupt bit (IBIF) is set also; an interrupt will be generated if the
interrupt function is enabled during initialization by setting the IBIE bit.
Software must clear the IBIF bit in the interrupt routine first. The TCF bit
will be cleared by reading from the IIC Bus Data I/O Register (IBDR) in
receive mode or writing to IBDR in transmit mode.
Software may service the IIC I/O in the main program by monitoring the
IBIF bit if the interrupt function is disabled. Note that polling should
monitor the IBIF bit rather than the TCF bit since their operation is
different when arbitration is lost.
Note that when an interrupt occurs at the end of the address cycle the
master will always be in transmit mode, i.e. the address is transmitted. If
master receive mode is required, indicated by R/W bit in IBDR, then the
Tx/Rx bit should be toggled at this stage.
During slave mode address cycles (IAAS=1) the SRW bit in the status
register is read to determine the direction of the subsequent transfer and
the Tx/Rx bit is programmed accordingly. For slave mode data cycles
(IAAS=0) the SRW bit is not valid, the Tx/Rx bit in the control 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 routine (see
Figure 41
).
CHFLAG
TXSTART
BRSET
BSET
IBSR,#$20,*
IBCR,#$30
;WAIT FOR IBB FLAG TO CLEAR
;SET TRANSMIT AND MASTER MODE
;i.e. GENERATE START CONDITION
;TRANSMIT THE CALLING
;ADDRESS, D0=R/W
;WAIT FOR IBB FLAG TO SET
MOVB
CALLING,IBDR
IBFREE
BRCLR
IBSR,#$20,*
ISR
BCLR
BRCLR
BRCLR
BRSET
MOVB
IBSR,#$02
IBCR,#$20,SLAVE
IBCR,#$10,RECEIVE
IBSR,#$01,END
DATABUF,IBDR
;CLEAR THE IBIF FLAG
;BRANCH IF IN SLAVE MODE
;BRANCH IF IN RECEIVE MODE
;IF NO ACK, END OF TRANSMISSION
;TRANSMIT NEXT BYTE OF DATA
TRANSMIT
18-iicbus