完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我按照如下配置,但是就是不能进入接收中断,求大神帮忙看看。谢谢了
void I2C_Configuration(void) { GPIO_InitTypeDef GPIO_InitStruct; I2C_InitTypeDef I2C_InitStruct; NVIC_InitTypeDef NVIC_InitStructure; /* Configure the I2C clock source. The clock is derived from the HSI */ RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK); /*Enable GPIOB and I2c1 clock*/ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1 , ENABLE); /* Connect PXx to I2C_SCL*/ GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_1); /* Connect PXx to I2C_SDA*/ GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_1); /*GPIO Configuration*/ /*Configure I2C1 pins: SCL */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_OType = GPIO_OType_OD; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB,&GPIO_InitStruct); /*Configure sEE_I2C pins: SDA */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOB , &GPIO_InitStruct); /* Enable the USART1 gloabal Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = I2C1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /*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 =0x00; I2C_InitStruct.I2C_Ack = I2C_Ack_Enable; I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStruct.I2C_Timing = 0x00210507; I2C_Init(I2C1, &I2C_InitStruct); I2C_ITConfig(I2C1,I2C_IT_RXI | I2C_IT_TXI | I2C_IT_TCI | I2C_IT_STOPI,ENABLE); // I2C1->CR1|=0x7F<<1; //¿ªÆôÖÐ¶Ï I2C_Cmd(I2C1, ENABLE); } void sI2CInterrupt(void) { if(I2C_GetITStatus(I2C1,I2C_ISR_TXIS) != RESET) { if(num++ < 1) { I2C_SendData(I2C1, 0x00); } else { I2C_SendData(I2C1, Data2); num = 0; } } else if(I2C_GetITStatus(I2C1,I2C_ISR_TCR) != RESET) { I2C_TransferHandling(I2C1,0xA8,1,I2C_AutoEnd_Mode,I2C_No_StartStop); } else if(I2C_GetITStatus(I2C1,I2C_IT_RXNE) != RESET) //Êý¾Ý½ÓÊÕÖÐ¶Ï { Data1 = I2C_ReceiveData(I2C1); } else if(I2C_GetITStatus(I2C1,I2C_ISR_TC) != RESET) { I2C_TransferHandling(I2C1,0xA8,1,I2C_AutoEnd_Mode,I2C_Generate_Start_Read); } else if(I2C_GetITStatus(I2C1,I2C_IT_STOPF) != RESET) { I2C_ClearITPendingBit(I2C1,I2C_IT_STOPF); } } void sReadI2C(INT8U* lubData,INT16U luwI2CAddr,INT8U lubDataLen) { INT8U i; INT8U lubDeviceAddr; lubDeviceAddr = luwI2CAddr / 256; lubDeviceAddr = (lubDeviceAddr & 0x03) << 1; // µÈ´ý×ÜÏß¿ÕÏÐ while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)); I2C_TransferHandling(I2C1,EepromAddr | lubDeviceAddr,1,I2C_SoftEnd_Mode,I2C_Generate_Start_Write); } void I2C_uWriteData(INT8U *WriteBuf,INT8U lubWriteAddr,INT8U WriteLen,INT8U lubDeviceAddr) { INT8U i; lubDeviceAddr = (lubDeviceAddr & 0x03) << 1; // µÈ´ý×ÜÏß¿ÕÏÐ while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)); I2C_TransferHandling(I2C1,EepromAddr | lubDeviceAddr,1,I2C_Reload_Mode,I2C_Generate_Start_Write); } |
|
相关推荐
9个回答
|
|
stm32的硬件有点复杂,我用模拟的比较多
|
|
|
|
用HAL库吧,中断方式适合DMA。也有非中断的阻塞调用方式。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
楼主1楼这个程序是通的吧?
|
|
|
|
本帖最后由 alisa123 于 2016-4-7 13:34 编辑 我忘记了,下面这个链接是通的。 |
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
878 浏览 0 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
936 浏览 2 评论
2044 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1145 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1568 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 03:03 , Processed in 0.808345 second(s), Total 58, Slave 51 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号