Update I2C README

This commit is contained in:
UncleRus 2017-03-22 02:14:06 +05:00
parent 67a0cfbf8e
commit 07ca0d2e9e

View file

@ -2,18 +2,8 @@
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]. 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].
### Adding to your project
Add the driver to your project as a submodule rather than cloning it:
````
% git submodule add https://github.com/kanflo/esp-open-rtos-driver-i2c.git i2c
````
The esp-open-rtos makefile-fu will make sure the driver is built.
### Usage ### Usage
```` ````
#include <i2c.h> #include <i2c.h>
@ -23,18 +13,23 @@ The esp-open-rtos makefile-fu will make sure the driver is built.
uint8_t slave_addr = 0x20; uint8_t slave_addr = 0x20;
uint8_t reg_addr = 0x1f; uint8_t reg_addr = 0x1f;
uint8_t reg_data; uint8_t reg_data;
uint8_t data[] = {reg_addr, 0xc8};
i2c_init(SCL_PIN, SDA_PIN); i2c_init(SCL_PIN, SDA_PIN);
// Write data to slave // Write 1 byte to slave register
bool success = i2c_slave_write(slave_addr, data, sizeof(data)); 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 // Issue write to slave, sending reg_addr, followed by reading 1 byte
success = i2c_slave_read(slave_addr, &reg_addr, reg_data, 1); 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. 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 [1] https://en.wikipedia.org/wiki/I²C#Example_of_bit-banging_the_I.C2.B2C_Master_protocol