stm8L PB1读IIC总线时设置成GPIO_Mode_In_PU_No_IT,会进外部中断,这是什么情况?
unsigned char I2C_Read(void)
{
unsigned char dat=0;
unsigned char i = 8;
I2C_SDA1; //在读取数据之前,要把SDA拉高
GPIO_Init(GPIOB,GPIO_Pin_1,GPIO_Mode_In_PU_No_IT );
for (i=0; i<8; i++)
{
I2C_SCL1;
I2C_Delay();
dat <<= 1;
if (I2C_SDA)
dat |= 0x01;
I2C_Delay();
I2C_SCL0;
I2C_Delay();
}
GPIO_Init(GPIOB,GPIO_Pin_1, GPIO_Mode_Out_PP_High_Fast);//PE_DDR |= 0x04; //output
return (dat);
}
传感器SDA应答时会进入外部中断
INTERRUPT_HANDLER(EXTI1_IRQHandler, 9)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
EXTI_ClearITPendingBit(EXTI_IT_Pin1);
}
一周热门 更多>