2021-02-01 10:31 AM
Hello,
I'm still able to read i2c sensors (such as the TMP75 temperature sensor, the FT6336 touch sensor, and the TCA6424 multiplexer).
However it seems I'm not able to read data from OPT3001 ambient light sensor. The code is the following
static void OPT3001_Init(void)
{
uint8_t buf[] = {0x01, 0xCE, 0x10};
HAL_I2C_Master_Transmit(&hi2c1, OPT3001_ADDR, buf, 3, HAL_MAX_DELAY);
}
static uint16_t OPT3001_Read(void)
{
uint8_t buf[2];
uint16_t m;
HAL_I2C_Master_Transmit(&hi2c1, OPT3001_ADDR, (uint8_t *)0x00, 1, HAL_MAX_DELAY);
HAL_I2C_Master_Receive(&hi2c1, OPT3001_ADDR, buf, 2, HAL_MAX_DELAY);
m = (buf[0] << 8) | buf[1];
// lux = (float)m * (float)(1 << (buf[0] >> 4)) * 0.01;
return m;
}
The only register which returns non-zero values is the configuration register (0x01). The others return always zero.
I tried to see only buf[0] or buf[1] individually, but they are always zero.
The datasheet says "To change the register address for a read operation, a new partial I2C write transaction must be initiated. This partial write is accomplished by issuing a slave address byte with the R/W bit low, followed by the register address byte and a stop command."
I think that the stop command is the problem, but i don't know how to do it.
2021-02-01 12:42 PM
The sensor was soldered by JLCPCB, I think they soldered it in the wrong sense. Because I can read succesfully to it with another MCU and with this sensor soldered by me in a breakout board. Tomorrow I will try to reverse the original one.