Uint16 SaveIIC(Uint16 addr,Uint8 data)
{
Uint16 ret;
Uint8 test;
OutMsg.MemoryLowAddr=addr;
OutMsg.MsgBuffer[0]=data;
ret=I2CA_WriteData(&OutMsg);
DELAY_US(50000);
//校验
}
Uint16 I2CA_WriteData(struct I2CMSG *msg) // I2C 写数据
{
Uint16 i; // 开始发送数据
I2caRegs.I2CSAR = msg->SlaveAddress; // 设置从设备地址
I2caRegs.I2CCNT = msg->NumOfBytes + 1; // 设置要发送的字节数目
I2caRegs.I2CDXR = msg->MemoryLowAddr; // 设置寄存器地址
I2caRegs.I2CMDR.all = 0x6E20; // 配置 I2C 发送模式——FREE、STT、STP、MST、TRX、IRS
for( i= 0; i < msg->NumOfBytes; i++)
{
while(!I2caRegs.I2CSTR.bit.XRDY); //Transmit-data-ready interrupt flag bit.发送数据就绪中断标志位。(I2CDXR)准备好接受新数据
I2caRegs.I2CDXR = *(msg->MsgBuffer + i);
}
while(I2caRegs.I2CSTR.bit.BB); // 忙检测
return SUCCESS;
}