DS1307RTC.ino
4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
DS1307RTC.ino - CLI library sample implementing a CLI to control a DS1307 RTC
Version 1.0, latest version, documentation and bugtracker available at:
https://gitlab.lindenaar.net/arduino/CLI
Copyright (c) 2019 Frederik Lindenaar
This example shows how to add commands to read and set an DS1307 RTC (Real
Time Clock) module to the CLI. It extends the Debug example so that the CLI
library debugging commands are also included to check the I2C bus wiring and
access the module's NVRAM and EEPROM. The implementation uses Paul
Stoffregen's DS1307RTC library (https://github.com/PaulStoffregen/DS1307RTC)
so please ensure you have added that (and it's dependency TimeLib) through
the Aruino IDE's built-in library manager.
The following commands are available through the Serial Monitor (available
from the Tools menu of the Arduino IDE):
- ds1307 Set and/or show DS1307 RTC date and time
- eeprom_dump dump the contents of the built-in EEPROM
- i2c_scan scan the I2C bus for slave devices
- i2c_dump dump the contents of I2C attached EEPROM or Memory
- reset restart the microcontroller (software reset)
- help show the available commands and how to use them
To read the the DS1307 use:
ds1307 show the current time of the DS1307
i2c_dump 0x68 64 8 single show NVRAM (assuming device ID is 0x68)
(dump 56-byte NVRAM, start at offset 8)
To set the DS1307 clock use:
ds1307 2019-01-01 12:34:56 to set both the date and time
ds1307 2019-01-31 to set only the date
ds1307 12:34 to set only the time (seconds set to 0)
When your module also has an EEPROM (assuming device ID is 0x50) use:
i2c_dump 0x50 4096 dump 24LC32 EEPROM contents (4k)
Please note that the ds1307 command is implemented in separate files (that
opens in a separate tab in the Arduino IDE)
This sketch is free software: you can redistribute it and/or modify it under
the terms of version 3 of the GNU General Public License as published by the
Free Software Foundation, or (at your option) a later version of the license.
This code is distributed in the hope that it will be useful but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, visit <http://www.gnu.org/licenses/> to download it.
*/
#include <CLI.h>
#include <Wire.h>
#include "DS1307_Command.h"
// Initialize the Debug Command Line Interface
const char banner[] PROGMEM = "DS1307RTC Sample CLI"; // Banner to show upon startup of the CLI
CLI CLI(Serial, banner); // Initialize the CLI, telling it to attach to Serial
DS1307_Command DS1307RTC(CLI); // Initialize/Register ds1307 command
EEPROM_Dump_Command EEPROM_Dump(CLI); // Initialize/Register (built-in) eeprom_dump command
I2C_Scan_Command I2C_Scan(CLI); // Initialize/Register (built-in) i2c_scan command
I2C_Dump_Command I2C_Dump(CLI); // Initialize/Register (built-in) i2c_dump command
Reset_Command Reset(CLI); // Initialize/Register (built-in) reset command
Help_Command Help(CLI); // Initialize/Register (built-in) help command
// the setup function runs once when you reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
// Initialize the Serial port for the CLI
while (!Serial); // For Leonardo: wait for serial USB to connect
Serial.begin(9600);
// Initialize the Wire Interface
Wire.begin();
}
// the loop function runs over and over again forever
void loop() {
// handle CLI, if this returns true a command is running. Set Builtin LED accordingly
if (CLI.process()) {
digitalWrite(LED_BUILTIN, HIGH); // turn LED on when processing CLI command
} else {
digitalWrite(LED_BUILTIN, LOW); // turn LED off when not processing CLI command
}
}