PSoC5LP Lab 09: I2C RTC Module

Objective

  1. Learn how to interface a Real‑Time Clock (RTC) module — such as the DS1307 or DS3231 — with the PSoC5LP MCU using the I²C protocol.
  2. Set up and configure the I2C Master component in PSoC Creator.
  3. Retrieve and display real-time data (time and date) from the RTC on a character LCD, enabling accurate timekeeping across power cycles.
  4. Understand RTC features like battery backup, low power consumption, and alarm/interrupt capability.

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. I2C or SPI Interface: RTCs commonly use I2C or SPI communication protocols to interface with microcontrollers, allowing simple, reliable integration into embedded systems.
  6. 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.
  7. 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.

In this lab, you will interface a microcontroller with the DS3231 RTC module using I2C to display the current date and time on an LCD, and allow the host PC to update the clock via UART commands. You will learn how to handle I2C register decoding, binary‑coded decimal (BCD) conversion, UART parsing, interrupt-driven design, and state machines — all essential skills for real-time embedded systems.

Required Reading Materials

Required Components

The following components are required for this lab.

Button Small 64 DS3231 (or DS1307) RTC module x 1
Resistor 64 Character LCD Module x 1

Circuit / Schematic

  • Connection for Character LCD Module
    LCDConnection
  • Connection for DS3231 RTC module

Procedure

Creating a New Project

  1. Launch PSoC Creator.
  2. Got to File ➤ Open Project ➤ Project/Workspace.
  3. Open the PSoC5LP workspace in the EE4450 folder.
  4. After PSoC Creator opens the workspace, right-click on Workspace 'PSoC5LP' in the Workspace Explorer and select Add ➤ New Project….
  5. 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:

  1. Add a UART:
    • In the Communication category.
    • Drag and drop a UART onto the schematic.
  2. Add an I2C Master component:
    • Still under the Communications category, open the I2C catalog.
    • Drag and drop the I2C Master (UDB) onto the schematic.
  3. Add an Interrupt:
    • In the System category.
    • Drag and drop an Interrupt onto the schematic.
  4. Add a Character LCD component:
    • In the Display catalog.
    • Drag and drop the Character LCD onto the schematic.
  5. Add a Logic Low '0' signal:
    • In the Digital ➤ Logic category.
    • Drag and drop a Logic Low '0' onto the schematic.

After completing these steps, the schematic will include all necessary components — UART, I2C Master, Interrupt, Character LCD, and Logic Low '0' — ready for configuration and connection in the next stage.

Configure the Components

  1. Configure the I2C (I2C_1):
    • Click on the I2C_1 component in the schematic.
    • Rename the component to I2C to represent its connection to the I2C bus.
    • Select Implementation to ☉ UDB.
    • Select the ☉ Internal clock to use the internal clock source.
    • Change the Data rate (kbps) to 400 kbps.
  2. Configure the Character LCD (LCD_Char_1):
    • Click on the LCD_Char_1 component in the schematic.
    • Rename it to LCD for clarity and easier identification.
  3. Configure the Digital Output Pin (SDA_1):
    • Click on the SDA_1 component in the schematic.
    • Rename it to I2C_SDA.
  4. Configure the Digital Output Pin (SCL_1):
    • Click on the SCL_1 component in the schematic.
    • Rename it to I2C_SCL.
  5. Configure the UART (UART_1):
    • Select the UART_1 component.
    • Rename the component to UART.
    • Set the following UART parameters:
      • Mode: Full UART (TX + RX)
      • Baud Rate: 115200 bps
      • Parity: None
      • Stop Bits: 1
      • Flow Control: None
  6. Configure the Interrupt (isr_1):
    • Select the isr_1 component.
    • Rename the component to ISR_UART.
  7. Configure the Digital Input Pin (Rx_1):
    • Select the Rx_1 component.
    • Rename the component to UART_Rx to indicate its role as the UART receive pin.
  8. Configure the Digital Input Pin (Tx_1):
    • Select the Tx_1 component.
    • Rename the component to UART_Tx to indicate its role as the UART transmit pin.

Wiring

  1. Remove unused Components
    • Delete the existing Clock_1 component and the wire connected to the I2C component.
      • The I2C will use its internal clock source, so no external clock is required.
    • Delete the existing RST_1 component connected to the reset pin of the I2C component.
  2. Connect Reset Pins
    • Connect the Logic Low '0' signal to the reset pin of both the I2C and UART components.
  3. Connect UART Interrupt
    • Connect the ISR_UART component to the rx_interrupt output of the UART component.
    • This ensures that the interrupt service routine (ISR) is triggered whenever a character is received via UART.

After completing these steps, the TopDesign.cysch file will show the updated design with the renamed I2C, LCD, ISR_UART and UART components properly set up for I2C and UART communication.

02 TopDesign s

Pin Assignment

DevicePort.PinDirectionDrive Mode

Generate Application

  • From the menu bar, click Build ➤ Generate Application.
  • This command instructs PSoC Creator to generate the necessary source code files based on the components you have placed and configured in the TopDesign.cyschschematic.

Configure Interrupt Priority

  • In the Workspace Explorer window, open Design Wide Resources ➤ Interrupts.
  • Locate I2C_I2C_IRQ in the interrupt list.
  • Set its Priority value to 6.
    Configure Interrupt Priority s

Template Firmware Code

Exercises

© 2025 Air Supply Information Center (Air Supply BBS)