Question
STM32F411RE I2C
Posted on September 25, 2015 at 21:34
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?
int
main(
int
argc,
char
* argv[])
{
GPIO_InitTypeDef init;
I2C_HandleTypeDef i2c1Handle;
/* CLKs enable only if needed */
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_I2C1_CLK_ENABLE();
// SDL Port B8
init.Pin = GPIO_PIN_8;
init.Mode = GPIO_MODE_AF_PP;
init.Alternate = GPIO_AF4_I2C1;
HAL_GPIO_Init(GPIOB, &init);
init.Pin = GPIO_PIN_9;
HAL_GPIO_Init(GPIOB, &init);
i2c1Handle.Instance = I2C1;
i2c1Handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
i2c1Handle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
i2c1Handle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
i2c1Handle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
HAL_I2C_Init(&i2c1Handle);
// Infinite loop
while
(1)
{
// Add your code here.
}
} The programm jumps everytime in this routines:
void
__attribute__((weak))
_exit(
int
code __attribute__((unused)))
{
#if !defined(DEBUG)
__reset_hardware();
#endif
// TODO: write on trace
while
(1)
;
}
// ----------------------------------------------------------------------------
void
__attribute__((weak,
noreturn
))
abort
(
void
)
{
trace_puts(
''abort(), exiting...''
);
_exit(1);
}