I2C2 configuration for SCCB with OV7725 CMOS
@@ -47,6 +47,30 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c)
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
+ if( hi2c->Instance == I2C2 )
+ {
+ /*##-1- Configure the I2C clock source. The clock is derived from the SYSCLK #*/
+ RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C2;
+ RCC_PeriphCLKInitStruct.I2c2ClockSelection = RCC_I2C2CLKSOURCE_PCLK1;
+ HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
+
+ /* Enable I2Cx clock */
+ __HAL_RCC_I2C2_CLK_ENABLE();
+
+ /*##-3- Configure peripheral GPIO ##########################################*/
+ /* I2C SCL GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_10;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+ /* I2C SDA GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_11;
+ GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+ }
}
/**
@@ -71,4 +95,16 @@ void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c)
/* Configure I2C SDA as alternate function */
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
}
+ if( hi2c->Instance == I2C2 )
+ {
+ /*##-1- Reset peripherals ##################################################*/
+ __HAL_RCC_I2C2_FORCE_RESET();
+ __HAL_RCC_I2C2_RELEASE_RESET();
+
+ /*##-2- Disable peripherals and GPIO Clocks #################################*/
+ /* Configure I2C SCL as alternate function */
+ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10);
+ /* Configure I2C SDA as alternate function */
+ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_11);
+ }
}
