MOTOROLA
Chapter 24. I
2
C Interface
24-13
I
2
C Programming Examples
For a master receiver to terminate a data transfer, it must inform the slave transmitter by not
acknowledging the last data byte. This is done by setting I2CR[TXAK] before reading the
next-to-last byte. Before the last byte is read, a STOP signal must be generated, as in the
following example.
MASR
MOVE.B RXCNT,D0
;Decrease RXCNT
SUBQ.L #1,D0
MOVE.B D0,RXCNT
BEQ.S ENMASR
;Last byte to be read
MOVE.B RXCNT,D1
;Check second-to-last byte to be read
EXTB.L D1
SUBI.L #1,D1;
BNE.S NXMAR
;Not last one or second last
LAMAR BSET.B #3,I2CR
;Disable ACK
BRA NXMAR
ENMASR
BCLR.B #5,I2CR
;Last one, generate STOP signal
NXMAR
MOVE.B I2DR,RXBUF
;Read data and store RTE
24.6.5 Generation of Repeated START
After the data transfer, if the master still wants the bus, it can signal another START
followed by another slave address without signalling a STOP, as in the following example.
RESTART MOVE.B I2CR,-(A7)
;Repeat START (RESTART)
BSET.B #2, (A7)
MOVE.B (A7)+, I2CR
MOVE.B CALLING,-(A7)
;Transmit the calling address, D0=R/W-
MOVE.B CALLING,-(A7)
MOVE.B (A7)+, I2DR
24.6.6 Slave Mode
In the slave interrupt service routine, software should poll the I2SR[IAAS] bit to determine
if the controller has received its slave address. If IAAS is set, software should set the
transmit/receive mode select bit (I2CR[MTX]) according to the I2SR[SRW]. Writing to the
I2CR clears the IAAS automatically. The only time IAAS is read as set is from the interrupt
at the end of the address cycle where an address match occurred; interrupts resulting from
subsequent data transfers will have IAAS cleared. A data transfer can now be initiated by
writing information to I2DR for slave transmits, or read from I2DR in slave-receive mode.
A dummy read of I2DR in slave/receive mode releases SCL, allowing the master to send
data.
In the slave transmitter routine, I2SR[RXAK] must be tested before sending the next byte
of data. Setting RXAK means an end-of-data signal from the master receiver, after which
software must switch it from transmitter to receiver mode. Reading I2DR then releases SCL
so that the master can generate a STOP signal.
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 ...