Photon I2C Read API Function Return Buffer

Hi,

Please, need help Reading API via I2C between photon and TS80000( as slave) (http://www.semtech.com/images/datasheet/ts80000.pdf)

I have managed to read registers following the instructions on page 6 . eg reading register MAX_POWER_WPC:

  Wire.beginTransmission(TS80000_I2C_SLAVE_ADDRESS);
  Wire.write(MAX_POWER_WPC);
  Wire.endTransmission();

  Wire.requestFrom(TS80000_I2C_SLAVE_ADDRESS, 1);

  while(Wire.available()){   // slave may send less than requested
    byte lowerByte = Wire.read();

    Serial.print(lowerByte,DEC);
  }

I have stuck on how Read API Function Return Buffer using instructions on page 7. eg How do I read
READ_RX_ID on page 30.

Thanks

The docs do feature this sample code to illustrate how to read multi byte responses

https://docs.particle.io/reference/firmware/photon/#read--1

void setup() {
  Wire.begin();              // join i2c bus as master
  Serial.begin(9600);        // start serial for output
}

void loop() {
  Wire.requestFrom(2, 6);    // request 6 bytes from slave device #2

  while(Wire.available()){   // slave may send less than requested
    char c = Wire.read();    // receive a byte as character
    Serial.print(c);         // print the character
  }

  delay(500);
}

If you have a buffer, you’d just read into this buffer with something along this line

  buffer[i++] = Wire.read();
1 Like