Skip to main content
sukoy27k
Associate II
October 21, 2015
Question

stm32f207zg i2c, start bit error

  • October 21, 2015
  • 3 replies
  • 1005 views
Posted on October 21, 2015 at 15:54

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
    This topic has been closed for replies.

    3 replies

    Amel NASRI
    ST Technical Moderator
    October 22, 2015
    Posted on October 22, 2015 at 15:23

    Hi gennaro82,

    The I2C clock speed is set to 10000. Is this a typo when copying your code here or it is a wrong value? It should be 100000 in standard mode.

    -Mayla-

    To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
    sukoy27k
    sukoy27kAuthor
    Associate II
    October 22, 2015
    Posted on October 22, 2015 at 15:48

    Hi Mayla

    Thanks for you help. No it was a test just for fun, the default speed is 100000.

    Gennaro

    sukoy27k
    sukoy27kAuthor
    Associate II
    October 29, 2015
    Posted on October 29, 2015 at 10:09

    ok problem fixed.

    there was a problem with pull up resistor.

    Thanks