accumulation 发表于 2019-7-27 10:53 明白了,谢谢朋友解疑 |
地址指针是自动加1的,比如说 0iic开始 1写操作 2写地址sec 0x00 3写入数据 sex 4再次写数据 这里写入数据就是写到min寄存器0x01; 5iic结束 所以时间初始化是可以一次性写完的 |
这段程序读出寄存器数据没有问题,但是我想可不可以依次从首地址连续读出数据直到主机发出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(); } |