2013-06-22 10:06 AM
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
2013-06-23 01:08 AM
When i debug, my program hangs in stm32f4xx_i2c.c at
/* Write to I2Cx CR2 */ I2Cx->CR2 = tmpreg;tmpreg = 63 hereI have no idea where to go from hereI just tried to disable all my code except i2c init, still with the same result2013-06-23 02:22 AM
Okay guys,
I just replaced my discovery board and now it seems to be working :sWith this old board it just has hard faults on i2c.....What can be broken here?2013-06-23 04:55 AM
Not sure why it would hard fault, but PA9 isn't usable on the STM32F4-Discovery (VBUS + GREEN LED + 4u7 F)
Shouldn't I2C3 SDA be on PC9?2013-06-23 06:18 AM
Okay that's something i should change than....
The problem is that i always end up having to expand everything (prototyping robotics)I will need to put more on i2c bus and use less PWM outputs (here we go again).Still weird that it hard faults though.Well thanks for the info, i'm pushed in the right direction now!