We have launched a new Community! Please post any new forum topics there. This forum will remain available as an archive, but we hope you enjoy the new experience and feature set the latest NCD Community will offer!

using i2c bus on particle

Hello,

I'm trying to understand some sample code using a light sensor TCS34725 over the i2c bus on a particle electron (https://github.com/ControlEverythingCommunity/TCS34725/blob/master/Parti...). The TCS34725 address is 0x29 (as provided by the data sheet). My understanding of i2c is that in addition to the 7 bit address we need to include a read (1) or write (0) as the least significant bit. My first question is where is this read write bit set? Next looking at the TCS34725 data sheet (https://cdn-shop.adafruit.com/datasheets/TCS34725.pdf) the enable register address is listed as 0x00 (pasted below). In the sample code to access the enable register, 0x80 is written to (1000 0000). That really doesn't make sense to me. Could anyone explain why it's being written as 0x80?

Thanks for the help!

Brad

 // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Select enable register
  Wire.write(0x80);
  // Power ON, RGBC enable, wait time disable
  Wire.write(0x03);
  // Stop I2C Transmission
  Wire.endTransmission();

Trey's picture

Hi Brad,

The Particle "Wire" object handles the read/write bit when you call the corresponding function, so there is no need to set that manually.

The Enable register needs to be ORed with specific settings you would like to enable, though according to the data sheet, that bit should be written as 0, so I'm not sure why they are using it like that. Here is a newer library that actually provides an object class.

https://github.com/ncd-io/TCS3472/tree/master/Particle