mr_sev 发表于 2015-11-17 11:52:37

stm32f03 I2C从模式,无法触发中断

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)
{
}
}

mr_sev 发表于 2015-11-17 11:53:55

这款芯片作为一个从芯片,通讯用IIC从模式,可是无法触发中断,这哪儿有问题啊

maxingyu1122 发表于 2015-11-17 20:23:36

帮顶。我也要做I2C从机,没头绪

mr_sev 发表于 2015-11-18 18:25:18

maxingyu1122 发表于 2015-11-17 20:23
帮顶。我也要做I2C从机,没头绪

已经解决,文档看错了

maxingyu1122 发表于 2015-11-25 21:09:15

mr_sev 发表于 2015-11-18 18:25
已经解决,文档看错了

我现在用I2C从模式发数据,没有ACK。。LZ是做的从机吗?能加个QQ咨询下嘛~

dengnian602 发表于 2016-1-16 17:34:53

maxingyu1122 发表于 2015-11-25 21:09
我现在用I2C从模式发数据,没有ACK。。LZ是做的从机吗?能加个QQ咨询下嘛~

问题解决了吗 求分享

alisa123 发表于 2016-3-9 16:25:41

楼主,你的问题已经解决了,请问是哪里出现问题了,分享下哦
页: [1]
查看完整版本: stm32f03 I2C从模式,无法触发中断