简要记录一下:ds1302 读取秒寄存器,总是在第一次读出ff,第二次才能读出准确的值的问题
遇到问题:ds1302 读取秒寄存器,总是在第一次读出ff,第二次才能读出准确的值
//无论再写保护WP开启状态,还是关闭状态,都存在上述问题
//经查 https://bbs.csdn.net/topics/390207271 可能需要在读取字节结束时,将IO脚置零,告诉器件释放总线
//添加了以下置零语句后,时钟数据读取正常。
DS1302_IO = 0;
对此问题简要记录,便于自己和大家查询参考。芯片手册未见与此现象有关的描述,因此暂不清楚原因,待学习研究。如有人了解此问题的原因,请留言赐教,谢谢。
另外,对于ds1302的写保护,记录如下:
* 【WP】位:WRITE-PROTECT BIT
* Bit 7 of the control register is the write-protect bit. The first seven bits (bits 0 to 6) are forced to 0 and always read 0 when read. Before any write operation to the clock or RAM, bit 7 must be 0. When high, the write-protect bit prevents a write operation to any other register. The initial power-on state is not defined. Therefore, the WP bit should be cleared before attempting to write to the device.
注意:仅在需要写入时,才关闭写保护。在读取数据时,请开启写保护,这样更稳定,更符合时钟芯片设计初衷
经实测,在关闭写保护的状态下,无法正常读取trickle_charge寄存器的值,始终读取到0xff。
遇到上述“ds1302 读取秒寄存器,总是在第一次读出ff,第二次才能读出准确的值”读取异常问题时,示波器显示的时序图:

添加了置零语句后,时钟数据读取正常,示波器抓取的时序如下:

浙公网安备 33010602011771号