I2C example
Introduction
This is a simple example of how to implement an I2C master
interface using two GPIO pins. The example consists of two separate
applications, the first (master) is a full blown C application that
sends and receives data. The second is a standalone assembler
application that acts as the slave.
Master
The master application uses the BSP to open and initialise the GPIO
port, but then uses direct register access to actually do the bit
toggling. It repeated sends and then receives 16 bytes across the bus.
It uses GPIO A, bit 0 for the data and GPIO A, bit 2 for the clock.
Slave
The slave application does not use the BSP or RTOS, instead is coded in
assembler to ensure that all bit transitions are correctly detected.
The slave can receive I2C messages of up to 1024 bytes. Once
the message is received, it dumps the contents of the message to UART
0. It uses GPIO A, bit 0 for the data and GPIO A, but 1 for the clock.
Building the example
Change directory to the I2C example
cd %LF_HOME%\examples\i2c
Rebuild the application
lfmake clean all
Running the example
Connect GPIO A bit 0 on the slave board to GPIO A bit 0 on the master
board.
Connect GPIO A bit 1 on the slave board to GPIO A bit 2 on the master
board.
Connect a ground cable between the two boards.
To run the slave on the board
lfdownload -a <slave board address>
i2c_slave.bin
To run the master on the board
lfdownload -a <master board address>
i2c_master.bin
Features
This example demonstrates the following SDK features.