Example 17: DS1302 RTC Clock
About 1 min
Example 17: DS1302 RTC Clock
Experiment Overview
DS1302 is a low-power real-time clock chip that can maintain timekeeping after power-off via a coin cell battery. FastBee has a built-in DS1302 dedicated peripheral type (type: 50), supporting time read/set, trickle charging and 31 bytes of user RAM.
Hardware Wiring
| Board Label | GPIO Pin | Connected Device |
|---|---|---|
| CLK | GPIO14 | DS1302 clock line |
| DAT | GPIO27 | DS1302 data line |
| RST | GPIO26 | DS1302 reset/enable |
DS1302 uses a three-wire interface (CE/IO/SCLK), requiring 3 GPIO pins.
JSON Configuration Example
{
"peripherals": [
{
"id": "rtc_clk",
"name": "DS1302-CLK",
"type": 12,
"enabled": false,
"pins": [14],
"params": { "initialState": 0 }
},
{
"id": "rtc_dat",
"name": "DS1302-DAT",
"type": 12,
"enabled": false,
"pins": [27],
"params": { "initialState": 0 }
},
{
"id": "rtc_rst",
"name": "DS1302-RST",
"type": 12,
"enabled": false,
"pins": [26],
"params": { "initialState": 0 }
}
]
}Peripheral Execution Linkage (Plan A: NTP Approach)
Scenario: Periodic Time Display (Timer Trigger)
Function: Update seven-segment display with NTP-synced system time every second
Web Interface Configuration Steps
Step 1: Ensure TM1637 seven-segment display is configured
- Peripheral ID:
tm1637_01 - Type: Seven-segment display
Step 2: Create Rule
- Click left menu Peripheral Configuration → Switch to Peripheral Execution Management tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Periodic Time Display - Report Data: ✅ Enable
- Enabled: ✅ Enable
- Rule Name:
Step 3: Configure Trigger
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Timer Trigger Periodic update Timer Mode Select Fixed Interval By millisecond interval Interval Time 10001 second
Step 4: Configure Action
Click Add Action button
Fill in:
- Action Type: Select Display Time
- Target Peripheral: Select
tm1637_01
Click Save button
Approach Comparison
| Approach | Pros | Cons | Use Case |
|---|---|---|---|
| NTP | High precision, no hardware needed | Requires network | Networked devices |
| DS1302 | Retains on power-off, works offline | Extra hardware needed, lower precision | Offline devices |
Notes
- Battery: DS1302 needs a CR2032 coin cell to maintain time during power-off
- NTP Priority: In networked environments, recommend NTP; DS1302 is suited for offline scenarios
- Driver Support: FastBee has built-in DS1302 driver (FASTBEE_ENABLE_DS1302=1)
- Precision: DS1302 precision is ~±2ppm (~5 seconds per month)
- Communication Protocol: DS1302 uses 3-wire SPI (non-standard SPI), timing requires software emulation
