cancel
Showing results for 
Search instead for 
Did you mean: 

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.

VSrin
Associate II

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

}

4 REPLIES 4
VSrin
Associate II

My code is getting stuck in "void i2cwrite" function in the while loop.

All looks very crude, are you sure there are some better I2C examples you can review?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

This is what I found in the internet. And i modified it according to my project

The alternative would be to read and understand the chip level documentation.

https://www.st.com/en/embedded-software/stsw-stm8016.html

en.stsw-stm8016.zip\STM8L15x-16x-05x-AL31-L_StdPeriph_Lib\Project\STM8L15x_StdPeriph_Examples\I2C\I2C_EEPROM

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..