cancel
Showing results for 
Search instead for 
Did you mean: 

Having problem with I2C4 in stm32H747 Disco

SLuit.1
Associate III

I am using STM32H747I-DISCO discovery kit. I want to use I2C4 in the kit but clock is not generated in scl.

I am using pin D15 as SCL and pin D14 as SDA of CN5 connector of discovery board. According to the user manual of discovery board D15 is connected to PD12 of MCU and D14 is connected to PD13 of MCU.

I configure the GPIO(PD12 and PD13) in output selecting AF6 as alternate function number. I have tried both GPIO_PULLDOWN and GPIO_PULLP in  GPIO_InitStruct.Pull  but it does not work. Code is below:

GPIO_InitTypeDef GPIO_InitStruct;

__HAL_RCC_GPIOD_CLK_ENABLE();

/*Configuring pin PD12: It is configured as AF6 alternate function for I2C4_SCL*/

 GPIO_InitStruct.Pin    = GPIO_PIN_12;

 GPIO_InitStruct.Pull   = GPIO_PULLDOWN;

 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;

 GPIO_InitStruct.Speed   = GPIO_SPEED_HIGH;;

 GPIO_InitStruct.Alternate = GPIO_AF6_I2C4;

 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

/* Configuring pin PD13: It is configured as AF6 alternate function for I2C4_SDA*/

 GPIO_InitStruct.Pin    = GPIO_PIN_13;

 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;

 GPIO_InitStruct.Pull = GPIO_PULLDOWN;

 GPIO_InitStruct.Speed   = GPIO_SPEED_HIGH;

 GPIO_InitStruct.Alternate = GPIO_AF6_I2C4;

 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

I have enabled the I2C4 clock:

  //Initialise I2C4 clock

  __HAL_RCC_I2C4_CLK_ENABLE();

And Finally, I have initialised I2C4:

static void MX_I2C4_Init(void){

hi2c4.Instance       = I2C4;

hi2c4.Mode         = HAL_I2C_MODE_MASTER;

hi2c4.Init.Timing      = 0x10707DBC;        //I2C frequency at 100 KHz. Value generated from CubeMX

hi2c4.Init.AddressingMode  = I2C_ADDRESSINGMODE_7BIT;

hi2c4.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;  //Needed only in I2C slave features

hi2c4.Init.OwnAddress2Masks = I2C_OA2_NOMASK;

hi2c4.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;

hi2c4.Init.NoStretchMode  = I2C_NOSTRETCH_DISABLE;

if(HAL_I2C_Init(&hi2c4) == HAL_OK)

{

HAL_UART_Transmit(&huart3,(void*) "Initialise success \r\n",21,200);

}

}

I loaded the tx buffer with some data in the while loop to see if clock is generated or not:

 BSP_LED_On(2u);

 uint8_t data_send = 0x80;

 uint16_t dev_addr = 0x44;

 HAL_I2C_Master_Transmit(&hi2c4, dev_addr, &data_send, 1,100);

 HAL_UART_Transmit(&huart3,dev_addr,1,200);

 HAL_Delay(1000);

When I looked at the clock data line, I could not see anything in the oscilloscope.

Could you please help me out with the problem as I am new to STM32.

1 ACCEPTED SOLUTION

Accepted Solutions
Mike_ST
ST Employee

Hello,

According to the datasheet I2C4 on PD12-PD13 is on alternate function #4, so I recommend to use GPIO_AF4_I2C4 for both pins.

https://www.st.com/en/microcontrollers-microprocessors/stm32h747-757.html#documentation

View solution in original post

2 REPLIES 2
Mike_ST
ST Employee

Hello,

According to the datasheet I2C4 on PD12-PD13 is on alternate function #4, so I recommend to use GPIO_AF4_I2C4 for both pins.

https://www.st.com/en/microcontrollers-microprocessors/stm32h747-757.html#documentation

Thank you. That was the problem. Now, I can see clock and data lines up and running.