AnsweredAssumed Answered

STM32F411RE I2C

Question asked by marmsoler.martin on Sep 25, 2015
Latest reply on Sep 27, 2015 by marmsoler.martin
Hello,

I would like to configure on a stm32f4 the i2c interface, but the programm crashes in the gpio_init when I add the i2c_init line. Does anyone have an idea?

01.int
02.main(int argc, char* argv[])
03.{
04.    GPIO_InitTypeDef init;
05.    I2C_HandleTypeDef i2c1Handle;
06. 
07. 
08.    /* CLKs enable only if needed */
09.    __HAL_RCC_GPIOB_CLK_ENABLE();
10.    __HAL_RCC_I2C1_CLK_ENABLE();
11. 
12.    // SDL Port B8
13.    init.Pin = GPIO_PIN_8;
14.    init.Mode = GPIO_MODE_AF_PP;
15.    init.Alternate = GPIO_AF4_I2C1;
16.    HAL_GPIO_Init(GPIOB, &init);
17. 
18.    init.Pin = GPIO_PIN_9;
19.    HAL_GPIO_Init(GPIOB, &init);
20. 
21. 
22.    i2c1Handle.Instance = I2C1;
23.    i2c1Handle.Init.AddressingMode  = I2C_ADDRESSINGMODE_7BIT;
24.    i2c1Handle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
25.    i2c1Handle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
26.    i2c1Handle.Init.NoStretchMode   = I2C_NOSTRETCH_DISABLED;
27.    HAL_I2C_Init(&i2c1Handle);
28.    // Infinite loop
29.    while (1)
30.    {
31.        // Add your code here.
32.    }
33.}
 The programm jumps everytime in this routines:
01.void
02.__attribute__((weak))
03._exit(int code __attribute__((unused)))
04.{
05.#if !defined(DEBUG)
06.  __reset_hardware();
07.#endif
08. 
09.  // TODO: write on trace
10.  while (1)
11.    ;
12.}
13. 
14.// ----------------------------------------------------------------------------
15. 
16.void
17.__attribute__((weak,noreturn))
18.abort(void)
19.{
20.  trace_puts("abort(), exiting...");
21. 
22.  _exit(1);
23.}

Outcomes