24-12
MCF5282 User’s Manual
MOTOROLA
I
2
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
2
C I/O in the main program by monitoring IIF if the interrupt
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)
;Load effective address
BCLR.B #1,(A7)+
;Clear the IIF flag
MOVE.B I2CR,-(A7)
;Push the address on stack,
BTST.B #5,(A7)+
;check the MSTA flag
BEQ.S SLAVE
;Branch if slave mode
MOVE.B I2CR,-(A7)
;Push the address on stack
BTST.B #4,(A7)+
;check the mode flag
BEQ.S RECEIVE
;Branch if in receive mode
MOVE.B I2SR,-(A7)
;Push the address on stack,
BTST.B #0,(A7)+
;check ACK from receiver
BNE.B END
;If no ACK, end of transmission
TRANSMIT MOVE.B DATABUF,-(A7)
;Stack data byte
MOVE.B (A7)+, I2DR
;Transmit next byte of data
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)
;If no ACK, branch to end
BTST.B #0,(A7)+
BNE.B END
MOVE.B TXCNT,D0
;Get value from the transmitting counter
BEQ.S END
;If no more data, branch to end
MOVE.B DATABUF,-(A7)
;Transmit next byte of data
MOVE.B (A7)+,I2DR
MOVE.B TXCNT,D0
;Decrease the TXCNT
SUBQ.L #1,D0
MOVE.B D0,TXCNT
BRA.S EMASTX;Exit
END
LEA.L I2CR,-(A7)
;Generate a STOP condition
BCLR.B #5,(A7)+
EMASTX RTE
;Return from interrupt
Summary of Contents for ColdFire MCF5281
Page 124: ...3 20 MCF5282 User s Manual MOTOROLA EMAC Instruction Set Summary ...
Page 141: ...MOTOROLA Chapter 5 Static RAM SRAM 5 5 SRAM Programming Model ...
Page 142: ...5 6 MCF5282 User s Manual MOTOROLA SRAM Programming Model ...
Page 168: ...6 26 MCF5282 User s Manual MOTOROLA Interrupts ...
Page 186: ...7 18 MCF5282 User s Manual MOTOROLA Functional Description ...
Page 228: ...9 22 MCF5282 User s Manual MOTOROLA Functional Description ...
Page 246: ...10 18 MCF5282 User s Manual MOTOROLA Low Power Wakeup Operation ...
Page 254: ...11 8 MCF5282 User s Manual MOTOROLA Memory Map and Registers ...
Page 264: ...12 10 MCF5282 User s Manual MOTOROLA Chip Select Registers ...
Page 280: ...13 16 MCF5282 User s Manual MOTOROLA Misaligned Operands ...
Page 314: ...14 34 MCF5282 User s Manual MOTOROLA MCF5282 External Signals ...
Page 339: ...MOTOROLA Chapter 15 Synchronous DRAM Controller Module 15 25 SDRAM Example ...
Page 340: ...15 26 MCF5282 User s Manual MOTOROLA SDRAM Example ...
Page 356: ...16 16 MCF5282 User s Manual MOTOROLA DMA Controller Module Functional Description ...
Page 408: ...17 52 MCF5282 User s Manual MOTOROLA Buffer Descriptors ...
Page 446: ...20 24 MCF5282 User s Manual MOTOROLA Interrupts ...
Page 474: ...22 18 MCF5282 User s Manual MOTOROLA Programming Model ...
Page 510: ...23 36 MCF5282 User s Manual MOTOROLA Operation ...
Page 526: ...24 16 MCF5282 User s Manual MOTOROLA I2C Programming Examples ...
Page 672: ...28 12 MCF5282 User s Manual MOTOROLA Functional Description ...
Page 718: ...29 46 MCF5282 User s Manual MOTOROLA Motorola Recommended BDM Pinout ...
Page 750: ...32 8 MCF5282 User s Manual MOTOROLA Ordering Information ...