Created
February 13, 2017 02:05
-
-
Save AlexanderBrevig/637a60cdd3b08accd7067be8aabc5d85 to your computer and use it in GitHub Desktop.
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
// http://www.stmicroelectronics.com.cn/content/ccc/resource/technical/document/errata_sheet/7d/02/75/64/17/fc/4d/fd/CD00190234.pdf/files/CD00190234.pdf/jcr:content/translations/en.CD00190234.pdf | |
// ERRATA 2.13.7 | |
// disable I2C1 | |
CLEAR_BIT(hi2c1.Instance->CR1, I2C_CR1_PE); | |
// make output open drain | |
GPIO_InitTypeDef GPIO_InitStruct; | |
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7; | |
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; | |
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; | |
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |
// force high | |
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_SET); | |
while (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6|GPIO_PIN_7) != GPIO_PIN_SET) {} | |
//force SDA low | |
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET); | |
while (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7) != GPIO_PIN_RESET) {} | |
//force SCL low | |
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET); | |
while (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6) != GPIO_PIN_RESET) {} | |
//force SCL high | |
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET); | |
while (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6) != GPIO_PIN_SET) {} | |
//force SDA high | |
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET); | |
while (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_7) != GPIO_PIN_SET) {} | |
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; | |
GPIO_InitStruct.Pull = GPIO_PULLUP; | |
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |
SET_BIT(hi2c1.Instance->CR1, I2C_CR1_SWRST); | |
CLEAR_BIT(hi2c1.Instance->CR1, I2C_CR1_SWRST); | |
SET_BIT(hi2c1.Instance->CR1, I2C_CR1_PE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment