树莓派2 Model B安装Hwclock RTC DS3231模块技术求助
Hey there! Let's walk through your DS3231 RTC setup and fix the key issues in your current process, plus cover the critical steps you might be missing.
First, Correct Your Existing Mistakes
Looking at your steps, there's one obvious error that'll block your DS3231 from working:
- In step 3, you added
dtoverlay=i2c-rtc,ds1307to/boot/config.txt— but you're using a DS3231 chip! The overlay parameter must match your exact RTC model. Let's fix that first.
Full Step-by-Step Correct Setup
1. Fix the Device Tree Overlay
Run this command to edit the config file:
sudo nano /boot/config.txt
Replace the incorrect line with:
dtoverlay=i2c-rtc,ds3231
Save and exit with Ctrl+O, press Enter, then Ctrl+X.
2. Clean Up Module Loading
Your /etc/modules entry can be adjusted for clarity and correctness. Run:
sudo nano /etc/modules
Add these lines (one per module, instead of combining them):
i2c-bcm2708 i2c-dev
Save and exit.
3. Disable the Fake Hardware Clock (Critical for Wheezy)
Raspbian Wheezy uses a fake software-based clock by default, which will conflict with your physical DS3231. Let's disable it completely:
# Stop the running service sudo /etc/init.d/fake-hwclock stop # Prevent it from starting on boot sudo update-rc.d fake-hwclock remove # Optional but recommended: Uninstall the package sudo apt-get remove fake-hwclock
4. Update the hwclock Configuration
You already made a backup of /etc/default/hwclock — great move! Now tweak the active config to use your RTC:
sudo nano /etc/default/hwclock
Ensure these lines are set correctly:
HWCLOCKACCESS=yes HWCLOCKPARS= SHOWCLOCK=no HCTOSYS_DEVICE=/dev/rtc0
Save and exit.
5. Reboot and Verify the RTC
Reboot your Pi to apply all changes:
sudo reboot
After reboot, check if the DS3231 is detected on the I2C bus:
sudo i2cdetect -y 1
You should see 68 in the output — that's the default I2C address of the DS3231.
Next, set your system time and write it to the RTC:
# Replace with your current local time sudo date -s "2024-05-20 14:30:00" # Write system time to RTC sudo hwclock -w
Verify the RTC is reading the correct time:
sudo hwclock -r
This should return the time you just set.
6. Test Persistence (Optional)
To make sure the RTC keeps time without power:
- Power off your Pi, disconnect it from power for 5-10 minutes
- Power it back on, run
sudo hwclock -r— the time should still be accurate.
内容的提问来源于stack exchange,提问作者Rohit

