Created
November 16, 2017 22:24
-
-
Save rwoloszyn/e928a619b3f0e4fe26f11872e8586653 to your computer and use it in GitHub Desktop.
STM32F103 I2C BUSY FLAG Fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GPIO_InitTypeDef GPIO_I2CInitStructure; | |
/*Workaround p26 errata STM32F103*/ | |
__HAL_I2C_DISABLE(&hi2c1); | |
//OD HIGHG | |
GPIO_I2CInitStructure.Pin = I2C_SCL_PIN | I2C_SDA_PIN; | |
GPIO_I2CInitStructure.Mode = GPIO_MODE_OUTPUT_OD; | |
GPIO_I2CInitStructure.Pull = GPIO_PULLUP; | |
HAL_GPIO_Init(I2C_PORT, &GPIO_I2CInitStructure); | |
HAL_GPIO_WritePin(I2C_PORT, I2C_SCL_PIN, GPIO_PIN_SET); | |
HAL_GPIO_WritePin(I2C_PORT, I2C_SDA_PIN, GPIO_PIN_SET); | |
while(HAL_GPIO_ReadPin(I2C_PORT,I2C_SCL_PIN != GPIO_PIN_SET) | |
&& HAL_GPIO_ReadPin(I2C_PORT,I2C_SCL_PIN != GPIO_PIN_SET)); | |
//OD SDA LOW | |
// GPIO_I2CInitStructure.Pin = I2C_SDA_PIN; | |
// GPIO_I2CInitStructure.Mode = GPIO_MODE_OUTPUT_OD; | |
// GPIO_I2CInitStructure.Pull = GPIO_PULLDOWN; | |
// HAL_GPIO_Init(POWERON_PORT, &GPIO_InitStructure); | |
HAL_GPIO_WritePin(I2C_PORT, I2C_SDA_PIN, GPIO_PIN_RESET); | |
while(HAL_GPIO_ReadPin(I2C_PORT,I2C_SDA_PIN != GPIO_PIN_RESET)); | |
//OD SDA LOW | |
// GPIO_I2CInitStructure.Pin = I2C_SCL_PIN; | |
// GPIO_I2CInitStructure.Mode = GPIO_MODE_OUTPUT_OD; | |
// GPIO_I2CInitStructure.Pull = GPIO_PULLDOWN; | |
HAL_GPIO_Init(I2C_PORT, &GPIO_I2CInitStructure); | |
HAL_GPIO_WritePin(I2C_PORT, I2C_SCL_PIN, GPIO_PIN_RESET); | |
while(HAL_GPIO_ReadPin(I2C_PORT,I2C_SCL_PIN != GPIO_PIN_RESET)); | |
//OD SDA LOW | |
// GPIO_I2CInitStructure.Pin = I2C_SDA_PIN; | |
// GPIO_I2CInitStructure.Mode = GPIO_MODE_OUTPUT_OD; | |
// GPIO_I2CInitStructure.Pull = GPIO_PULLUP; | |
// HAL_GPIO_Init(POWERON_PORT, &GPIO_InitStructure); | |
HAL_GPIO_WritePin(I2C_PORT, I2C_SDA_PIN, GPIO_PIN_SET); | |
while(HAL_GPIO_ReadPin(I2C_PORT,I2C_SDA_PIN != GPIO_PIN_SET)); | |
//OD SDA LOW | |
// GPIO_I2CInitStructure.Pin = I2C_SCL_PIN; | |
// GPIO_I2CInitStructure.Mode = GPIO_MODE_OUTPUT_OD; | |
// GPIO_I2CInitStructure.Pull = GPIO_PULLUP; | |
// HAL_GPIO_Init(POWERON_PORT, &GPIO_InitStructure); | |
HAL_GPIO_WritePin(I2C_PORT, I2C_SCL_PIN, GPIO_PIN_SET); | |
while(HAL_GPIO_ReadPin(I2C_PORT,I2C_SCL_PIN != GPIO_PIN_SET)); | |
GPIO_I2CInitStructure.Pin = I2C_SCL_PIN | I2C_SDA_PIN; | |
GPIO_I2CInitStructure.Mode = GPIO_MODE_AF_OD; | |
GPIO_I2CInitStructure.Pull = GPIO_PULLUP; | |
HAL_GPIO_Init(I2C_PORT, &GPIO_I2CInitStructure); | |
__HAL_RCC_AFIO_CLK_ENABLE(); | |
__HAL_AFIO_REMAP_I2C1_ENABLE(); | |
hi2c1.Instance->CR1 |= I2C_CR1_SWRST; | |
hi2c1.Instance->CR1 &= ~I2C_CR1_SWRST; | |
__HAL_I2C_ENABLE(&hi2c1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment