![]() |
發布時間: 2019-7-23 16:00
正文摘要:DS3231讀時間寄存器給定寄存器首地址后是否可以依次讀0x00秒, 0x01分,0x02時,0x03天,.....還是只能讀出給定寄存器的數據。 |
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(); } |