void I2C_GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Enable GPIOA clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /*!< sEE_I2C Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1 , ENABLE); /*!< GPIO configuration */ /*!< Configure sEE_I2C pins: SCL */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;//GPIO_Mode_IN GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_3; GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;//open-drain GPIO_Init(GPIOA , &GPIO_InitStruct); /*!< Configure sEE_I2C pins: SDA */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIOA , &GPIO_InitStruct); /* Connect PXx to I2C_SCL*/ GPIO_PinAFConfig( GPIOA , GPIO_PinSource9, GPIO_AF_1); /* Connect PXx to I2C_SDA*/ GPIO_PinAFConfig( GPIOA ,GPIO_PinSource10, GPIO_AF_1); } void I2C_Configuration(void) { I2C_InitTypeDef I2C_InitStruct; /* I2C configuration */ I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; I2C_InitStruct.I2C_AnalogFilter = I2C_AnalogFilter_Enable; I2C_InitStruct.I2C_DigitalFilter = 0x00; I2C_InitStruct.I2C_OwnAddress1 =0xA0; I2C_InitStruct.I2C_Ack = I2C_Ack_Enable; I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStruct.I2C_Timing = 0x00100000;//100Kbits /* Apply I2C configuration after enabling it */ I2C_ITConfig(I2C2,I2C_IT_ADDRI,ENABLE); I2C_Cmd(I2C1, ENABLE); I2C_Init(I2C1, &I2C_InitStruct); /* I2C Peripheral Enable */ } void I2C1_IRQHandler(void) { I2C_ClearITPendingBit(I2C1, I2C_ISR_ADDR|I2C_ISR_STOPF ); LED_ON(); } #if 1 void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Configure the NVIC Preemption Priority Bits */ NVIC_InitStructure.NVIC_IRQChannel = I2C1_IRQn ; //I2C???? NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; //?????1 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //?????? NVIC_Init(&NVIC_InitStructure); //??NVIC_InitStruct???????????NVIC??? //I2C_ITConfig(I2C2, I2C_IT_EVT, ENABLE); } #else void NVIC_Configuration(void){} #endif int main(void) { ALL_Config(); NVIC_Configuration(); I2C_GPIO_Configuration(); I2C_Configuration(); while(1) { } } |
将 GPIO_AF_1改 GPIO_AF_4试试吧,我也刚搞这个,还没搞好,大家分享一下 |
下载到flash无法运行,开调试就能成功,是什么问题?
STM32是小端模式,但为什么Keil中memory窗口和反汇编窗口的32位指令不一致?
各位朋友,有没有STM32F0系列教程,最好是汇编语言的。
STM32F042F6P6TR
STM32F030F4P6使用SPI+DMA通信会受到UART中断堵塞吗?
关于STM32F030F4P6 SPI一主多从通信问题
STM32F030K6 低功耗停止模式下 SysTick 的问题
如何使用定时器在任意IO输出PWM
哪一个型号的stm32支持DMA直接从SPI将数据搬运到FMC
如何确定引脚编号?