RCC->AHBENR |= RCC_AHBENR_GPIOBEN; GPIOB->OTYPER = GPIOB->OTYPER | GPIO_OTYPER_OT_6 | GPIO_OTYPER_OT_7; GPIOB->AFR[0] = (GPIOB->AFR[0] & ~(GPIO_AFRL_AFRL6 | GPIO_AFRL_AFRL7)) | (1 << ( 6 * 4 )) | (1 << (7 * 4)); GPIOB->MODER = (GPIOB->MODER & ~(GPIO_MODER_MODER6 | GPIO_MODER_MODER7)) | (GPIO_MODER_MODER6_1 | GPIO_MODER_MODER7_1); RCC->APB1ENR |= RCC_APB1ENR_I2C1EN; RCC->CFGR3 |= RCC_CFGR3_I2C1SW; I2C1->TIMINGR = (uint32_t)0x00200000; I2C1->CR1 = I2C_CR1_GCEN | I2C_CR1_NOSTRETCH | I2C_CR1_PE | I2C_CR1_ADDRIE | I2C_CR1_TXIE | I2C_CR1_RXIE | I2C_CR1_TCIE | I2C_CR1_SBC; I2C1->OAR1 |= (uint32_t)(0x7F << 1); I2C1->OAR1 |= I2C_OAR1_OA1EN; NVIC_SetPriority(I2C1_IRQn, 0); NVIC_EnableIRQ(I2C1_IRQn); |
官方不是有例程代码和库文件么 可以参考看看 PE一般都是配置好前面的信息 最后才打开设备 有些配置需要在打开设备前配置好 |
【STM32F0开发日志/评测/笔记】+互补PWM波的产生
STM32F030 PB14和PB15无法输出PWM求助
【STM32F030探索套件】序列之五 外部中断
【STM32F0开发日志---二】+ucosii.2.92移植在STM32F030
上传个STM32F0+5110+内部温度传感器的菜鸟实例
【STM32F030探索套件使用问题】STM32F030 SPI方式驱动ST7565LCD失败
求一份STM32F051 I2C驱动LCD 12864的例程
STM32F0 M0 向结构体赋值进入HardFault异常
STM32F0 ADC-DMA方式采集2路数据时出现问题
STM32F030C8T6,TIM16定时慢很多问题?