alisa123 发表于 2016-3-14 16:26:22

lkl0305 发表于 2016-3-14 15:58
我现在基本用HAL库,用起来放便些,我这两天给你看看,你没有逻辑分析仪之类的么,调试一下看看哪里有问题 ...

有逻辑分析仪的,就没怎么用过分析仪,我的这个只能进一次发送中断,然后就进不去了
我把我配置的程序发出来
void I2C_Configuration(void)
{
        GPIO_InitTypeDefGPIO_InitStruct;
        I2C_InitTypeDefI2C_InitStruct;
        NVIC_InitTypeDefNVIC_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)
{
        INT32U I2CFlagStatus = 0x00000000;
        I2CFlagStatus = (uint32_t)(I2C1->ISR & (uint16_t)0x0000000F6);
       
        if(I2C_GetITStatus(I2C1,I2C_ISR_TXIS) != RESET)
        {
                I2C_SendData(I2C1, Data2);       
        }
        else if(I2C_GetITStatus(I2C1,I2C_IT_RXNE) != RESET)                //Êý¾Ý½ÓÊÕÖжÏ
        {
                Data1 = I2C_ReceiveData(I2C1);
        //        I2C_ClearITPendingBit(I2C1, I2C_IT_RXNE);
        }
        else if(I2C_GetITStatus(I2C1,I2C_IT_STOPF) != RESET)
        {
                I2C_ClearITPendingBit(I2C1,I2C_IT_STOPF);
        }
        if(I2C_GetFlagStatus(I2C1, I2C_FLAG_STOPF) == SET)
        {
                I2C_ClearFlag(I2C1, I2C_ICR_STOPCF);
        }                       
}

lisha_love 发表于 2016-4-28 16:05:25

alisa123 发表于 2016-3-14 16:26
有逻辑分析仪的,就没怎么用过分析仪,我的这个只能进一次发送中断,然后就进不去了
我把我配置的程序发 ...

您好,您的程序能发我一份吗?我参考下。。。99834014@qq.com
谢谢您!

alisa123 发表于 2016-4-29 11:45:53

lisha_love 发表于 2016-4-28 16:05
您好,您的程序能发我一份吗?我参考下。。。
谢谢您!

你要查询方式的代码吗??

feiyingha 发表于 2016-6-30 18:59:55

万分感谢

jinzainanjing 发表于 2016-8-3 15:17:40

帮了大忙了

全球绝版仅此 发表于 2016-10-13 21:48:41

帮忙了:D

zbber 发表于 2016-10-13 23:45:49

谢谢分享

ynwscfsfi 发表于 2016-10-14 00:53:30


谢谢分享

anywill 发表于 2016-10-14 09:26:14


学习了,:P

a421622611 发表于 2016-11-16 22:45:04

大神谁给分析分析,为什么我的I2C能读正确读出一个字节数据,但是读完这个字节后不能产生NACK和STOP(MCU型号是:STM32F0303K6)C:\Users\JunHuaDen\Desktop\scope_10.bmp
页: 1 2 3 4 [5] 6 7
查看完整版本: 【STM32F030开发日志/评测/笔记】+(2)STM32F0处理器I2C实例(...