I have stm8l discovery and Can any one help with i2c configuration here. I am using LP55231 led driver and I do not know whether this configuration is correct.
Please go through the code and help me out in the configuration.
void i2c_init(void)
{
I2C1_FREQR = 0x20;// 16mHz
I2C1_CCRL = 0x50; // 160
I2C1_OARH = 0x40; // 7-bit addressing and add-mode configuration
I2C1_CR1 = 0x01; // enable peripheral
}
void i2c_start(void)
{
I2C1_CR2 |= 0x01; // start bit
(void) I2C1_SR1; // clear EV5
}
void i2c_write(uint8_t data)
{
I2C1_DR = data;
while (!(I2C1_SR1 & (0x80))); // data transmission polling
}
void i2c_write_addr(uint8_t addr)
{
I2C1_DR = addr; // address of led driver
(void) I2C1_SR1;
(void) I2C1_SR3; // clear EV6
}
