Chapter 15 Inter-Integrated Circuit (IICV3) Block Description
MC9S12XE-Family Reference Manual , Rev. 1.19
598
Freescale Semiconductor
15.7.1.3
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 because 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.
15.7.1.4
Generation of STOP
A data transfer ends with a STOP signal generated by the 'master' device. A master transmitter can simply
generate a STOP signal after all the data has been transmitted. The following is an example showing how
a stop condition is generated by a master transmitter.
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)
MOVB
CALLING,IBDR
;TRANSMIT THE CALLING ADDRESS, D0=R/W
ISR
BCLR
IBSR,#$02
;CLEAR THE IBIF FLAG
BRCLR
IBCR,#$20,SLAVE
;BRANCH IF IN SLAVE MODE
BRCLR
IBCR,#$10,RECEIVE
;BRANCH IF IN RECEIVE MODE
BRSET
IBSR,#$01,END
;IF NO ACK, END OF TRANSMISSION
TRANSMIT
MOVB
DATABUF,IBDR
;TRANSMIT NEXT BYTE OF DATA
MASTX
TST
TXCNT
;GET VALUE FROM THE TRANSMITING COUNTER
BEQ
END
;END IF NO MORE DATA
BRSET
IBSR,#$01,END
;END IF NO ACK
MOVB
DATABUF,IBDR
;TRANSMIT NEXT BYTE OF DATA
DEC
TXCNT
;DECREASE THE TXCNT
BRA
EMASTX
;EXIT
END
BCLR
IBCR,#$20
;GENERATE A STOP CONDITION
EMASTX
RTI
;RETURN FROM INTERRUPT
IBFREE
BRCLR
IBSR,#$20,*
;WAIT FOR IBB FLAG TO SET
Because
of
an
order
from
the
United
States
International
Trade
Commission,
BGA-packaged
product
lines
and
part
numbers
indicated
here
currently
are
not
available
from
Freescale
for
import
or
sale
in
the
United
States
prior
to
September
2010:
S12XE
products
in
208
MAPBGA
packages