6

First post here on the forum! Been getting a lot of help here from all the past posts and I am grateful for such a great community.

I have been trying to use Repeated Start by using the PIGPIO library using bitbanging.

However, I have not been able to get it working and I keep getting:

-82 error: i2c write failed.

For example, when I try to initialize the RGB sensor using the following line:

err = bbI2CZip(2,RGB_init_buf,sizeof(RGB_init_buf),NULL,0);

with the following initialization buffer:

char RGB_init_buf[] = {4, RGB_ADDR,  // set up Chip address
                   2, 7, 2, (RGB_COMMAND_BIT | TCS34725_ATIME), 0xEB, 3,   // 
                   2, 7, 2, (RGB_COMMAND_BIT | TCS34725_CONFIG), 0x00, 3, // 
                   2, 7, 2, (RGB_COMMAND_BIT | TCS34725_CONTROL), 0x01, 3, // 
           2, 7, 2, (RGB_COMMAND_BIT | TCS34725_ENABLE), TCS34725_ENABLE_PON,3, //power on
                   0 // EOL
                   };

I get an error code of -82, corresponding to a failed I2C write.

I set up my I2C bus as follows:

if (gpioInitialise() < 0) {
     printf("Pigpio library initialization failed\n");
     return -1;
}

if (bbI2COpen(2,3,100000) != 0){
     printf("Bit Banging initialization failed\n");
     return -1;
}

Anyone have any idea what could be problem?

SlySven
  • 3,631
  • 1
  • 20
  • 46
Thomas
  • 61
  • 1

1 Answers1

1

Are you sure that you have the right value for RGB_ADDR? Whenever I have seen a -82 error with pigpio it has been because the I2C chip is not responding. This is usually because you are using the wrong address. Another possibility is that SCL/SDA are swapped. Note that the data array expects a 7 bit address and pigpio automatically appends the correct read/write bit to create the 8 bit address/RW value used to access the slave.

Also, as joan noted above, you do not have any actual repeated starts in your array.

Typically a repeated start is used to read a register after writing the register number. It is specified by byte array data in the format shown below:

  ...   2, 7, 1, regnum, 2, 6, nbytes, 3, ...

The initial "2, 7, 1" is start, write, byte count 1, followed by the 1 byte register number. The "2, 6, nbytes, 3" is a repeated start followed by a read of nbytes followed by a stop.

Note that you must specify an address of a buffer to receive the read data.

crj11
  • 503
  • 4
  • 10