PSoC5LP Lab 09: I2C RTC Module
Objective
Overview
A Real-Time Clock (RTC) module in an embedded system is a dedicated hardware component that accurately tracks time, often across various power cycles. It provides precise timekeeping regarding seconds, minutes, hours, days, months, and years. RTCs are crucial for applications requiring accurate time management, such as data logging, scheduling tasks, alarms, and managing timestamps in file systems.
Key Features and Functions of RTC Modules
- Time and Date Tracking: An RTC maintains accurate time and date information. It can manage leap years, handle month-end adjustments, and keep track of hours, minutes, seconds, day of the week, and year.
- Battery Backup: RTCs typically operate with a low-power backup battery. This feature allows them to continue counting time even when the main power supply is off, ensuring uninterrupted time tracking.
- Low Power Consumption: Most RTC modules consume minimal power, making them ideal for battery-powered devices that require continuous timekeeping, such as wearable devices, portable equipment, and IoT nodes.
- Programmable Alarms and Interrupts: Many RTCs include alarm and interrupt features. Programmable alarms can trigger at specified times or intervals, which is useful for scheduling tasks in low-power modes or waking up the system from sleep.
- I2C or SPI Interface: RTCs commonly use I2C or SPI communication protocols to interface with microcontrollers, allowing simple, reliable integration into embedded systems.
- Automatic Calibration: Some advanced RTCs have self-calibration mechanisms to maintain high accuracy. This feature can correct for drift caused by temperature variations or oscillator aging.
- Applications: RTC modules are essential in applications where maintaining accurate time is critical, including:
- Data logging (e.g., environmental monitoring)
- Scheduled tasks and automation
- Timestamping in file systems
- Alarm systems and reminders
- Low-power devices where periodic wake-ups are necessary
Popular RTC Modules
- DS1307: A widely-used I2C-based RTC with battery backup and basic date/time tracking, suitable for simple applications.
- DS3231: Known for high accuracy, this I2C RTC has an integrated temperature-compensated crystal oscillator (TCXO) and features alarms, making it ideal for precision applications.
- PCF8563: This low-power RTC also uses I2C and is known for its power efficiency, making it popular in portable devices.
In summary, RTC modules in embedded systems enable precise and reliable timekeeping across power cycles, essential for any application requiring accurate time information or scheduled operations. Their low-power design and integration flexibility make them a core component in modern embedded and IoT systems.
Required Reading Material
- Lesson KB 01: Create a PSoC Project using PSoC Creator
- Datasheets:
- PSoC Creator Components
Required Components
If you use the Cypress CY8CKIT-059 Kit, the onboard LED and button will be used in this lab.
The following components are required for this lab.
DS3231 (or DS1307) RTC module | x 1 | |
Character LCD Module | x 1 | |
Red LED (or onboard LED) | x 1 |
Circuit / Schematic
Procedure
Creating a New Project
- Launch PSoC Creator.
- Got to File ➤ Open Project ➤ Project/Workspace.
- Open the PSoC5LP workspace in the EE4450 folder.
- After PSoC Creator opens the workspace, right-click on Workspace 'PSoC5LP' in the Workspace Explorer and select Add ➤ New Project….
- Select the correct PSoC5LP device model number, use the "Empty schematic" template, and enter the project name 09_I2C_RTC.
Adding PSoC Creator Components
Open the "TopDesign.cysch" Schematic File, add the following components:
- Add an I2C Master component:
- Similarly, go to the Communications ➤ I2C catalog.
- Drag and drop the I2C Master (UDB) onto the schematic.
- Add a Character LCD component:
- Navigate to the Display catalog in the component selection panel.
- Drag and drop the Character LCD onto the schematic.
Configure the Components
- Config the Digital Output Pin (Pin_1):
- Click on the Pin_1 component in the schematic.
- Rename the component to Wire1 to represent its connection to the 1-wire sensor.
- Uncheck the box for ☐ HW connection to disable the hardware connection. This step ensures that the pin will be controlled manually in the software.
- Change the Drive Mode to the Open drain, drive low mode.
- Config the Character LCD (LCD_Char_1):
- Click on the LCD_Char_1 component in the schematic.
- Rename the component to LCD for clarity and ease of identification.
The new TopDesign.cysch file is shown below:
Pin Assignment
Device | Port.Pin | Direction | Drive Mode |
---|---|---|---|