cancel
Showing results for 
Search instead for 
Did you mean: 

I2C3 Bus Busy issue!

Mujtaba
Senior

Dear friends,

I am trying to read data from DS3231 RTC using SPI3 peripheral of STM32407VGt6 MCU.

At first I used the latest version of HAL drivers and Cube and easily could read/wrtie the DS3231 RTC module.

But now I need to use Standard Peripheral libraries to read data from RTC module and also read data from it.

The problem is as soon as the APB1 peripheral clock of I2C3 is set, the Busy bit is set too while there is no ongoing communications since the MCU acts as the Master device and provides the clock for the module and the MCU has not yet START the communication.

I have checked the RCC, GPIO and I2C3 peripheral registers in debug mode and all are the same in HAL written program and StdPeriLib written program.

The initialization code for I2C3 is as follows:

void Ds3231_Low_Level_Init(void)

{

   GPIO_InitTypeDef  ds3231_gpio_initstruct;

   I2C_InitTypeDef   ds3231_i2c_initstruct;

 /* DS3231_I2C_SCL_GPIO_CLK and DS3231_I2C_SDA_GPIO_CLK Periph clock enable */

 RCC_AHB1PeriphClockCmd(DS3231_I2Cx_SCL_RCC_AHB_PERIPH | DS3231_I2Cx_SDA_RCC_AHB_PERIPH, ENABLE);

 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

 /* DS3231_I2C Periph clock enable */

 RCC_APB1PeriphClockCmd(DS3231_I2Cx_CLK, ENABLE);

   /* DS3231 Peripheral Disable */

   I2C_Cmd(DS3231_I2Cx ,DISABLE);

   /* DS3231 DeInit */

   I2C_DeInit(DS3231_I2Cx);

// /* Reset DS3231_I2C IP */

// RCC_APB1PeriphResetCmd(DS3231_I2Cx_CLK, ENABLE);

// 

// /* Release reset signal of DS3231_I2C IP */

// RCC_APB1PeriphResetCmd(DS3231_I2Cx_CLK, DISABLE);

 /* GPIO configuration */

 /* Connect PXx to I2C_SCL*/

 GPIO_PinAFConfig(DS3231_I2Cx_SCL_GPIO_PORT, DS3231_I2Cx_SCL_SOURCE, DS3231_I2Cx_SCL_AF);

 /* Connect PXx to I2C_SDA*/

 GPIO_PinAFConfig(DS3231_I2Cx_SDA_GPIO_PORT, DS3231_I2Cx_SDA_SOURCE, DS3231_I2Cx_SDA_AF); 

// 

   /* Configure DS3231_I2C pins: SCL */

   ds3231_gpio_initstruct.GPIO_Pin   = DS3231_I2Cx_SCL_GPIO_PIN;

  ds3231_gpio_initstruct.GPIO_Mode   = GPIO_Mode_AF;

 ds3231_gpio_initstruct.GPIO_Speed = GPIO_Speed_50MHz;

  ds3231_gpio_initstruct.GPIO_OType = GPIO_OType_OD;

 ds3231_gpio_initstruct.GPIO_PuPd = GPIO_PuPd_NOPULL;

   GPIO_Init(DS3231_I2Cx_SCL_GPIO_PORT, &ds3231_gpio_initstruct);

   /* Configure DS3231_I2C pins: SDA */

   ds3231_gpio_initstruct.GPIO_Pin   = DS3231_I2Cx_SDA_GPIO_PIN;

   GPIO_Init(DS3231_I2Cx_SCL_GPIO_PORT, &ds3231_gpio_initstruct);

   /* I2C configuration */

 /* DS3231_I2C configuration */

 ds3231_i2c_initstruct.I2C_Mode = I2C_Mode_I2C;

 ds3231_i2c_initstruct.I2C_DutyCycle = I2C_DutyCycle_2;

 ds3231_i2c_initstruct.I2C_OwnAddress1 = I2C_SLAVE_ADDRESS7;

 ds3231_i2c_initstruct.I2C_Ack = I2C_Ack_Enable;

 ds3231_i2c_initstruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

 ds3231_i2c_initstruct.I2C_ClockSpeed = I2C_SPEED;

 /* DS3231_I2C Peripheral Enable */

 I2C_Cmd(DS3231_I2Cx, ENABLE);

 /* Apply DS3231_I2C configuration after enabling it */

 I2C_Init(DS3231_I2Cx, &ds3231_i2c_initstruct);

}

As soon as RCC_APB1PeriphClockCmd(DS3231_I2Cx_CLK, ENABLE); is called the Busy bit in I2C3->SR2 register is set.

Could anyone help me where the problem is?

Any helps would be appreciated.

I am using standard peripheral library version 1.8.0.

13 REPLIES 13

I don't know, honestly.

Perhaps a comparison of the associated clock config registers in both cases shows a difference ?

But without the board, it is difficult to say. The I2C peripheral is probably the least beloved in ST's STM32 family - for such reasons.

What you could try:

- copying the init code from the HAL to the SPL version; with modifications, of course.

- start from a working SPL - I2C example

Thanks for your cooperation.

I will check everything and as soon as I find the answer I will release it here.

No, it's all depends on the I2C clock.

As soon as the clock is enabled, the Busy bit is set.

Do you have external pullups? Does HAL use internal ones?​

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