Skip to main content
Graduate
January 22, 2025
Solved

I2C1 & I2C2 Difference

  • January 22, 2025
  • 5 replies
  • 2780 views

Hello, this is DK.
I am working on a project using stm32f429IIt6.

I'm currently having an I2C problem at the end of my project.
I2C1 uses PF 0, 1 / I2C2 uses PB 6, 7. The HW PCB completed, and the HW I2C pull up is the same.

In I2C1 HAL code, the entire initialization does not work, and if I2C2 is used with the same code, it works well.

I am using various Pheripherals such as TIM Interrupt. Is there any conflict?

Is there any difference between I2C1 and I2C2?

In the TIMER part, it appears to share APB1.

 

    This topic has been closed for replies.
    Best answer by Jdogk

    I mean I2C3 has no problem.

     

    It just have I2C1 Initialize problem.

    When i call HAL_I2C_Master_Transmit(), HAL_I2C_Master_Receive() functions goes to HAL Busy Flag in Debug mode.

    and I temporarily fixed it. 

    When I use HAL_I2C_Master_Transmit, it goes HAL Busy Flag because of It's not in HAL_I2C_STATE_READY.

    so i add like above code. then it works.

     

    	if(HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)DevAddress, tx_buf, Size+1, 2) != HAL_OK)
    	{
    		MX_I2C1_Init();
    		HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)DevAddress, tx_buf, Size+1, 10);
    	}

     

    However, this method is only temporary, and I don't know what the fundamental problem is.
    I have already proceeded with I2C1 Initialize as a project to be created through CUBEIDE, and the code is written in the Main statement.
    Even if you debug by changing the MX_I2C1_Init() code up and down the Main statement, the same phenomenon occurs.
    The configuration of I2C1 is as follows. This appears to be correct code.

    100KHz polling I2C Initialize.

     

    /* I2C1 init function */
    void MX_I2C1_Init(void)
    {
    
     /* USER CODE BEGIN I2C1_Init 0 */
    
     /* USER CODE END I2C1_Init 0 */
    
     /* USER CODE BEGIN I2C1_Init 1 */
    
     /* USER CODE END I2C1_Init 1 */
    	hi2c1.Instance = I2C1;
    	hi2c1.Init.ClockSpeed = 100000;
    	hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
    	hi2c1.Init.OwnAddress1 = 0;
    	hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
    	hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
    	hi2c1.Init.OwnAddress2 = 0;
    	hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
    	hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
     if (HAL_I2C_Init(&hi2c1) != HAL_OK)
     {
     Error_Handler();
     }
    
     /** Configure Analogue filter
     */
     if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
     {
     Error_Handler();
     }
    
     /** Configure Digital filter
     */
     if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
     {
     Error_Handler();
     }
     /* USER CODE BEGIN I2C1_Init 2 */
    
     /* USER CODE END I2C1_Init 2 */
    
    }

     

     

    5 replies

    Technical Moderator
    January 22, 2025

    Hi @Jdogk ,

    You mean I2C1 on PB6/7 and I2C2 PF0/1.

    Is there any I2C error flag set when using I2C1?

    Does your PCB allow you to use PB8/9 instead of PB6/7 for I2C1?

    -Amel

     

    Super User
    January 22, 2025

    @Jdogk wrote:

    The HW PCB completed, and the HW I2C pull up is the same.


    Please show the PCB schematic.

    Have you used an oscilloscope and/or logic analyser to see what's happening on the wires?

    Super User
    January 22, 2025

    And to add one more question:
    > the entire initialization does not work,

    What does that mean exactly?  How can the "initialization" not work?  How do you know it doesn't work?  What are you trying to do and what errors get returned from the HAL functions?

    JdogkAuthor
    Graduate
    January 23, 2025

    Jdogk_1-1737597513302.png

     

    Hi Amel,

    My HW Setting is like this The first setting was I2C1 and the second setting was I2C2.


    Created with Cubeide project,

    #include i2c.h 
    MX_I2C2_Init();
    MX_I2C3_Init();

    in Main statement.

     

    And I use TIM1(PWM), TIM2(Timer interrupt count), TIM4(PWM), TIM5(for us Delay Timer Count), TIM8(Input Capture mode)

    Jdogk_2-1737597979526.png

    in Debug mode I2C Master Transmit in to HAL BUSY Flag

    Not initialize to HAL_I2C_STATE_READY

     

    here is logic analyzer sequence

    Jdogk_3-1737605769798.png

     

    Above one is normal intialzie and normal I2C communication sequence

    Jdogk_4-1737605841855.png

     

    I Think I2C1 is not working in abnormal initialize 

    Super User
    January 23, 2025

    @Jdogk wrote:

    Created with Cubeide project,

    #include i2c.h 
    MX_I2C2_Init();
    MX_I2C3_Init();

    in Main statement.


    I2C3, a typo?

    JdogkAuthor
    Graduate
    January 23, 2025

    What means typo? 

    I can't attach code because of my commpany rules.. 

    Super User
    January 23, 2025

    @Jdogk wrote:

    What means typo? 


    Misprint, typographical error. You wrote I2C3 here but talk about I2C1 issues.

    JdogkAuthor
    Graduate
    January 23, 2025

    Main issue is I2C1 go to HAL BUSY Flag.. and system locked.

    I2C Master Transmit in to HAL BUSY Flag

    I think Not initialize to HAL_I2C_STATE_READY

    This situation is often seen when you turn it on after first connecting the power, and it's working well afterwards.

    Super User
    January 23, 2025

    @Jdogk everyone can see all posts - there's no need to repeat posts with the same information.

     

    You can mention several people in one post with @