“RTC 3231”的版本间的差异

来自YFRobotwiki
跳转至: 导航搜索
 
(未显示2个用户的15个中间版本)
第1行: 第1行:
 
+
[[Image:DS3231.jpg|400px|thumb|RTC DS3231]]
  
 
DS3231是低成本、高精度I²C实时时钟(RTC),具有集成的温补晶振(TCXO)和晶体。该器件包含电池输入端,断开主电源时仍可保持精确计时。集成微机电系统(MEMS)提高了器件的长期精确度,并减少了生产线的元件数量。DS3231提供商用级和工业级温度范围,采用16引脚300mil的SO封装。
 
DS3231是低成本、高精度I²C实时时钟(RTC),具有集成的温补晶振(TCXO)和晶体。该器件包含电池输入端,断开主电源时仍可保持精确计时。集成微机电系统(MEMS)提高了器件的长期精确度,并减少了生产线的元件数量。DS3231提供商用级和工业级温度范围,采用16引脚300mil的SO封装。
第8行: 第8行:
  
 
 除计时精度高之外,DS3231还具有一些其它功能,这些功能扩展了系统主机的附加功能和选择范围。该器件内部集成了一个非常精确的数字温度传感器,可通过I2C*接口对其进行访问(如同时间一样)。这个温度传感器的精度为±3°C。片上控制电路可实现自动电源检测,并管理主电源和备用电源(即低压电池)之间的电源切换。如果主电源掉电,该器件仍可继续提供精确的计时和温度,性能不受影响。当主电源重新加电或电压值返回到容许范围内时,片上复位功能可用来重新启动系统微处理器。
 
 除计时精度高之外,DS3231还具有一些其它功能,这些功能扩展了系统主机的附加功能和选择范围。该器件内部集成了一个非常精确的数字温度传感器,可通过I2C*接口对其进行访问(如同时间一样)。这个温度传感器的精度为±3°C。片上控制电路可实现自动电源检测,并管理主电源和备用电源(即低压电池)之间的电源切换。如果主电源掉电,该器件仍可继续提供精确的计时和温度,性能不受影响。当主电源重新加电或电压值返回到容许范围内时,片上复位功能可用来重新启动系统微处理器。
 +
  
 
==特性==
 
==特性==
  
* 0°C   至 +40°C 范围 内精度为±2ppm
+
工作电压 范围 :2.3 - 5.5V(<font color="red">推荐工作 压:3V-3.3V</font>)
* -40°C 至 +85°C 范围内精度为±3.5ppm
+
* 工作温度范围
* 为连续计时提供 池备份输入
+
* 工作温度范围  
+
 
