![Freescale Semiconductor QE128 Quick Reference User Manual Download Page 56](http://html1.mh-extra.com/html/freescale-semiconductor/qe128/qe128_quick-reference-user-manual_2330661056.webp)
Using the Inter-Integrated Circuit (IIC) for the QE Microcontrollers
QE128 Quick Reference User Guide, Rev. 1.0
6-2
Freescale Semiconductor
6.2.1
IIC Master Project
In this application, two pins are used to work with the protocol. One is the PTH7, this is the Data pin for
IIC protocol.The other is the PTH6, the clock pin. For detailed information about the IIC protocol refer to
Inter-Integrated Circuit chapter in your reference manual.
The functions for IIC_Master.mcp project are:
•
main – Endless loop, sending a byte (counter) and waiting for IIC interrupt to occur.
•
MCU_Init – MCU initialization Watchdog disable and the IIC clock module enabled.
•
GPIO_Init – Configure PTE port as output, PTH6 and PTH7 pin as output.
•
IIC_Init – IIC module configuration.
•
IIC_ISR – IIC interrupt service routine.
•
Delay – Waste time routine.
The IIC master project configures the MCU to work as master and uses the IIC protocol to send a byte
counter to the slave. The counter count displays in eight LEDs.
This part of the code is the MCU initialization. These instructions disable the watchdog, enable the Reset
option and background pin. The System Option Register 1 (SOPT1) is used to configure the MCU. The
SCGC1 and SCGC2 are registers used to save power consumption, here the bus clock to peripherals can
be enabled or disabled. In this example only the bus clock to the IIC module is active. The clocks to other
peripherals are disable.
void MCU_Init(void) {
SOPT1 = 0x23; // Watchdog disable. Stop Mode Enable. Background Pin enable.
// RESET pin enable
SCGC1 = 0x08; // Bus Clock to the IIC module is enabled
}
This is the General Purpose Input/Output configuration. These code lines configure the directions for the
PTE and PTH ports. Eight LEDs are connected to the PTE port; therefore the PTE port is configured as
output. The PTH6 and PTH7 are configured as output. These two pins are the Serial clock (SCL) and serial
data (SDA).
void GPIO_Init(void) {
PTHPE = 0xC0; // Enable Pull ups on PTH7 and PTH6 pins
PTEDD = 0xFF; // Configure PTE as outputs
PTED = 0x00; // Put 0's in PTE port
}
This is the initialization code for the Inter-Integrated Circuit using the QE MCU. Here, the module is
configured to work as master. For example, the MCU runs with a bus speed of 4 MHz the IIC baud rate
can be calculated as following:
IIC baud rate = bus speed (Hz) / (mul * SCL divider)
Eqn. 6-1
IIC baud rate = 4000000 / (1 * 32)
IIC baud rate = 125000