void i2c_reset(i2c_t *obj) { int timeout; // wait before reset timeout = LONG_TIMEOUT; while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0)); if (obj->i2c == I2C_1) { __I2C1_FORCE_RESET(); __I2C1_RELEASE_RESET(); } if (obj->i2c == I2C_2) { __I2C2_FORCE_RESET(); __I2C2_RELEASE_RESET(); } #if defined I2C3_BASE if (obj->i2c == I2C_3) { __I2C3_FORCE_RESET(); __I2C3_RELEASE_RESET(); } #endif #if defined FMPI2C1_BASE if (obj->i2c == FMPI2C_1) { __HAL_RCC_FMPI2C1_FORCE_RESET(); __HAL_RCC_FMPI2C1_RELEASE_RESET(); } #endif }
void i2c_reset(i2c_t *obj) { if (obj->i2c == I2C_1) { __I2C1_FORCE_RESET(); __I2C1_RELEASE_RESET(); } if (obj->i2c == I2C_2) { __I2C2_FORCE_RESET(); __I2C2_RELEASE_RESET(); } }
void i2c_deinit(I2C_HandleTypeDef *i2c) { HAL_I2C_DeInit(i2c); if (0) { #if MICROPY_HW_ENABLE_I2C1 } else if (i2c->Instance == I2C1) { __I2C1_FORCE_RESET(); __I2C1_RELEASE_RESET(); __I2C1_CLK_DISABLE(); #endif } else if (i2c->Instance == I2C2) { __I2C2_FORCE_RESET(); __I2C2_RELEASE_RESET(); __I2C2_CLK_DISABLE(); } }
void I2C_Reset(I2C_TypeDef* I2Cx){ uint16_t timeout; timeout = LONG_TIMEOUT; while((I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY) != RESET) && (timeout-- != 0)); if(I2Cx == I2C1){ __I2C1_FORCE_RESET(); __I2C1_RELEASE_RESET(); } else if(I2Cx == I2C2){ __I2C2_FORCE_RESET(); __I2C2_RELEASE_RESET(); } }
void i2c_reset(i2c_t *obj) { int timeout; // wait before reset timeout = LONG_TIMEOUT; while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0)); if (obj->i2c == I2C_1) { __I2C1_FORCE_RESET(); __I2C1_RELEASE_RESET(); } if (obj->i2c == I2C_2) { __I2C2_FORCE_RESET(); __I2C2_RELEASE_RESET(); } }
void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) { GPIO_InitTypeDef GPIO_InitStruct; if(hi2c->Instance==I2C1) { __I2C2_FORCE_RESET(); __I2C2_RELEASE_RESET(); /* USER CODE BEGIN I2C1_MspInit 0 */ /* USER CODE END I2C1_MspInit 0 */ /**I2C1 GPIO Configuration PB8 ------> I2C1_SCL PB9 ------> I2C1_SDA */ GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); //hi2c->Instance->CR1 = I2C_CR1_SWRST; //复位I2C控制器 //hi2c->Instance->CR1 = 0; // 解除复位(不会自动清除) /* Peripheral clock enable */ __I2C1_CLK_ENABLE(); /* USER CODE BEGIN I2C1_MspInit 1 */ /* USER CODE END I2C1_MspInit 1 */ /*##-3- Configure the NVIC for I2C #########################################*/ /* NVIC for I2C1 */ // HAL_NVIC_SetPriority(I2C1_ER_IRQn, 0, 1); // HAL_NVIC_EnableIRQ(I2C1_ER_IRQn); // HAL_NVIC_SetPriority(I2C1_EV_IRQn, 0, 2); // HAL_NVIC_EnableIRQ(I2C1_EV_IRQn); } }
void i2c_deinit(I2C_HandleTypeDef *i2c) { HAL_I2C_DeInit(i2c); if (0) { #if defined(MICROPY_HW_I2C1_SCL) } else if (i2c->Instance == I2C1) { __I2C1_FORCE_RESET(); __I2C1_RELEASE_RESET(); __I2C1_CLK_DISABLE(); HAL_NVIC_DisableIRQ(I2C1_EV_IRQn); HAL_NVIC_DisableIRQ(I2C1_ER_IRQn); #endif #if defined(MICROPY_HW_I2C2_SCL) } else if (i2c->Instance == I2C2) { __I2C2_FORCE_RESET(); __I2C2_RELEASE_RESET(); __I2C2_CLK_DISABLE(); HAL_NVIC_DisableIRQ(I2C2_EV_IRQn); HAL_NVIC_DisableIRQ(I2C2_ER_IRQn); #endif #if defined(MICROPY_HW_I2C3_SCL) } else if (i2c->Instance == I2C3) { __I2C3_FORCE_RESET(); __I2C3_RELEASE_RESET(); __I2C3_CLK_DISABLE(); HAL_NVIC_DisableIRQ(I2C3_EV_IRQn); HAL_NVIC_DisableIRQ(I2C3_ER_IRQn); #endif #if defined(MICROPY_HW_I2C4_SCL) } else if (i2c->Instance == I2C4) { __HAL_RCC_I2C4_FORCE_RESET(); __HAL_RCC_I2C4_RELEASE_RESET(); __HAL_RCC_I2C4_CLK_DISABLE(); HAL_NVIC_DisableIRQ(I2C4_EV_IRQn); HAL_NVIC_DisableIRQ(I2C4_ER_IRQn); #endif } }