Data Sheet

AS7265x
Design Considerations
ams Application Note Page 12
[v1-5] 2018-May-23 Document Feedback
Figure 13. Sample Code of Reading a Virtual Register
#define I2C_AS72XX_SLAVE_STATUS_REG 0x00
#define I2C_AS72XX_SLAVE_WRITE_REG 0x01
#define I2C_AS72XX_SLAVE_READ_REG 0x02
#define I2C_AS72XX_SLAVE_TX_VALID 0x02
#define I2C_AS72XX_SLAVE_RX_VALID 0x01
uint8_t i2cm_AS72xx_read(uint8_t virtualReg)
{
volatile uint8_t status, d ;
while (1)
{
// Read slave I2C status to see if we can write the reg address.
status = i2cm_read(I2C_AS72XX_SLAVE_STATUS_REG) ;
if ((status & I2C_AS72XX_SLAVE_TX_VALID) == 0)
// No inbound TX pending at slave. Okay to write now.
break ;
}
// Send the virtual register address
i2cm_write(I2C_AS72XX_SLAVE_WRITE_REG, virtualReg) ;
while (1)
{
// Read the slave I2C status to see if our read data is available.
status = i2cm_read(I2C_AS72XX_SLAVE_STATUS_REG) ;
if ((status & I2C_AS72XX_SLAVE_RX_VALID) != 0)
// Read data is ready for us.
break ;
}
// Read the data to complete the operation.
d = i2cm_read(I2C_AS72XX_SLAVE_READ_REG) ;
return d ;
}