This library currently only supports the arduino DUE hardware TWI interface
Including this library
When including this library, add these lines to your module's Makefile.due:
#add I2C_library I2C ?= ../../../libraries/I2C_library include $(I2C)/Makefile.inc
Then you'll be able to include the library like so in your project files:
Using the library
Instantiate the library like so:
auto bus = r2d2::i2c::i2c_bus_c(r2d2::i2c::i2c_bus_c::interface::interface_0, 50000);
You can replace
r2d2::i2c::i2c_bus_c::interface::interface_1 if you need to use the secondary interface.
To use sda and scl you need to use
r2d2::i2c::i2c_bus_c::interface::interface_1. To use sda1 and scl1 you need to use
There is a chance you need to use pullup registers on a twi interface. Should work by default but interface_1 doesnt have internal pullup resistors.
Once instantiated you can use the read or the write function like so:
bus.write(address, data, sizeof(data) / sizeof(uint8_t)); bus.read(address, data, n);
data is your data array and
address is your 7-bit device address (i.e.
0x3C for an OLED display)
read example, data is your buffer and
n is the amount of bytes you want to read.