你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32F030F4 IIC从模式 无法触发中断

[复制链接]
mr_sev 提问时间:2015-11-17 12:38 /
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)
{
}
}
收藏 评论1 发布时间:2015-11-17 12:38

举报

1个回答
quanqiuying 回答时间:2015-12-20 16:47:54
将 GPIO_AF_1改 GPIO_AF_4试试吧,我也刚搞这个,还没搞好,大家分享一下
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版