mybag1 发表于 2013-11-5 21:51:25

Arduino + DS1302时钟模块遇到问题

本帖最后由 mybag1 于 2013-11-5 21:58 编辑

我使用arduino与DS1302时钟模块练习时,按照下面的代码,将VCC接5V,GND接地,CLK接4,DAT接3,RST接2。结果运行后,全显示为xxxxxxxxx 00.00.2000 -- 00:00:40是什么原因?

// DS1302_Serial_Easy (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1302-library to
// quickly send time and date information over a serial link
//
// I assume you know how to connect the DS1302.
// DS1302:CE pin    -> Arduino Digital 2
//          I/O pin   -> Arduino Digital 3
//          SCLK pin-> Arduino Digital 4

#include <DS1302.h>

// Init the DS1302
DS1302 rtc(2, 3, 4);

void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);

// Setup Serial connection
Serial.begin(9600);

// The following lines can be commented out to use the values already stored in the DS1302
// rtc.setDOW(FRIDAY);      // Set Day-of-Week to FRIDAY
rtc.setTime(12, 0, 0);   // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 8, 2013);   // Set the date to August 6th, 2010
}

void loop()
{
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");

// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");

// Send time
Serial.println(rtc.getTimeStr());

// Wait one second before repeating :)
delay (1000);
}

执行情况:


mybag1 发表于 2013-11-6 20:29:12

没人能帮忙回答一下吗?弘毅老师能否帮帮忙?

shenhaiyu 发表于 2013-11-7 11:24:21

setup部分这样写试试:

void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(true);
rtc.writeProtect(false);

// Setup Serial connection
Serial.begin(9600);

// The following lines can be commented out to use the values already stored in the DS1302
// rtc.setDOW(FRIDAY);      // Set Day-of-Week to FRIDAY
rtc.setTime(12, 0, 0);   // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 8, 2013);   // Set the date to August 6th, 2010
rtc.halt(false);
rtc.writeProtect(true);
}

飞翔的红猪 发表于 2013-11-7 15:11:48

看了一下你的库代码,可能是模块数据读取出错了,建议直接读取各个时间变量,而不是使用它的字符输出函数
另外,下次求助记得也贴一下你的库~~

mybag1 发表于 2013-11-7 20:58:21

shenhaiyu 发表于 2013-11-7 11:24 static/image/common/back.gif
setup部分这样写试试:

void setup()


灰常感谢,搞定!

shenhaiyu 发表于 2013-11-7 21:46:50

mybag1 发表于 2013-11-7 20:58 static/image/common/back.gif
灰常感谢,搞定!

有空的话建议你看看我转来的几篇帖子,都看懂了就完全明白DS130X系列的工作原理了,遇到问题也能自己解决了:


http://www.geek-workshop.com/thread-2225-1-1.html
http://www.geek-workshop.com/thread-2224-1-1.html
http://www.geek-workshop.com/thread-2227-1-1.html

mybag1 发表于 2013-11-7 22:04:31

好的,谢谢

philhoo 发表于 2013-12-9 21:55:51

好久没搞这个了,一直想在数码管上输出,还是LCD简单。

zengwh 发表于 2014-1-14 14:35:39

shenhaiyu 发表于 2013-11-7 11:24 static/image/common/back.gif
setup部分这样写试试:

void setup()


我这样试了还是不行怎么办?

shenhaiyu 发表于 2014-1-14 22:07:17

zengwh 发表于 2014-1-14 14:35 static/image/common/back.gif
我这样试了还是不行怎么办?

那就是晶振停震了

Joyce 发表于 2016-4-15 10:45:40

问题解决吗?有同一问题,你是怎么解决的?
页: [1]
查看完整版本: Arduino + DS1302时钟模块遇到问题