@felmue this IDE code works for me on the CoreS3 - I had to cobble together code from various sources to get this to work (and still use the CoreS3 lib)
#define LTR553_ADDR 0x23
void writeRegister8(uint8_t _address, uint8_t subAddress, uint8_t data, uint32_t freq) {
Wire1.beginTransmission(_address);
Wire1.write(subAddress);
Wire1.write(data);
Wire1.endTransmission();
}
uint8_t readRegister8(uint8_t _address, uint8_t subAddress, uint32_t freq) {
Wire1.beginTransmission(_address);
Wire1.write(subAddress);
Wire1.endTransmission();
Wire1.requestFrom(_address, (size_t)1);
return Wire1.read();
}
void readRegister(uint8_t _address, uint8_t subAddress, uint8_t buff[], int size, uint32_t freq) {
Wire1.beginTransmission(_address);
Wire1.write(subAddress);
Wire1.endTransmission();
Wire1.requestFrom(_address, (size_t)size);
for (int i = 0; i < size; i++) {
buff[i] = Wire1.read();
}
}
bool LTR553Init() {
// soft reset
uint8_t value_r = readRegister8(LTR553_ADDR, 0x80, 100000L);
value_r &= (~0x02);
uint8_t value_w = value_r | 0x02;
writeRegister8(LTR553_ADDR, 0x80, value_w, 100000L);
// PS Led Pluse
writeRegister8(LTR553_ADDR, 0x83, 0x0F, 100000L);
// ALS Active Mode
value_r = readRegister8(LTR553_ADDR, 0x80, 100000L);
value_r &= (~0x01);
value_w = value_r | 0x01;
writeRegister8(LTR553_ADDR, 0x80, value_w, 100000L);
// PS Active Mode
value_r = readRegister8(LTR553_ADDR, 0x81, 100000L);
value_r &= (~0x03);
value_w = value_r | 0x03;
writeRegister8(LTR553_ADDR, 0x81, value_w, 100000L);
return true;
}
uint32_t GetLTR553AlsCh0Value() {
uint8_t buffer[2];
uint32_t result;
readRegister(LTR553_ADDR, 0x8A, buffer, 2, 100000L);
result = (buffer[1] << 8) | buffer[0];
return result;
}
uint32_t GetLTR553AlsCh1Value() {
uint8_t buffer[2];
uint32_t result;
readRegister(LTR553_ADDR, 0x88, buffer, 2, 100000L);
result = (buffer[1] << 8) | buffer[0];
return result;
}
uint16_t GetLTR553PsValue() {
uint8_t buffer[2];
uint16_t result;
readRegister(LTR553_ADDR, 0x8D, buffer, 2, 100000L);
buffer[0] &= 0xFF;
buffer[1] &= 0x07;
result = (buffer[1] << 8) | buffer[0];
return result;
}
call the Init from setup and call the Get* ones as you need