: 商用级:0°C   至 +70°C  (DS3231S#)
 
: 商用级:0°C   至 +70°C  (DS3231S#)
 
: 工业级:-40°C 至 +85°C  (DS3231SN#)   
 
: 工业级:-40°C 至 +85°C  (DS3231SN#)   
 +
* 精度:
 +
: 0°C   至 +40°C 范围内精度为±2ppm
 +
: -40°C 至 +85°C 范围内精度为±3.5ppm
 +
* 为连续计时提供电池备份输入
 
* 低功耗
 
* 低功耗
 
* 实时时钟产生秒、分、时、星期、日期、月和年计时,并提供有效期到2100年的闰年补偿
 
* 实时时钟产生秒、分、时、星期、日期、月和年计时,并提供有效期到2100年的闰年补偿
第22行: 第25行:
 
* 可编程方波输出
 
* 可编程方波输出
 
* 高速(400kHz) I2C接口
 
* 高速(400kHz) I2C接口
* 支持工作电压范围2.3 - 5.5V(<font color="red">推荐工作电压:3V-3.3V</font>)
+
* 数字温度传感器输出:精度为±3°C (温度64秒更新一次 - 在VCC初次上电或Vbat供电下首次进行IIC通信时,开始读取温度值,之后每64秒读取一次)
* 数字温度传感器输出:精度为±3°C
+
 
* 老化修正寄存器  
 
* 老化修正寄存器  
 
* /RST输出/按钮复位去抖输入
 
* /RST输出/按钮复位去抖输入
 
 
  
 
==Arduino 库==
 
==Arduino 库==
第56行: 第56行:
 
|align="left"|SCL/A5
 
|align="left"|SCL/A5
 
|}
 
|}
 
 
   
 
   
 
<!--[[Image: RTC3231时钟模块.jpg|400px|center|RTC3231时钟模块接线图]]-->
 
<!--[[Image: RTC3231时钟模块.jpg|400px|center|RTC3231时钟模块接线图]]-->
 
 
  
 
:'''示例代码'''
 
:'''示例代码'''
<pre >
+
<source lang="c">
 
+
 
/* arduino sketch -- arduino print date and time with ds3231 RTC breakout
 
/* arduino sketch -- arduino print date and time with ds3231 RTC breakout
 
   SETUP:
 
   SETUP:
第177行: 第173行:
 
   Serial.print(datestring);
 
   Serial.print(datestring);
 
}
 
}
 +
</source>
  
</pre>
+
 程序下载地址:[https://eyun.baidu.com/s/3hsFQmUS  ClockWithSerialPrint] 密码:04gm
 程序下载地址:[http://pan.baidu.com/s/1eQ8SmzC passiveBuzzer_test]
+
 
 +
提示:程序中使用到的__DATE__,__TIME__;如果不理解请看介绍:[[宏: DATE , TIME , FILE , LINE]]
 +
 
 +
 
 +
小制作:[http://www.yfrobot.com/thread-11946-1-1.html RTC3231时钟模块做的小项目:桌面时钟]
  
  
  
 
==参考文档==
 
==参考文档==
[[http://wiki.yfrobot.com/datasheet/DS3231.pdf DS3231 芯片 手册]]
+
 
 +
[http://wiki.yfrobot.com/datasheet/DS3231.pdf DS3231_datasheet] [https://eyun.baidu.com/s/3eSL8wp0 备用地址]
 +
 
 +
[http://wiki.yfrobot.com/datasheet/DS3231_cn.pdf DS3231 数据 手册] [https://eyun.baidu.com/s/3miLwfTA 备用地址]
 +
 
 +
 
  
  
 
----
 
----
 +
  
  

2020年4月10日 (五) 16:40的最后版本

RTC DS3231

DS3231是低成本、高精度I²C实时时钟(RTC),具有集成的温补晶振(TCXO)和晶体。该器件包含电池输入端,断开主电源时仍可保持精确计时。集成微机电系统(MEMS)提高了器件的长期精确度,并减少了生产线的元件数量。DS3231提供商用级和工业级温度范围,采用16引脚300mil的SO封装。

RTC保存秒、分、时、星期、日期、月和年信息。少于31天的月份,将自动调整月末的日期,包括闰年修正。时钟格式可以是24小时或带/AM/PM指示的12小时格式。提供两个可设置的日历闹钟和一个1Hz输出。地址与数据通过I²C双向总线串行传输。

精密的、经过温度补偿的电压基准和比较器电路用来监视VCC状态,检测电源故障,提供复位输出,并在必要时自动切换到备份电源。另外,/RST监测引脚可以作为产生微处理器复位的按键输入,详细信息请参考完整数据资料中的方框图。

除计时精度高之外,DS3231还具有一些其它功能,这些功能扩展了系统主机的附加功能和选择范围。该器件内部集成了一个非常精确的数字温度传感器,可通过I2C*接口对其进行访问(如同时间一样)。这个温度传感器的精度为±3°C。片上控制电路可实现自动电源检测,并管理主电源和备用电源(即低压电池)之间的电源切换。如果主电源掉电,该器件仍可继续提供精确的计时和温度,性能不受影响。当主电源重新加电或电压值返回到容许范围内时,片上复位功能可用来重新启动系统微处理器。


特性

  • 工作电压范围:2.3 - 5.5V(推荐工作电压:3V-3.3V
  • 工作温度范围:
商用级:0°C 至 +70°C (DS3231S#)
工业级:-40°C 至 +85°C (DS3231SN#)
  • 精度:
0°C 至 +40°C 范围内精度为±2ppm
-40°C 至 +85°C 范围内精度为±3.5ppm
  • 为连续计时提供电池备份输入
  • 低功耗
  • 实时时钟产生秒、分、时、星期、日期、月和年计时,并提供有效期到2100年的闰年补偿
  • 两个日历闹钟
  • 可编程方波输出
  • 高速(400kHz) I2C接口
  • 数字温度传感器输出:精度为±3°C(温度64秒更新一次 - 在VCC初次上电或Vbat供电下首次进行IIC通信时,开始读取温度值,之后每64秒读取一次)
  • 老化修正寄存器
  • /RST输出/按钮复位去抖输入

Arduino 库

RTC DS1307 DS3231库


应用示例


电路连接


RTC3231时钟模块 Arduino UNO
VCC +5V
GND GND
SDA SDA/A4
SCL SCL/A5


示例代码
/* arduino sketch -- arduino print date and time with ds3231 RTC breakout
   SETUP:
    arduino (UNO R3)     ds3231
      A4/SDA          →    SDA
      A5/SCL          →    SCL
      GND             →    GND
 
   Read More about DS3231: http://www.yfrobot.com/wiki/index.php?title=RTC_3231
 
   BY YFROBOT
*/
 
#include <Wire.h>  // must be incuded here so that Arduino library object file references work
#include <RtcDS3231.h>
 
RtcDS3231 Rtc;
 
void setup ()
{
  Serial.begin(115200);
 
  Serial.print("compiled: ");
  Serial.print(__DATE__);      // 编译文档的日期
  Serial.println(__TIME__);    // 编译文档的时间
 
  //--------RTC SETUP ------------
  Rtc.Begin();
 
  // if you are using ESP-01 then uncomment the line below to reset the pins to
  // the available pins for SDA, SCL
  // Wire.begin(0, 2); // due to limited pins, use pin 0 and 2 for SDA, SCL
 
  RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__); // 存储当前编译的时间及日期并打印
  printDateTime(compiled);
  Serial.println();
 
  if (!Rtc.IsDateTimeValid())
  {
    // Common Cuases:
    //    1) first time you ran and the device wasn't running yet
    //    2) the battery on the device is low or even missing
 
    Serial.println("RTC lost confidence in the DateTime!");
 
    // following line sets the RTC to the date & time this sketch was compiled
    // it will also reset the valid flag internally unless the Rtc device is
    // having an issue
 
    Rtc.SetDateTime(compiled);
  }
 
  if (!Rtc.GetIsRunning())
  {
    Serial.println("RTC was not actively running, starting now");
    Rtc.SetIsRunning(true);
  }
 
  RtcDateTime now = Rtc.GetDateTime();  // 获取当前DS3231时间及日期
  if (now < compiled)
  {
    Serial.println("RTC is older than compile time!  (Updating DateTime)");
    Rtc.SetDateTime(compiled);
  }
  else if (now > compiled)
  {
    Serial.println("RTC is newer than compile time. (this is expected)");
  }
  else if (now == compiled)
  {
    Serial.println("RTC is the same as compile time! (not expected but all is fine)");
  }
 
  // never assume the Rtc was last configured by you, so
  // just clear them to your needed state
  Rtc.Enable32kHzPin(false);
  Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone);
}
 
