Question
I2C3 configuration stm32F4Discovery
Posted on June 22, 2013 at 19:06
Hi everyone,
I'm trying to configure I2C3 on the stm32f4 discovery board but i end up in the hard fault handler at I2C_Init. I am doing something weird i'm sure, any ideas?void
I2C_Config(
void
)
{
GPIO_InitTypeDef GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C3, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
// Connect I2C3 pins to AF
GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_I2C3);
// SCL
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_I2C3);
// SDA
// configure I2C3
I2C_InitStruct.I2C_ClockSpeed = 100000;
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStruct.I2C_OwnAddress1 = 0x00;
I2C_InitStruct.I2C_Ack = I2C_Ack_Disable;
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_Init(I2C3, &I2C_InitStruct);
// enable I2C3
I2C_Cmd(I2C3, ENABLE);
}
#i2c3-stm32f4discovery