esp-open-rtos/extras/i2c
Our Air Quality afa834a805 i2c: remove wip 400k define
Looks like this was test wip code that should not have been included.
Want to be able to set the i2c per-project rather than having to patch
the driver.
2017-08-02 10:36:06 +10:00
..
component.mk Rework component makefiles to have a default <component>_ROOT 2015-09-08 09:59:59 +10:00
i2c.c I2c optimization and features (#321) 2017-03-21 11:41:47 +05:00
i2c.h i2c: remove wip 400k define 2017-08-02 10:36:06 +10:00
LICENSE Added BMP180 and I2C driver and example 2015-08-31 13:39:27 +02:00
README.md Update I2C README 2017-03-22 02:14:06 +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].

Usage

#include <i2c.h>

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

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

i2c_init(SCL_PIN, SDA_PIN);

// Write 1 byte to slave register
int err = i2c_slave_write(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(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