在线时间0 小时
UID363991
ST金币0
蝴蝶豆0
注册时间2012-6-8
新手上路
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2012-8-31 12:31:28
|
显示全部楼层
a0a.1 0b0c
回复:stm32f107 iic进不了中断【悬赏问答】
回复第 2 楼 于2012-08-31 09:52:41发表:
中断的使用主要是开启模块中断,中断向量正确就可以。
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);
NVIC_InitStructure.NVIC_IRQChannel =I2C1_EV_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
I2C_ITConfig(I2C1,I2C_IT_BUF,ENABLE);
I2C_ITConfig(I2C1,I2C_IT_EVT,ENABLE);
void I2C_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
I2C_GPIO_Configuration();
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C_Speed;
I2C_Cmd(I2C1, ENABLE);
I2C_Init(I2C1, &I2C_InitStructure);
I2C_AcknowledgeConfig(I2C1, ENABLE);
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
I2C_GenerateSTART(I2C1, ENABLE);
相关代码应该就是这样了。while都能过,产生start后不会进中断。老大有空帮忙看看
|
|