[Diao Ye learns programming] Arduino hands-on (84) --- DS1307 clock module 2

insert image description here

The reference to 37 sensors and modules has been widely circulated on the Internet. In fact, there must be more than 37 sensor modules compatible with Arduino. In view of the fact that I have accumulated some sensor and actuator modules on hand, in accordance with the concept of true knowledge (must be hands-on), for the purpose of learning and communication, here I am going to try and do more experiments one by one. Whether it is successful or not, it will be recorded ——Small progress or unsolvable problems, I hope to be able to throw bricks and spark jade.

[Arduino] 168 kinds of sensor module series experiments (data code + simulation programming + graphics programming)
Experiment 84: DS1307 clock module Tiny RTC I2C module 24C32 memory clock (with battery)

insert image description here

Knowledge points: DS1307 chip and DS1307 clock module
1. DS1307 chip
1. DS1307 is an I2C bus interface real-time clock chip launched by DALLAS in the United States. It can work independently of the CPU and is not affected by the main crystal oscillator and its capacitance of the CPU, and the timing is accurate. , the monthly cumulative error is generally less than 10 seconds. The chip also has a clock protection circuit in the case of main power failure. The clock of DS1307 is maintained by the backup battery, and the CPU is denied read and write access to it. At the same time, it also has a backup power automatic switching control circuit, so it can ensure the timing accuracy of the system clock in the event of main power failure and other harsh environments. DS1307 has the functions of generating seconds, minutes, hours, days, months, years, etc., and has the function of automatic leap year adjustment. At the same time, the DS1307 chip also integrates a static RAM with a certain capacity and power-down protection feature, which can be used to save some key data.

insert image description here
2. Functional block diagram of DS1307

insert image description here
3. Main features of DS1307
(1) 56-byte non-volatile RAM
(2) Two-wire serial interface
(3) Programmable square wave output signal
(4) Automatic power failure detection and switching circuit
(5) In battery backup mode
(6) Industrial-grade operating temperature: -40°C to +85°C (
7) 8-pin DIP and SOIC packages
(8) Can be used for seconds, hours, minutes, days of the month, month , the number of days per week is counted, and it has a leap year compensation function, and the upper limit of the counting year is 2100.
(9) Approved by Underwriters Laboratories (UL).

insert image description here
4. Typical application circuit of DS1307
IC has SCL (serial clock) and SDA (serial data) pins for communicating with CPU, both pins must be pulled high with resistors. The IC can be powered by supplying 5V on the Vcc pin, when the power fails, it will automatically switch to the battery powered mode, in this mode, it is powered by a lithium battery connected to the pin Vbat and ground power supply.

insert image description here
X1 and X2 pins are used to connect crystal oscillator; usually 32.7KHz quartz crystal is used. The SQW pin is used to provide a PWM square wave with a programmable frequency range of 1Hz, 4KHz, 8KHZ or 32KHz. This pin also requires a pull-up resistor. Data between CPU and RTC IC can only be exchanged through I2C protocol. Both reading and writing happen through this communication. The IC can provide details such as real time clock counting seconds, minutes, hours, day of month, month, day of week and year with leap year compensation valid up to 2100.

5. DS1307 pins and configuration

insert image description here

insert image description here

Attachment: DS1307 chip related technical information
https://datasheets.maximintegrated.com/en/ds/DS1307.pdf

2. DS1307 clock module

insert image description here

1. Module features
(1) Use DS1307 I2C real-time clock chip (RTC)
(2) Use 24C32 32K I2C EEPROM memory
(3) Use LIR2032 rechargeable lithium battery with charging circuit
(4) Solve the problem that DS1307 cannot read and write with a backup battery The problem.
(5) After fully charged, it can provide DS1307 timing for 1 year.
(6) The design is compact, 27mm 28mm 8.4mm
(7) Lead out the clock pin of DS1307 to provide the clock signal for the microcontroller.
(8) Other I2C devices can be cascaded.

insert image description here
2. Module electrical schematic diagram

insert image description here
3. 32kHz crystal oscillator
The DS1307 chip needs a 32KHz external crystal oscillator to run (timing). Therefore, the RTC module comes with a 32KHz external crystal oscillator. But there is a problem with this 32KHz crystal oscillator, that is, changes in the ambient temperature will affect the oscillation frequency of the crystal oscillator. This variation of the external crystal oscillator frequency 32KHz is negligible. But in the long run it shows errors. It provides a clock drift of 2-3 minutes per month.

insert image description here

4. Onboard 24C32 EEPROM
DS1307 RTC module also includes onboard 24C32 EEPROM. The EEPROM can store 32 bytes and has limited read and write operations. We can use this memory to save time when we want to use the RTC module for alarm based projects. For example, we want to set an alarm at 8:00 every morning. We can save this time value into EEPROM and whenever the time matches this saved value, the alarm will be activated. These EEPROM chips also communicate with a microcontroller or Arduino via the I2C bus. Therefore, it shares the same I2C bus with the DS1307. Different slave addresses are assigned to EEPROM (o 0x50 Hex) and DS1307 chip to communicate with them on the same I2C bus.

5. Spare battery
On the back of the RTC module, there is a bracket for connecting the CR2032 coil unit. This backup battery is used to keep the time accurate even if the main power supply connected to the DS1307 fails. The chip contains a power sensing circuit to sense the main power, whenever the main power is turned off, it will switch to the backup coil unit.

insert image description here
6. DS1307 RTC module pins
The figure below shows the pin assignment diagram. The module has 7 pins in total, two of which are power supply pins, and two are SCL and SDA pins for I2C communication bus.

insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/132353748