esp-open-rtos/extras/i2c
Sakari Kapanen 4a1b600be4 i2c: improve timing
Look-up tables were used for determining the delay loop counts before.
Based on these hand-tuned values, the loop overhead was estimated for
each option -- 80 and 160 MHz, fast and slow GPIO access. Instead of the
great number of tunable parameters one now only has to tune the overhead
values if the code is changed.

Functions were added to the API which allow setting an arbitrary
frequency. API backward compatibility is retained.

i2c: fix potential overflow situation
2018-02-27 23:47:16 +02:00
..
component.mk Rework component makefiles to have a default <component>_ROOT 2015-09-08 09:59:59 +10:00
i2c.c i2c: improve timing 2018-02-27 23:47:16 +02:00
i2c.h i2c: improve timing 2018-02-27 23:47:16 +02:00
LICENSE Added BMP180 and I2C driver and example 2015-08-31 13:39:27 +02:00
README.md I2C code formatting, README fix (#462) 2017-10-12 17:42:34 +05:00

Yet another I2C driver for the ESP8266

This time a driver for the excellent esp-open-rtos. This is a bit banging I2C driver based on the Wikipedia pesudo C code [1].

Basic usage

#include <i2c.h>

#define BUS     (0)
#define SCL_PIN (0)
#define SDA_PIN (2)

uint8_t slave_addr = 0x20;
uint8_t reg_addr = 0x1f;
uint8_t reg_data;

i2c_init(BUS, SCL_PIN, SDA_PIN, I2C_FREQ_400K);

// Write 1 byte to slave register
int err = i2c_slave_write(BUS, slave_addr, &reg_addr, &data, 1);
if (err != 0)
{
	// do something with error
}

// Issue write to slave, sending reg_addr, followed by reading 1 byte
err = i2c_slave_read(BUS, slave_addr, &reg_addr, &reg_data, 1);

For details please see extras/i2c/i2c.h.

The driver is released under the MIT license.

[1] https://en.wikipedia.org/wiki/I²C#Example_of_bit-banging_the_I.C2.B2C_Master_protocol