Generation Of Stop - Motorola ColdFire MCF5281 User Manual

Motorola microcontroller user's manual
Table of Contents

Advertisement

2
I
C Programming Examples
the interrupt routine. I2SR[ICF] is cleared either by reading from I2DR in receive mode or
by writing to I2DR in transmit mode.
Software can service the I
function is disabled. Polling should monitor IIF rather than ICF because that operation is
different when arbitration is lost.
When an interrupt occurs at the end of the address cycle, the master is always in transmit
mode; that is, the address is sent. If master receive mode is required I2CR[MTX] should be
toggled.
During slave-mode address cycles (I2SR[IAAS] = 1), I2SR[SRW] is read to determine the
direction of the next transfer. MTX is programmed accordingly. For slave-mode data cycles
(IAAS = 0), SRW is invalid. MTX should be read to determine the current transfer
direction.
The following is an example of a software response by a master transmitter in the interrupt
routine (see Figure 24-10).
I2SR
LEA.L I2SR,-(A7)
BCLR.B #1,(A7)+
MOVE.B I2CR,-(A7)
BTST.B #5,(A7)+
BEQ.S SLAVE
MOVE.B I2CR,-(A7)
BTST.B #4,(A7)+
BEQ.S RECEIVE
MOVE.B I2SR,-(A7)
BTST.B #0,(A7)+
BNE.B END
TRANSMIT MOVE.B DATABUF,-(A7)
MOVE.B (A7)+, I2DR

24.6.4 Generation of STOP

A data transfer ends when the master signals a STOP, which can occur after all data is sent,
as in the following example.
MASTX
MOVE.B I2SR, -(A7)
BTST.B #0,(A7)+
BNE.B END
MOVE.B TXCNT,D0
BEQ.S END
MOVE.B DATABUF,-(A7)
MOVE.B (A7)+,I2DR
MOVE.B TXCNT,D0
SUBQ.L #1,D0
MOVE.B D0,TXCNT
BRA.S EMASTX;Exit
END
LEA.L I2CR,-(A7)
BCLR.B #5,(A7)+
EMASTX RTE
24-12
2
C I/O in the main program by monitoring IIF if the interrupt
;Load effective address
;Clear the IIF flag
;Push the address on stack,
;check the MSTA flag
;Branch if slave mode
;Push the address on stack
;check the mode flag
;Branch if in receive mode
;Push the address on stack,
;check ACK from receiver
;If no ACK, end of transmission
;Stack data byte
;Transmit next byte of data
;If no ACK, branch to end
;Get value from the transmitting counter
;If no more data, branch to end
;Transmit next byte of data
;Decrease the TXCNT
;Generate a STOP condition
;Return from interrupt
MCF5282 User's Manual
MOTOROLA

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfire mcf5282

Table of Contents