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;
}
sulin su:
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、IRSfor( 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;
}
,
Susan Yang:
请问您是否有用示波器看一下总线波形?SCL和SDA线的状态是什么?
您使用什么设备作为从设备?在您的代码中,您使用的是I2C FIFO模式还是非FIFO?
之前有客户遇到了类似的问题,是总线上噪声的问题
,
sulin su:
这是我的IIC的初始化代码
void I2CA_Init(void){ // Initialize I2C I2caRegs.I2CSAR = 0x0050; // Slave address – EEPROM control code
I2caRegs.I2CPSC.all = 6; // Prescaler – need 7-12 Mhz on module clk I2caRegs.I2CCLKL = 10; // NOTE: must be non zero I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
I2caRegs.I2CMDR.all = 0x0020; // Take I2C out of reset // Stop I2C when suspended
return;}
,
Susan Yang:
请问您是否有用示波器看一下总线波形?SCL和SDA线的状态是什么?