4.1 I2C Simple Driver Example Source Code Reference
This file contains the API that implements the I2C simple master driver functionalities.
This file contains sample source codes to demonstrate the I2C SIMPLE Foundation Services APIs.
The example works like this:
- In this example, we will use I2C SIMPLE drivers to communicate with EEPROM 24LC256
- First, we will write a block of data to EEPROM. Then we will read the data we wrote into it.
- We will use UART/EUSART to display what we wrote and read from the EEPROM
Hardware Connections
- Connect the 24LC256 EEPROM to the device:
- Add Pull up resistors as per the 24LC256 data sheet recommendations
- Have a common ground connected
- Connect the appropriate SCL and SDA pins
For this example application to work the following needs to be done:
- Configure SCL and SDA pins in pin manager (Connected to SCL and SDA of EEPROM 24LC256)
- Add Delay Foundation Services library
- Configure the I2C Clock frequency to 100 KHz
- Add and configure the EUSART/UART module as follows:
- Enable EUSART: ticked
- Enable Transmit: ticked
- Redirect STDIO to USART: ticked
- Select TX and RX pins in Pin Manager Grid View.
- Connect the board to a laptop serial port.
- Open a serial port terminal application (i.e. PuTTY or TeraTerm)
- Configure the serial port application to the following settings:
- Baud Speed: same as the UART configuration
- Data: same as the UART configuration
- Parity: none
- Stop bits: same as the UART configuration
- Flow control: none
- Receive: Carriage Return
- Transmit: Carriage Return
- Local Echo: On
- Call I2CSIMPLE_example in the main function.