这段程序读出寄存器数据没有问题,但是我想可不可以依次从首地址连续读出数据直到主机发出NACK
信号结束。还想请教一下大家
uchar date[7]; /* date[2]=hour,date[1]=minute,date[0]=second*/
uchar read_ds3231(uchar address) //从DS3231的某个地址读取1byte数据
{
uchar dat;
uchar n;
start();
write_i2c(0xd0);
while(!respons());
write_i2c(0x00); // 写秒寄存器地址
while(!respons());
start();
write_i2c(0xd1);
while(!respons());
date[0]=read_i2c();
stop();
delay();delay();delay();delay();
start();
write_i2c(0xd0);
while(!respons());
write_i2c(0x01); // 写分寄存器地址
while(!respons());
start();
write_i2c(0xd1);
while(!respons());
date[1]=read_i2c();
stop();
delay();delay();delay();delay();
start();
write_i2c(0xd0);
while(!respons());
write_i2c(0x02); //写小时寄存器地址
while(!respons());
start();
write_i2c(0xd1);
while(!respons());
date[2]=read_i2c();
stop();
} |