Skip to main content
VSrin
Associate III
November 7, 2019
Question

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.

  • November 7, 2019
  • 4 replies
  • 2406 views

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

}

    This topic has been closed for replies.

    4 replies

    VSrin
    VSrinAuthor
    Associate III
    November 7, 2019

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

    Tesla DeLorean
    Guru
    November 7, 2019

    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    VSrin
    VSrinAuthor
    Associate III
    November 8, 2019

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