2019-11-07 01:24 PM
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
}
2019-11-07 01:25 PM
My code is getting stuck in "void i2cwrite" function in the while loop.
2019-11-07 02:22 PM
All looks very crude, are you sure there are some better I2C examples you can review?
2019-11-08 06:15 AM
This is what I found in the internet. And i modified it according to my project
2019-11-08 06:42 AM
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