各位朋友,最近在用STM32F030C8T6的硬件I2C 从模式,发现不管怎么做都无法进入中断,很是郁闷。有做过的朋友没有?
下面是初始化程序,请朋友看看有什么问题,谢谢!
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)(I2C1_SAVE_ADDRESS << 1);
I2C1->OAR1 |= I2C_OAR1_OA1EN;
NVIC_SetPriority(I2C1_IRQn, 0);
NVIC_EnableIRQ(I2C1_IRQn);
涛荣科技,提供高速PCB设计、制版、贴片一条龙服务。QQ:2787646549.