Advertisement
7134956

Untitled

Nov 6th, 2020 (edited)
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.93 KB | None | 0 0
  1. /*******************************************************************************
  2.  * I2C analog filter may provide wrong value, locking BUSY flag and
  3.  * preventing master mode entry
  4.  ******************************************************************************/
  5. void I2C_FixByErrata() {
  6. #ifdef SYSTEM_STM32
  7.     //1. Disable the I2C peripheral by clearing the PE bit in I2Cx_CR1 register
  8.     I2C2->CR1 &= ~I2C_CR1_PE;
  9.     //2. Configure the SCL and SDA I/Os as General Purpose Output Open-Drain, High level (Write 1 to GPIOx_ODR).
  10.     GPIOB->CRH &= ~(GPIO_CRH_CNF10_1 | GPIO_CRH_CNF11_1);
  11.     //3. Check SCL and SDA High level in GPIOx_IDR.
  12.     while(!(GPIOB->IDR & GPIO_IDR_IDR10) || !(GPIOB->IDR & GPIO_IDR_IDR11)); //SCL SDA
  13.     //4. Configure the SDA I/O as General Purpose Output Open-Drain, Low level (Write 0 to GPIOx_ODR).
  14.     GPIOB->ODR &= ~GPIO_ODR_ODR11;
  15.     //5. Check SDA Low level in GPIOx_IDR.
  16.     while(GPIOB->IDR & GPIO_IDR_IDR11);
  17.     //6. Configure the SCL I/O as General Purpose Output Open-Drain, Low level (Write 0 to GPIOx_ODR).
  18.     GPIOB->ODR &= ~GPIO_ODR_ODR10;
  19.     //7. Check SCL Low level in GPIOx_IDR.
  20.     while(GPIOB->IDR & GPIO_IDR_IDR10);
  21.     //8. Configure the SCL I/O as General Purpose Output Open-Drain, High level (Write 1 to GPIOx_ODR).
  22.     GPIOB->ODR |= GPIO_ODR_ODR10;
  23.     //9. Check SCL High level in GPIOx_IDR.
  24.     while(!(GPIOB->IDR & GPIO_IDR_IDR10));
  25.     //10. Configure the SDA I/O as General Purpose Output Open-Drain , High level (Write 1 to GPIOx_ODR).
  26.     GPIOB->ODR |= GPIO_ODR_ODR11;
  27.     //11. Check SDA High level in GPIOx_IDR.
  28.     while(!(GPIOB->IDR & GPIO_IDR_IDR11));
  29.     //12. Configure the SCL and SDA I/Os as Alternate function Open-Drain.
  30.     GPIOB->CRH |= GPIO_CRH_CNF10_1 | GPIO_CRH_CNF11_1;
  31.     //13. Set SWRST bit in I2Cx_CR1 register.
  32.     I2C2->CR1 |= I2C_CR1_SWRST;
  33.     //14. Clear SWRST bit in I2Cx_CR1 register.
  34.     I2C2->CR1 &= ~I2C_CR1_SWRST;
  35.     //15. Enable the I2C peripheral by setting the PE bit in I2Cx_CR1 register
  36.     I2C2->CR1 &= ~I2C_CR1_PE;
  37. #endif
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement