AnsweredAssumed Answered

stm32f207zg i2c, start bit error

Question asked by gennaro82 on Oct 21, 2015
Latest reply on Oct 29, 2015 by gennaro82
Hi,

I'm working on a custom board,

cpu :stm32f207zg
 
on i2c2 there is an rtc - pcf2129

I started the project in STM32CubeMX, updated to the last version.
Pins are pf0 and pf1, pins are pulled up by 4,7k on both lines.

The project is generated for uVision, updated to the last version.

If I try to transmit something on i2c bus, the process fails due a timeout. The timeout occured in :

   /* Generate Start */
  hi2c->Instance->CR1 |= I2C_CR1_START;
 
  /* Wait until SB flag is set */
  if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_SB, RESET, Timeout) != HAL_OK)
  {
    return HAL_TIMEOUT;
  }

Honestly I checked the cpu manual all day long, and I didn't find faults in HAL library. The init code in master mode seems to be good:
 
   hi2c2.Instance = I2C2;
  hi2c2.Init.ClockSpeed = 10000;
  hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
  hi2c2.Init.OwnAddress1 = 0x00;
  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
  hi2c2.Init.OwnAddress2 = 0;
  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
  HAL_I2C_Init(&hi2c2);

Of course before to initialize the i2c, the clock is enabled on GPIOF.

Some people on line suggest to move i2c2 enable clock on top of gpio init function.

     +++__I2C2_CLK_ENABLE();
      /**I2C2 GPIO Configuration   
    PF0     ------> I2C2_SDA
    PF1     ------> I2C2_SCL
    */
    GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
    HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
 
    /* Peripheral clock enable */
    ---__I2C2_CLK_ENABLE();


But it doesn't fix anythings the only effect the device become always busy after init, and the software return for error here
  
if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
{
  return HAL_BUSY;
}

All the suggestions are welcome and thanks in advice for your help.

Gennaro

Outcomes