一个很bug的函数gpio_bit_write

  1. /*!
  2. \brief write data to the specified GPIO pin
  3. \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G)
  4. \param[in] pin: GPIO pin
  5. one or more parameters can be selected which are shown as below:
  6. \arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
  7. \param[in] bit_value: SET or RESET
  8. \arg RESET: clear the port pin
  9. \arg SET: set the port pin
  10. \param[out] none
  11. \retval none
  12. */
  13. void gpio_bit_write(uint32_t gpio_periph, uint32_t pin, bit_status bit_value)
  14. {
  15. if(RESET != bit_value){
  16. GPIO_BOP(gpio_periph) = (uint32_t)pin;
  17. }else{
  18. GPIO_BC(gpio_periph) = (uint32_t)pin;
  19. }
  20. }

bit_value 只能是SET or RESET 想弄成 0 1

解决办法:
image.png
image.png
image.png

搞了一天,I2C驱动OLED,没想到问题出在时钟上,不仅要打开GPIO的时钟,I2C也要同时打开。
image.png