AnsweredAssumed Answered

I2C setting problem in STM8L101

Question asked by Wong.Edward on Apr 24, 2017



I have a I2C setting problem on STM8L101, I am using the ST's "STM8L10x_StdPeriph_Driver" library and try to setup the I2C bus to run at standard mode 100KHz (with system clock of 2MHz) for reading a magnetic sensor. Unfortunately, it seems the I2C clock simply does not start properly.  However, if i slow down the I2C clock to 25KHz, the I2C bus becomes working normally and can get data from the magnetic sensor correctly.


Below is the program code that I used to configure the I2C interface of STM8L101:


//Initialization of Peripheral and CPU clock
   CLK_PeripheralClockConfig(CLK_Peripheral_I2C, ENABLE);     //Activation of I2C_CTR clock

   CLK_MasterPrescalerConfig(CLK_MasterPrescaler_HSIDiv8); // System clock (fMaster clock) is 2MHz

// Setup I2C pin => PC0 = SDA, PC1 = SCL (Both pin has external 4.7KOhm pull-up resistor) 


 //Initialization of the integrated I2C peripheral
    I2C_Cmd(ENABLE); //Activation of I2C peripheral
    I2C_DeInit();    //Initialization the I2C peripheral registers to their default reset values.
    I2C_Init(100000, 0xA0, I2C_DutyCycle_2,I2C_Ack_Enable,I2C_AcknowledgedAddress_7bit); // Initialization of I2C peripheral




If I use the below code (using 100KHz I2C speed), the I2C clock does NOT output:


I2C_Init(100000, 0xA0, I2C_DutyCycle_2,I2C_Ack_Enable,I2C_AcknowledgedAddress_7bit);




When I changed it to below code (using 25KHz I2C speed), the I2C clock can work correctly:


I2C_Init(25000, 0xA0, I2C_DutyCycle_2,I2C_Ack_Enable,I2C_AcknowledgedAddress_7bit);



1) Do you know what would be the possible cause of this I2C setting problem?

2) How can I use the standard mode 100KHz and what registers setting shall be used?