The FOX Board natively supports the I2C protocol at kernel level, so the drivers are ready inside the kernel to interface directly I2C peripherals. In particular for the Dallas DS1302 RTC chip the support is already enabled in the memory image released with the FOX board, so , when you connect the chip as explained in the following, it will be immediately used by the operating system without any software adaptation or script changing.
As you can see from the schematic, there are only 5 wires to connect RTC DS1302 and FOX board. apart from the power supply wires, "+3.3 Volts" and "GND", the data communication between the FOX board and the RTC uses just other two wires for the I2C interface: I2C_DATA (connected on the FOX board on header J6 pin 32) and I2C_CLOCK (connected on the FOX board on header J6 pin 31). Moreover, the RTC chip DS1302 needs to be connected to a RESET signal that has to be held at logic level high when in I2C communication. This signal is generated by the driver inside the FOX Linux kernel and it comes out as I2C_RESET from header J6 pin 21.
In the proposed circuit as an application example, we used a common lithum battery type CR2032. The lithium batteries cannot be recharged hence it is necessary to block the DS1302 chip in its recharge battery function.
Infact, with the DS1302 you could change the lithium battery with a rechargeable battery or a supercap if you want, and the chip has the capaility to recharge it when the main power supply is switched on.
To avoid the current flow towards the battery we interposed a series diode D1 and the limiting current resistor R1 of 1000 Ohms in such a way that the current can flow from the battery to the RTC and not on the other way.
The I2C_DATA line has to be maintained at logic level high with a pull-up resistor. This line is bidirectional, so when the FOX needs to write data in the peripheral it drives the line, however when the FOX has to receive data from the peripheral, it sets its line in input mode. In the time interval during the switch from FOX driving and peripheral driving, the I2C_DATA line is not held by an output driver so it could go at logic level low. To prevent it we posed the pull-up resistor of 4700 Ohms.
To guarantee the best stability of the timing it is recommended to follow the hints presented in the datasheet of the DS1302 chip in terms of correct positioning of the 32768 Hz quartz. In particular regarding the ground plane to build in the surrounding of the quartz itself.
The RTC Dallas DS1302 chip with its quartz and lithium battery
Once completed the proposed circuit and connected to the FOX board it will be possible to see on the FOX console output during the Linux power on phase that it recognise the RTC chip Dallas DS1302. The chip will be read by the Linux system through the I2C interface signals. You can also see, from the console messages that you can obtain issuing from a telnet session or from the console itself the command:
dmesgthere you will find on which lines the Linux system is interfacing the RTC function:
... ds1302: RTC found. ds1302: SDA, SCL, RST on PB0, PB1, GENIO2 rtc_time : 16:51:18 rtc_date : 2006-03-06 ...
To read the FOX board Linux system clock and date the right command is:
To program a desired value of clock and date as system clock and date in the FOX Linux system the command is:
Example: 13:50 of May 18th 2005
To store in permanent way the system clock and date just set, in the RTC chip so to reload it at every power on cycle, type the following command: