Using the Inter-Integrated Circuit (IIC) for the QE Microcontrollers
QE128 Quick Reference User Guide, Rev. 1.0
6-6
Freescale Semiconductor
count = 0;
bytes_to_trans = a; // Number of bytes to transfer
num_to_rec = b; // Number of bytes to store
IIC2C1_TX = 1; // Set TX bit for Address cycle
IIC2C1_MST = 1; // Set Master Bit to generate a Start
IIC2D = 0xAA; // Send Address data LSB is R or W for Slave
}
This function is used to read data received from the slave device and stored in the IIC_Rec_Data array. In
this example only the first byte is used.
void Master_Read_and_Store(void) {
if (rec_count == num_to_rec) {
last_byte_to_rec = 2;
}
IIC_Rec_Data[rec_count] = IIC2D;
re+;
}
This function is used to initialize the receive and store process in the MCU. Some variables are initialized
and the MST bit is set to generate a start.
void Master_Receive() {
rec_count = 0;
last_byte_to_rec = 0;
last_byte = 0;
count = 0;
num_to_rec = 0;
IIC2C1_TXAK =0;
IIC2C1_TX = 1; // Set TX bit for Address cycle
IIC2C1_MST = 1; // Set Master Bit to generate a Start
add_cycle = 1; // This variable sets up a master rec in the ISR
IIC2D = 0xAB; // Send Address data LSB is R or W for Slave
}
6.2.2
IIC Slave Project
This project is similar to the IIC_Master project. This example shows how to configure the MCU as slave.
The ISR is the same and the used functions are the same. For detailed information about the codes visit the
web page www.freescale.com.
This function is used when the device is working as slave and is necessary to know if the device does a
dummy read or writes data to the master.
void SRW(void) {
if (IIC2S_SRW) { // Check for Slave Rec or transmit
IIC2C1_TX = 1; // Set Tx bit to begin a Transmit
IIC2D = IIC_TX_Data[count];
count++;
}
else {
IIC2C1_TX = 0;
IIC2D; // Dummy read
}
}