cI2C=Arduino Hardware I2C for AVR (in plain c)
|
Arduino Hardware I2C for AVR (plain c)
Hardware I2C library for AVR MCUs (lib intended for I2C protocols development in c, for easier ports to other MCUs)
No refactoring is required when switching between cI2C & WireWrapper libs; Both libs share same Typedefs, Functions & Parameters.
This library is intended to be able to work with multiple slaves connected on the same I2C bus. Thus, the I2C bus and Slaves are defined separately.
I2C_init(speed)
: speed can be chosen from I2C_SPEED
enum for convenience, or passing an integer as parameterI2C_SLAVE
typedef to declare slaves structsI2C_slave_init(pSlave, addr, regsize)
pSlave
: pointer to the slave struct to initializeaddr
: slave I2C address (don't shift addr, lib takes care of that)regsize
: width of internal slave registers (to be chosen from I2C_INT_SIZE
)I2C_slave_set_rw_func(pSlave, pFunc, rw)
pSlave
: pointer to the slave declaration to initializepFunc
: pointer to the Read or Write bypass functionrw
: can be chosen from I2C_RW
enum (wr=0, rd=1)After all inits are done, the lib can basically be used this way:
I2C_read(pSlave, regaddr, pData, bytes)
pSlave
: pointer to the slave struct to read fromregaddr
: start address to read frompData
: pointer to the place where datas read will be storedbytes
: number of bytes to read from slavetrue
if read is ok, false
otherwiseI2C_write(pSlave, regaddr, pData, bytes)
pSlave
: pointer to the slave struct to write toregaddr
: start address to write topData
: pointer to the block of datas to write to slavebytes
: number of bytes to write to slavetrue
if write is ok, false
otherwisefollowing examples should work with any I2C EEPROM/FRAM with address 0x50 (yet function to get Chip ID are device dependent (and will probably only work on FUJITSU devices))
Doxygen doc can be generated using "Doxyfile".
See [release notes]("https://github.com/SMFSW/cI2C/Release Notes.md")
cI2C
WireWrapper