
Inter-Integrated Circuit Bus Controller Module (I
2
C)
PXN20 Microcontroller Reference Manual, Rev. 1
32-16
Freescale Semiconductor
32.5
Initialization/Application Information
32.5.1
I
2
C Programming Examples
32.5.1.1
Initialization Sequence
Reset puts the I
2
C bus control register in its default state. Before the interface can be used to transfer serial
data, an initialization procedure must be carried out, as follows:
1. Update the frequency divider register (IBFD) and select the required division ratio to obtain SCL
frequency from system clock.
2. Update the I
2
C bus address register (IBAD) to define its slave address.
3. Clear the MDIS bit of the I
2
C bus control register (IBCR) to enable the I
2
C interface system.
4. Modify the bits of the IBCR to select master/slave mode, transmit/receive mode and interrupt
enable or not. Optionally modify the bits of the I
2
C bus interrupt configuration register (IBIC) to
further refine the interrupt behavior.
5. Configure the SDA and SCL pads. (The SIU Pad Configuration registers must be configured to
select the appropriate I
2
C function. Also, the open drain feature of the pad must be enabled by
setting the ODE bit in the appropriate SIU pad configuration register.)
32.5.1.2
Generation of START
After completion of the initialization procedure, serial data can be transmitted by selecting the master
transmitter mode. If the device is connected to a multi-master bus system, the state of the I
2
C bus busy bit
(IBB) must be tested to check if the serial bus is free.
If the bus is free (IBB = 0), the start condition and the first byte (the slave address) can be sent. The data
written to the data register comprises the slave calling address and the LSB, which is set to indicate the
direction of transfer required from the slave.
The bus free time (i.e., the time between a STOP condition and the following START condition) is built
into the hardware that generates the START cycle. Depending on the relative frequencies of the system
clock and the SCL period, it may be necessary to wait until the I
2
C is busy after writing the calling address
to the IBDR before proceeding with the following instructions. This is illustrated in the following example.
An example of the sequence of events which generates the START signal and transmits the first byte of
data (slave address) is shown below:
while (bit 2, IBSR ==1)
// wait in loop for IBB flag to clear
bit3 and bit 2, IBCR = 1
// set transmit and master mode, i.e. generate start condition
IBDR = calling_address
// send the calling address to the data register
while (bit 2, IBSR ==0)
// wait in loop for IBB flag to be set
32.5.1.3
Post-Transfer Software Response
Transmission or reception of a byte sets the data transferring bit (TCF) to 1, which indicates one byte
communication is finished. The I
2
C Bus interrupt bit (IBIF) is set also; an interrupt is generated if the
Содержание PXN2020
Страница 1: ...PXN20 Microcontroller Reference Manual Devices Supported PXN2020 PXN2120 PXN20RM Rev 1 06 2011...
Страница 42: ...PXN20 Microcontroller Reference Manual Rev 1 lxiv Freescale Semiconductor...
Страница 64: ...Introduction PXN20 Microcontroller Reference Manual Rev 1 1 22 Freescale Semiconductor...
Страница 112: ...Signal Description PXN20 Microcontroller Reference Manual Rev 1 3 44 Freescale Semiconductor...
Страница 118: ...Resets PXN20 Microcontroller Reference Manual Rev 1 4 6 Freescale Semiconductor...
Страница 162: ...Clocks Reset and Power CRP PXN20 Microcontroller Reference Manual Rev 1 6 30 Freescale Semiconductor...
Страница 182: ...Frequency Modulated Phase Locked Loop FMPLL PXN20 Microcontroller Reference Manual Rev 1 7 20 Freescale Semiconductor...
Страница 268: ...Boot Assist Module BAM PXN20 Microcontroller Reference Manual Rev 1 9 14 Freescale Semiconductor...
Страница 318: ...Interrupts and Interrupt Controller INTC PXN20 Microcontroller Reference Manual Rev 1 10 50 Freescale Semiconductor...
Страница 326: ...General Purpose Static RAM SRAM PXN20 Microcontroller Reference Manual Rev 1 11 8 Freescale Semiconductor...
Страница 372: ...e200z6 Core Z6 PXN20 Microcontroller Reference Manual Rev 1 13 8 Freescale Semiconductor...
Страница 412: ...e200z0 Core Z0 PXN20 Microcontroller Reference Manual Rev 1 14 14 Freescale Semiconductor...
Страница 460: ...Memory Protection Unit MPU PXN20 Microcontroller Reference Manual Rev 1 18 20 Freescale Semiconductor...
Страница 478: ...Error Correction Status Module ECSM PXN20 Microcontroller Reference Manual Rev 1 19 18 Freescale Semiconductor...
Страница 488: ...Software Watchdog Timer SWT PXN20 Microcontroller Reference Manual Rev 1 20 10 Freescale Semiconductor...
Страница 494: ...System Timer Module STM PXN20 Microcontroller Reference Manual Rev 1 21 6 Freescale Semiconductor...
Страница 821: ...Media Local Bus MLB PXN20 Microcontroller Reference Manual Rev 1 Freescale Semiconductor 27 49...
Страница 822: ...Media Local Bus MLB PXN20 Microcontroller Reference Manual Rev 1 27 50 Freescale Semiconductor...
Страница 926: ...Controller Area Network FlexCAN PXN20 Microcontroller Reference Manual Rev 1 29 42 Freescale Semiconductor...
Страница 990: ...Deserial Serial Peripheral Interface DSPI PXN20 Microcontroller Reference Manual Rev 1 30 64 Freescale Semiconductor...
Страница 1044: ...Enhanced Serial Communication Interface eSCI PXN20 Microcontroller Reference Manual Rev 1 31 54 Freescale Semiconductor...
Страница 1080: ...Cross Triggering Unit CTU PXN20 Microcontroller Reference Manual Rev 1 33 12 Freescale Semiconductor...
Страница 1134: ...Analog to Digital Converter ADC PXN20 Microcontroller Reference Manual Rev 1 34 54 Freescale Semiconductor...
Страница 1150: ...IEEE 1149 1 Test Access Port Controller JTAGC PXN20 Microcontroller Reference Manual Rev 1 35 16 Freescale Semiconductor...
Страница 1257: ...Nexus Development Interface NDI PXN20 Microcontroller Reference Manual Rev 1 Freescale Semiconductor 36 107...
Страница 1258: ...Nexus Development Interface NDI PXN20 Microcontroller Reference Manual Rev 1 36 108 Freescale Semiconductor...
Страница 1376: ...Memory Map PXN20 Microcontroller Reference Manual Rev 1 A 118 Freescale Semiconductor...