[求助]这样为什么只能读出一个字节呢???
我是第一次写I2C程序。我现在试着用当前地址读、随机读、顺序读三种方式来对时钟
芯片X1226进行读操作,前面两种已读操作成功,但顺序读时却只能读出一个字节(我向时钟芯片定入秒、分、时、天、月、年6个数,但顺序读时只能读出秒,其它的则为0,且当60秒到时也不进位!)。这个问题折磨了我几天了,现在我把程序贴出来,还望高手多多指点哪!!不胜感激!!
void I2cSerialRead(uchar device,uint address,uchar count,uchar *buff)
{ //从slave接收count字节数据
uchar i;
uchar addressh,addressl;
addressl = address&0xFF; //低位字节地址
addressh = address> > 8; //高位字节地址
I2cStart();
I2cSendByte(device);//写入器件地址
I2cSendByte(addressh); // 向slave写入高位字节地址
I2cSendByte(addressl); // 向slave写入低位字节地址
I2cStart();
I2cSendByte(device|0x01); //传送“读取信号”,即device地址加1
for(i=0;i <count;i++)
{
buff[i]=I2cReceiveByte();
if(i!=count-1)
SendAck(0); //应答
else
SendAck(1);
}
SendAck(1); //不应答
I2cStop();
}
发表时间:2005年6月3日22:26:53