cancel
Showing results for 
Search instead for 
Did you mean: 

I2C3 configuration stm32F4Discovery

kenny__84
Associate II
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
4 REPLIES 4
kenny__84
Associate II
Posted on June 23, 2013 at 10:08

When i debug, my program hangs in stm32f4xx_i2c.c at

/* Write to I2Cx CR2 */

  I2Cx->CR2 = tmpreg;

tmpreg = 63 here

I have no idea where to go from here

I just tried to disable all my code except i2c init, still with the same result
kenny__84
Associate II
Posted on June 23, 2013 at 11:22

Okay guys,

I just replaced my discovery board and now it seems to be working :s

With this old board it just has hard faults on i2c.....

What can be broken here?

Posted on June 23, 2013 at 13:55

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?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kenny__84
Associate II
Posted on June 23, 2013 at 15:18

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!