123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #include "i2c.h"
- I2C_HandleTypeDef hi2c2;
- void MX_I2C2_Init(void)
- {
- hi2c2.Instance = I2C2;
- hi2c2.Init.ClockSpeed = 100000;
- hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
- hi2c2.Init.OwnAddress1 = 0;
- hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
- hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
- hi2c2.Init.OwnAddress2 = 0;
- hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
- hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
- if (HAL_I2C_Init(&hi2c2) != HAL_OK)
- {
- Error_Handler();
- }
- }
- void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
- {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- if(i2cHandle->Instance==I2C2)
- {
-
-
-
- __HAL_RCC_GPIOF_CLK_ENABLE();
-
- GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
- HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
-
- __HAL_RCC_I2C2_CLK_ENABLE();
-
-
- }
- }
- void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle)
- {
- if(i2cHandle->Instance==I2C2)
- {
-
-
-
- __HAL_RCC_I2C2_CLK_DISABLE();
-
-
- HAL_GPIO_DeInit(GPIOF, GPIO_PIN_0|GPIO_PIN_1);
-
-
- }
- }
|