{
Uint16 i;
// Clearing of this bit by the module is delayed until after the SCD bit is
// set. If this bit is not checked prior to initiating a new message, the
// I2C could get confused.
if (I2caRegs.I2CMDR.bit.STP == 1) {
return I2C_STP_NOT_READY_ERROR;
I2caRegs.I2CSAR = msg->SlaveAddress; //这代表I2C为主机模式
if (I2caRegs.I2CSTR.bit.BB == 1) //代表接受到了起始信号
{
return I2C_BUS_BUSY_ERROR;
}
// MsgBuffer + Address
I2caRegs.I2CCNT = msg->NumOfBytes+2; // 为一个设备地址,一个是数据地址
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
// for (i=0; i<msg->NumOfBytes-2; i++)
for (i=0; i<msg->NumOfBytes; i++)
I2caRegs.I2CDXR = *(msg->MsgBuffer+i); //msg->MsgBuffer 是数组的首地址,则加1是下一个数组
}
I2caRegs.I2CMDR.all = 0x6E20; //0x0110 1110 0010 0000 理解位启动I2C
}
Susan Yang:
请问您现在使用的是哪款芯片?以28035为例,在其用户指南中有对应的说明
In the master mode, the RM, STT, and STP bits determine when the I2C module starts and stops data transmissions
在master 模式下,RM STT和STP位确定I2C模块何时启动和停止数据传输
而黄色部分的状态就是为了使I2C通信更加准确的
user5949198:
回复 Susan Yang:
想坠问一个关于I2C的
void WriteData(Uint16 addr,Uint16 data)//向EEPROM 指定地址写入一个字节的数据
{begintrans();//开始bytein(0xA0 + ((addr & 0x0300) >> 7));//写入写控制字0xA0bytein(addr);//写入指定地址bytein(data);//写入待写入EEPROM 的数据stoptrans();//停止delay1(8000);
}
中的bytein(0xA0 + ((addr & 0x0300) >> 7))地址和0x0300与,这有什么意义
其中0xA0为EEPROM的设备地址void bytein(Uint16 ch)//向EEPROM 写入一个字节
{Uint16 i;//变量定义SCL_0;//SCL=0delay1(delay1_UNIT * 2);//延时SDA_WRITE();//SDA方向为输出到EEPROMdelay1(delay1_UNIT);//延时for(i=8;i>0;i–){ if ((ch & 0x80)== 0) {SDA_W0;//数据通过SDA 串行移入EEPROMdelay1(delay1_UNIT);//延时}else {SDA_W1;delay1(delay1_UNIT);//延时}SCL_1;//SCL=1 delay1(delay1_UNIT * 2);//延时ch <<= 1;SCL_0;//SCL=0 delay1(delay1_UNIT);//延时}
user5949198:
回复 Susan Yang:
0xA0应该是写控制字,想问下什么叫控制字啊