Other Parts Discussed in Thread: LP5861
Tool/software:
Hello,
I'm trying to interface LP5861T with a USB-I2C bridge chip (MCP2221), but it seems something is wrong with the initialization sequence, can someone have a look at the following source code and let me know if the initialization function is ok?
// Write a single byte to LP5861T register
void LP5861_Write(uint8_t i2cTargetAddress, uint16_t startRegAddress, uint8_t data)
{
uint8_t payload[2] = {0};
i2cTargetAddress = (i2cTargetAddress << 2) | ((uint8_t) (startRegAddress >> 8)); //get the highest 2 bits of the startRegAddress to construct the i2c slave address with the 5 bits device address
payload[0] = (uint8_t) startRegAddress; //get the lower 8 bits of the startRegAddress
payload[1] = data; //data to send
qDebug() << Qt::hex << i2cTargetAddress << Qt::hex << payload[0] << Qt::hex << payload[1];
flag = Mcp2221_I2cWrite(handle, 2, i2cTargetAddress, I2cAddr7bit, payload);
}
// Initialize LP5861 device
void LP5861_init()//(uint8_t i2cTargetAddress, uint16_t startRegAddress)
{
// GP0 - VSYNC signal, only with data refresh modes 2 and 3
//OutValues[0] = MCP2221_GPVAL_HIGH; //set GP0 (output high) - VSYNC pin
//Mcp2221_SetGpioValues(handle, OutValues); //now set the DIO pins values
LP5861_Write(I2C_TARGET_ADDRESS_INDEPENDENT, reset_reg, 0xff); // Reset device
QThread::usleep(500); //wait for t_por (max 500us) to enter normal mode
LP5861_Write(I2C_TARGET_ADDRESS_INDEPENDENT, chip_en_reg, 0x01); // Enable device
QThread::usleep(150); //wait for t_chip_en (max 100us) to enter normal mode
/* initialize device */
LP5861_Write(I2C_TARGET_ADDRESS_INDEPENDENT, dev_initial, 0x00); // Data refresh mode = Mode_1, PWM frequency = 125 KHz (no VSYNC required for Mode_1)
LP5861_Write(I2C_TARGET_ADDRESS_INDEPENDENT, dev_config1, 0x00); // Linear dimming scale, PWM phase shift off
LP5861_Write(I2C_TARGET_ADDRESS_INDEPENDENT, dev_config2, 0x00); // Low brightness compensation clock shift number setting for all groups (1,2,3) is off
LP5861_Write(I2C_TARGET_ADDRESS_INDEPENDENT, dev_config3, 0x0E); // Maximum current 125 mA
}
// set current for all channels (0-255) via dc0-dc17 registers
void LP5861_SetCurrentAll(uint8_t CurrentValue)
{
for(i = 0; i <= 17; i++)
{
LP5861_Write(I2C_TARGET_ADDRESS_INDEPENDENT, dcReg[i], CurrentValue);
}
}
Thanks,
Karim

