1
0
Fork 0
mirror of https://github.com/SMFSW/cI2C synced 2025-07-04 20:46:56 +02:00

v1.2: No internal address transmission when reading/writing to next internal address (auto-increment feature of most I2C devices)

This commit is contained in:
SMFSW 2017-11-30 22:40:42 +01:00
parent a44abc72ec
commit acfcfec7aa
6 changed files with 23 additions and 25 deletions

View file

@ -7,7 +7,7 @@
This example code is in the public domain.
created Jan 12 2017
latest mod Nov 21 2017
latest mod Nov 30 2017
by SMFSW
*/
@ -66,12 +66,12 @@ bool I2C_wr_advanced(I2C_SLAVE * slave, const uint16_t reg_addr, uint8_t * data,
{
if (bytes == 0) { return false; }
slave->reg_addr = reg_addr;
if (I2C_start() == false) { return false; }
if (I2C_sndAddr(slave, I2C_WRITE) == false) { return false; }
if (slave->cfg.reg_size)
if ((slave->cfg.reg_size) && (reg_addr != slave->reg_addr)) // Don't send address if writing next
{
slave->reg_addr = reg_addr;
if (slave->cfg.reg_size >= I2C_16B_REG) // if size >2, 16bit address is used
{
if (I2C_wr8((uint8_t) (reg_addr >> 8)) == false) { return false; }
@ -102,10 +102,10 @@ bool I2C_rd_advanced(I2C_SLAVE * slave, const uint16_t reg_addr, uint8_t * data,
{
if (bytes == 0) { return false; }
slave->reg_addr = reg_addr;
if (slave->cfg.reg_size)
if ((slave->cfg.reg_size) && (reg_addr != slave->reg_addr)) // Don't send address if reading next
{
slave->reg_addr = reg_addr;
if (I2C_start() == false) { return false; }
if (I2C_sndAddr(slave, I2C_WRITE) == false) { return false; }
if (slave->cfg.reg_size >= I2C_16B_REG) // if size >2, 16bit address is used