在i2c通信的时候,ARM作主机,stm8s207作从机。arm发A1给stm8s,让stm8s发数据给arm,arm收到的第一个字节总是A1,之后才是stm8s发的数据,这是怎么回事? 哪位高手请帮个忙
stm8s207的I2C中断程序如下:
#ifdef _COSMIC_
@far @interrupt void I2C_IRQHandler(void)
#else /* _RAISONANCE_ */
void I2C_IRQHandler(void) interrupt 19
#endif /* _COSMIC_ */
{
u8 temp=0;
GPIO_WriteLow(GPIOE, GPIO_PIN_2);
if(I2C_GetFlagStatus(I2C_FLAG_ADDRESSSENTMATCHED)==SET) //地址匹配
{
if(I2C_GetFlagStatus(I2C_FLAG_TRANSMITTERRECEIVER)==SET)
{
AddrSendFlag=1;
// I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
temp = SendBuffer[SendCount++];
I2C_SendData(temp);
}
else
AddrReceFlag=1;
}
if((I2C_GetFlagStatus(I2C_FLAG_TXEMPTY)==SET) && (AddrSendFlag==1)) //发送完毕
{
temp = SendBuffer[SendCount++];
I2C_SendData(temp);
if(SendCount==5)
{
SendCount=0;
AddrSendFlag=0;
}
}
if((I2C_GetFlagStatus(I2C_FLAG_RXNOTEMPTY)==SET) && (AddrReceFlag == 1)) //接收到数据
{
temp = I2C_ReceiveData();
ReceBuffer[ReceCount++]= temp;
if(ReceCount==4)
{
ReceCount=0;
AddrReceFlag=0;
I2CReceFlag=1;
}
}
if(I2C_GetFlagStatus(I2C_FLAG_STOPDETECTION)==SET) //检测到停止位
{
I2C_ClearFlag(I2C_FLAG_STOPDETECTION);
}
if(I2C_GetFlagStatus(I2C_FLAG_TRANSFERFINISHED)==SET) //字节发送结束
{
I2C_ClearFlag(I2C_FLAG_TRANSFERFINISHED);
}
I2C->SR2 = 0x00;
GPIO_WriteHigh(GPIOE, GPIO_PIN_2);
} |