I
2
C Programming Examples
MOTOROLA
I
2
C Module
29-15
29.7.1 Initialization Sequence
The registers must be initialized before the interface can transfer serial data. The procedure to initialize the
registers is as follows:
1. Set the Clock Rate Divider (IC field) in the I
2
C Frequency Divider Register (IFDR) for the
appropriate SCL frequency.
2. Write the device slave address in the I
2
C Address Register (IADR).
3. Enable the I
2
C module by setting the I
2
C Enable bit (IEN) in the I
2
C Control Register
(I2CR).
4. Modify the bits in the I
2
C Control Register (I2CR) to select master/slave mode,
transmit/receive mode, and interrupt enable/disable.
NOTE:
Before enabling the I
2
C module, ensure that another communication is not
in progress by verifying that the I
2
C Bus Busy bit (IBB) of the I
2
C Status
Register (I2SR) is cleared. When it is not cleared, execute the following
code sequence to force the slave device into an idle condition by issuing a
STOP command before enabling the I
2
C module.
29.7.2 Generation of START
After the initialization procedure is complete and the serial bus is free, the MC9328MX1 transmits serial
data by selecting the master transmitter mode. The IBB bit in the I2SR Register indicates the bus
condition. When the bus is free (IBB bit in the I2SR Register = 0), the START signal and the slave address
can be sent. The address of the appropriate slave is written to the I
2
C Data I/O Register (I2DR), where the
least significant bit (LSB) indicates the transfer direction.
The bus free time between a STOP signal and the next START signal is built into the hardware that
generates the START. Depending on the relative frequencies of the system clock and the SCL period, it is
sometimes necessary to wait after writing the calling address to the I2DR before proceeding with the
following instructions.
29.7.3 Post-Transfer Software Response
When one byte is sent or received, the Data Transfer (ICF) and the I
2
C Interrupt (IIF) bits in the I
2
C Status
Register (I2SR) are set. An interrupt occurs when interrupts are enabled by the IIEN bit of the I
2
C Control
Register (I2CR).
First, the software must clear IIF in the interrupt routine. ICF is cleared either by reading the data from the
I
2
C Data I/O Register (I2DR) in receive mode or by writing to the I2DR in transmit mode. Clearing ICF
triggers the start of the next communication byte.
The software can service the I
2
C I/O in the main program by disabling the interrupts (clear IIEN) and
polling the IIF bit.
When an interrupt occurs at the end of the address cycle, the master is still in transmit mode. When master
receive mode is required, toggle the MTX bit in the I2CR Register.
Summary of Contents for DragonBall MC9328MX1
Page 68: ...1 12 MC9328MX1 Reference Manual MOTOROLA Introduction ...
Page 86: ...2 18 MC9328MX1 Reference Manual MOTOROLA Signal Descriptions and Pin Assignments ...
Page 116: ...3 30 MC9328MX1 Reference Manual MOTOROLA Memory Map ...
Page 126: ...4 10 MC9328MX1 Reference Manual MOTOROLA ARM920T Processor ...
Page 160: ...8 8 MC9328MX1 Reference Manual MOTOROLA System Control ...
Page 272: ...13 32 MC9328MX1 Reference Manual MOTOROLA DMA Controller ...
Page 281: ...Programming Model MOTOROLA Watchdog Timer Module 14 9 ...
Page 282: ...14 10 MC9328MX1 Reference Manual MOTOROLA Watchdog Timer Module ...
Page 300: ...15 18 MC9328MX1 Reference Manual MOTOROLA Analog Signal Processor ASP ...
Page 438: ...18 16 MC9328MX1 Reference Manual MOTOROLA Serial Peripheral Interface Modules SPI 1 and SPI 2 ...
Page 478: ...19 40 MC9328MX1 Reference Manual MOTOROLA LCD Controller ...
Page 574: ...21 32 MC9328MX1 Reference Manual MOTOROLA Memory Stick Host Controller MSHC Module ...
Page 598: ...23 16 MC9328MX1 Reference Manual MOTOROLA Real Time Clock RTC ...
Page 670: ...24 72 MC9328MX1 Reference Manual MOTOROLA SDRAM Memory Controller ...
Page 726: ...25 56 MC9328MX1 Reference Manual MOTOROLA SmartCard Interface Module SIM ...
Page 736: ...26 10 MC9328MX1 Reference Manual MOTOROLA General Purpose Timers ...
Page 854: ...29 18 MC9328MX1 Reference Manual MOTOROLA I2C Module ...
Page 900: ...30 46 MC9328MX1 Reference Manual MOTOROLA Synchronous Serial Interface SSI ...
Page 942: ...32 26 MC9328MX1 Reference Manual MOTOROLA GPIO Module and I O Multiplexer IOMUX ...