void loop ()
{
  if (!Rtc.IsDateTimeValid())
  {
    // Common Cuases:
    //    1) the battery on the device is low or even missing and the power line was disconnected
    Serial.println("RTC lost confidence in the DateTime!");
  }
 
  RtcDateTime now = Rtc.GetDateTime();
  printDateTime(now);
  Serial.println();
 
  //输出温度 -- 温度每64秒更新一次 / 精度±3°C
  RtcTemperature temp = Rtc.GetTemperature();
  Serial.print("Temp:");
  Serial.print(temp.AsFloat());
  Serial.println("C");
 
  delay(10000); // ten seconds
}
 
#define countof(a) (sizeof(a) / sizeof(a[0]))
 
// 串口打印日期时间
void printDateTime(const RtcDateTime& dt)
{
  char datestring[20];
 
  snprintf_P(datestring, countof(datestring), PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
             dt.Month(), dt.Day(), dt.Year(),
             dt.Hour(), dt.Minute(), dt.Second() );
  Serial.print(datestring);
}

程序下载地址:ClockWithSerialPrint 密码:04gm

提示:程序中使用到的__DATE__,__TIME__;如果不理解请看介绍:宏: DATE , TIME , FILE , LINE


小制作:RTC3231时钟模块做的小项目:桌面时钟


参考文档

DS3231_datasheet 备用地址

DS3231数据手册 备用地址





返回首页

更多建议和问题欢迎反馈至 YFRobot论坛

购买方式:YFRobot 电子工作室