你好
我在用STM32 I2C通信的时候发现一个问题,我的STM32是主机,主要是从外部设备读取数据,但是当发送STOP信号后SDA引脚没有上升沿信号,在进行第二次通信的时候就无法通信了。
请问这个问题应该怎样解决呢?下面是我的程序
I2C_GenerateSTART(I2C1, ENABLE);
TIM_Cmd(TIM2, ENABLE);
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) //EV5
{
if(timeout==1)
{
TIM_Cmd(TIM2, DISABLE);
timeout=0;
cnt=0;
LCD_PutString(10,40,"The device is not responsed",White,Magenta);
return;
}
LCD_PutChar(100, 40, 0x30+((StandTime-cnt)&0x0f), Black, Yellow);
}
TIM_Cmd(TIM2, DISABLE);
I2C_Send7bitAddress(I2C1, 0x27<<1, I2C_Direction_Receiver);
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); //EV6
/*½ÓÊÜ8 BYTEÊý¾Ý*/
LCD_PutString(20,40,"The I2C data is:",Black,Yellow);
for(i=0,col=40;i<2;i++,col+=14)
{
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED)); //EV7
I2C_Receive_Data[i] = I2C_ReceiveData(I2C1);
LCD_PutChar(col, 60, 0x30+((I2C_Receive_Data[i]>>4)&0x0f), Black, Yellow);
col+=7;
LCD_PutChar(col, 60, 0x30+(I2C_Receive_Data[i]&0x0f), Black, Yellow);
}
for(i=2,col=82;i<8;i++,col+=14)
{
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED)); //EV7
I2C_Receive_Data[i] = I2C_ReceiveData(I2C1);
LCD_PutChar(col, 60, I2C_Receive_Data[i], Black, Yellow);
}
// while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED)); //EV7
I2C_GenerateSTOP(I2C1, ENABLE); |
|