I 2 C ModulesMCF5253 Reference Manual, Rev. 118-14 Freescale Semiconductor18.6.3 Post-Transfer Software ResponseTransmission or reception of a byte will set the data transferring bit (ICF) to 1, which indicates one bytecommunication is finished. The interrupt bit (IIF) is also set. An interrupt will be generated if the interruptfunction is enabled during initialization by setting the IIEN bit. Software must clear the IIF bit in theinterrupt routine first. The ICF bit will be cleared by reading from the I 2C Data I/O Register (MBDR) inreceive mode or writing to MBDR in transmit mode.Software can service the I2C I/O in the main program by monitoring the IIF bit if the interrupt function isdisabled. Polling should monitor the IIF bit rather than the ICF bit because that operation is different whenarbitration is lost.When an interrupt occurs at the end of the address cycle, the master will always be in transmit mode. Forexample, the address is transmitted. If master receive mode is required, indicated by MBDR[R/W], thenthe MTX bit should be toggled.During slave-mode address cycles (IAAS=1), the SRW bit in the status register is read to determine thedirection of the subsequent transfer and the MTX bit is programmed accordingly. For slave-mode datacycles (IAAS=0), the SRW bit is not valid. The MTX bit in the control register should be read to determinethe direction of the current transfer.The following is an example of a software response by a “master transmitter’' in the interrupt routine (seeFigure 18-9).MBSR LEA.L MBSR,-(A7) ;Load effective addressBCLR.B #1,(A7)+ ;Clear the IIF flagMOVE.B MBCR,-(A7) ;Push the address on stack,BTST.B #5,(A7)+ ;check the MSTA flagBEQ.S SLAVE ;Branch if slave modeMOVE.B MBCR,-(A7) ;Push the address on stackBTST.B #4,(A7)+ ;check the mode flagBEQ.S RECEIVE ;Branch if in receive modeMOVE.B MBSR,-(A7) ;Push the address on stack,BTST.B #0,(A7)+ ;check ACK from receiverBNE.BEND ;If no ACK, end of transmissionTRANSMIT MOVE.B DATABUF,-(A7) ;Stack data byteMOVE.B (A7)+, MBDR) ;Transmit next byte of data18.6.4 Generation of STOPA data transfer ends with a STOP signal generated by the “master’' device. A master transmitter cangenerate a STOP signal after all the data has been transmitted. The following code is an example showinghow a master transmitter generates a stop condition.MASTX MOVE.B MBSR, -(A7) ; If no ACK, branch to endBTST.B #0,(A7)+BNE.B ENDMOVE.B TXCNT,D0 ;Get value from the transmitting counterBEQ.S END ;If no more data, branch to endMOVE.B DATABUF,-(A7) ;Transmit next byte of dataMOVE.B (A7)+,MBDRMOVE.B TXCNT,D0 ;Decrease the TXCNTSUBQ.L #1,D0