Master Slave I2C serial data I2C serial clock I2C Half Duplex Communication SDA SCL I2C module I2C module protocol Multi-master, two wire bus , up to 100 kbits/sec One data line (SDA)
One clock line (SCL)
Master controls clock for slaves
Each connected slave has a unique 7-bit address
Features Software programmable for one of 64 different serial clock frequencies Software-selectable acknowledge bit Interrupt-driven byte-by-byte data transfer Arbitration-lost interrupt with automatic mode switching from master to slave Calling address identification interrupt Features (continued..) START and STOP signal generation and detection Repeated START signal generation and detection Acknowledge bit generation and detection Bus busy detection General call recognition Low power mode wakeup on slave address match Modes of operation Run mode: This is the basic mode of operation. To conserve power in this mode, Wait mode: The module continues to operate when the core is in wait mode and can provide a wake up interrupt Modes of operation(continued..) Stop mode
- The module is inactive in stop mode for reduced power consumption, except that address matching is enabled in stop mode. - The STOP instruction does not affect the I2C module's register states. Configuring the Baud Rate The baud rate of the i2c communication can be configured using the above equation Bus speed =5MHZ Mul and SCL divider can be selected from I2C Frequency Divider register (I2Cx_F) I2C baud rate = bus speed (Hz)/(mul SCL I2c connection in UNIQIT
I2C Driver Routines These Routines are written and kept in IIC.c file. The function prototypes for these routines are present in IIC.h These routines are used by the programmer to take the service from the I2C module of MK60 Some of these routines are board specific and designed for Cortex-M4 daughter board from Unified Softech.
Initialization Of I2C void init_iic(unsigned char bit_rate) this is the routine to initialize I2C. The steps followed to initialize the UART3 are 1. Turn on the clock to I2C1 module. 2. Configure GPIO for I2C1 module. 3. Set the baud rate 4. Enable I2C communication if the bus is busy ,diable I2C wait till bus is idle ,then resume
Initialization Of I2C Turn on the clock to I2C1 module. SIM_SCGC4 |= SIM_SCGC4_I2C1_MASK # define SIM_SCGC4_I2C1_MASK 0x80u Initialization Of UART3 Step 2. Enable the clock to the UART3 SIM_SCGC4 |= SIM_UART3;//SIM_SCGC4_UART3_MASK; UART3 UART3 bit = 1 . Enables the Clock
Initialization Of UART3 Step 3 .Disabled the Transmitter and Receiver while configure UART_C2_REG(UART3_BASE_PTR)&=~(UART_C2_TE_MASK | UART_C2_RE_MASK );
RE = 0 Disables the Receiver TE = 0 Disables the Transmitter
Step 4.Configure the UART for 8-bit mode and no parity UART_C1_REG(UART3_BASE_PTR) = 0;
Transmit Data through UART3 void tx_sci3_data(unsigned char ch), this routine is used to transmit one byte data through UART3 Steps to send data are 1. Wait until space is available in the FIFO 2. Put Data to be transmitted in the UART3 Data Register void tx_sci3_data(unsigned char ch) { while(!(UART_S1_REG(UART3_BASE_PTR)&UART_S1_TDRE_MASK)); UART_D_REG(UART3_BASE_PTR) = (unsigned char)ch; } Receive data through UART3 unsigned char rx_sci3_data() this function receives the data from other device through UART3. This function polls the Receive complete flag. And returns one byte data. Steps followed to receive the data are 1. Wait until character has been received 2. Read the data from UART3 data register 3. Return the 8-bit data from the receiver
Receive data through UART3 unsigned char rx_sci3_data() { while (!(UART_S1_REG(UART3_BASE_PTR) & UART_S1_RDRF_MASK));
return UART_D_REG(UART3_BASE_PTR); }
Assignment to test UART Driver Write a program to echo back the character received from the PC terminal Through RS232 Thank You