🛠 Ajouter une horloge temps réel sur le bus I2C des capes
Objectives
Wire and configure an I2C real-time clock (DS3231/DS1307 class) on the BeagleBone Black's I2C2 bus — the historical bus for capes, where addresses 0x54 to 0x57 are occupied by identification EEPROMs. You will learn how to probe the bus, declare the module to the kernel, and synchronize the system clock so that the date persists through a complete power loss without network access.
Hardware
- 1 BeagleBone Black
- 1 DS3231 (or DS1307) RTC module + CR2032 coin cell battery
- Wiring on P9: P9_19 = I2C2_SDA, P9_20 = I2C2_SCL, P9_03 = 3.3 V, P9_01/P9_02 = GND
- The bus is already pulled up to 3.3 V on the board: do not add additional pull-up resistors
Complete code
sudo apt install i2c-tools
sudo i2cdetect -l # repérer le numéro du bus I2C2
sudo i2cdetect -y -r 2 # le DS3231 répond en 0x68
# Déclaration à la volée pour tester (le module noyau existe déjà) :
sudo modprobe rtc-ds1307
echo ds1307 0x68 | sudo tee /sys/bus/i2c/devices/i2c-2/new_device
# Quelle RTC est laquelle ?
ls /sys/class/rtc/ ; cat /sys/class/rtc/rtc1/name
# Régler puis lire l'horloge RTC
sudo date -s "2026-10-14 09:00:00"
sudo hwclock -f /dev/rtc1 -w # système -> RTC
sudo hwclock -f /dev/rtc1 -r # RTC -> système
# Relire après un redémarrage complet (sans réseau)
sudo reboot
Expected verification
i2cdetect shows address 0x68; after running hwclock -w and rebooting with the network cable DISCONNECTED, the date is preserved (the kernel restores the RTC at boot). The name file of rtc1 contains "ds1307" or "ds3231".
Common errors
- Using the wrong bus number: i2cdetect -l is mandatory, as the bus visible on the pins is not always i2c-2 depending on the image.
- Address collision: cape EEPROMs occupy 0x54 to 0x57; a generic RTC module at 0x68 avoids conflict, but check before adding a second device.
- Forgetting the coin cell battery: without it, the RTC resets to zero at every power loss; test it (measure the battery holder voltage).
- Adding 5 V pull-ups on SDA/SCL: the bus is 3.3 V, and 5 V levels damage the pins.
- Relying on poweroff to preserve the battery: the SLEEP mode of the TPS65217 PMIC has been deemed risky for the hardware; the mainline kernel forces a complete OFF shutdown (ti,pmic-shutdown-controller property) — do not manually tamper with the PMIC.
Other tutorials for this board
- Premier boot de la BeagleBone Black avec un seul câble mini-USB
- Comprendre les triggers en pilotant les 4 LED utilisateur
- Bouton et LED avec Adafruit_BBIO, la bibliothèque historique
- Lire l'ADC 12 bits sans griller le SoC : la règle des 1,8 V
- Micro-HDMI : exploiter les limites d'affichage de la BBB
- Capes historiques : capemanager, EEPROM d'identification et pièges des broches
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash