cancel
Showing results for 
Search instead for 
Did you mean: 

Does CubeMX code generator has some problems in I2C or not?

hamid
Associate
Posted on February 19, 2015 at 10:31

I'm a beginner in stm32Fx. I'm using Keil IDE and cubeMX code generator.

I've used I2C1 and I2C3 in my board with stm32f407 microcontroller and used cubeMX for generating initial codes. I've tried to use I2C3 and it didn't work but I2C1 worked correctly.

I've tested cubeMX code generator in my stmf429 discovery board and the same issue. I2C1 worked and I2C3 didn't work.

I have found a website that has very good libraries with drivers but not as complete as stm's, in that libraries all I2Cs work properly.

Does CubeMX code generator has some problems in I2C or not?

Thank you

 Best regaurds

#auto-corrected-dyslexia #cubemx #i2c-stm32f4
11 REPLIES 11
Amel NASRI
ST Employee
Posted on February 23, 2015 at 15:52

In the generated code, check what is made first: I2C clock enable or GPIO configuration.

If I2C clock is enabled before initializing GPIO, try to inverse this order.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

montagnanigiovanni
Associate II
Posted on March 09, 2015 at 17:16

thank you mayla,

i think that the code generated initialize first the GPIO, don't think so?

i post here the code snippet taken from msp_init.

GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;

    GPIO_InitStruct.Pull = GPIO_PULLUP;

    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

    GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;

    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

i've already patched my prototype, anyway, so solving this issue is just curiosity now :)

thank you

Giovanni