/
Using RTC PCF85263A

Using RTC PCF85263A

1. Overview

This application note describes how to configure RTC PCF85263A in Zephyr BSP and use it in the user application.

2. Configuring RTC PCF85263A in Zephyr BSP

The PCF85263A device is declared in nrf9151som_nrf9151_ns.dts as a child node of the i2c1 bus:

&i2c1 { ... rtc_pcf85263a: pcf85263a@51 { compatible = "nxp,pcf85263a"; reg = <0x51>; alarms-count = <2>; inta-mode = <(INTx_ALARM1_IE | INTx_LEVEL_MODE)>; inta-gpios = <&gpio0 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; status = "okay"; }; ... };

This node configures the following parameters:

Parameter

Value

Description

Parameter

Value

Description

compatible

"nxp,pcf85263a"

Enables the rtc_pcf85263a.c driver and associates it with the device.

reg

<0x51>

LPS22HH slave address on the I2C bus, which will be used by the driver to communicate with the RTC.

alarms-count

<2>

Number of alarms supported by RTC device. The number of alarms defaults to 0, which indicates that the RTC has no alarms.

inta-mode

<(INTx_ALARM1_IE | INTx_LEVEL_MODE)>

RTC INTA pin output mode.

inta-gpios

<&gpio0 5 GPIO_ACTIVE_HIGH>

Host SoC GPIO, that will be used for RTC interrupts.

3. Using RTC PCF85263A in User Application

3.1. PCF85263A C-Binding API

The Customized Asset Tracker v2 application makes use of the Zephyr RTC API and implements the following C-binding helper API to control the PCF85263A real-time clock:

Function

Description

Comments

int rtc_app_set_time(struct rtc_time *rtctime);

Set RTC time.

rtctime - The pointer to the time to set.

Returns 0 if successful, negative errno code if failure.

int rtc_app_get_time(struct rtc_time *rtctime);

Get current RTC time.

rtctime - The pointer to store current RTC time.

Returns 0 if successful, negative errno code if failure.

int rtc_app_alarm_get_supported_fields(uint16_t *mask);

Get alarm fields supported by RTC.

mask - The pointer to store supported alarm mask fields.

Returns 0 if successful, negative errno code if failure.

int rtc_app_get_alarm_time(uint16_t *mask, struct rtc_time *rtctime);

Get RTC alarm time.

mask - The pointer to store the enabled alarm mask fields.

rtctime - The pointer to store current alarm RTC time.

Returns 0 if successful, negative errno code if failure.

int rtc_app_set_alarm_time(uint16_t mask, const struct rtc_time *rtctime);

Set RTC alarm time.

mask - RTC alarm mask.

rtctime - The pointer to the time to set.

Returns 0 if successful, negative errno code if failure.

int rtc_app_set_alarm_callback(rtc_alarm_callback callback, void *user_data);

Set RTC alarm callback.

callback - RTC alarm callback.

user_data - Data to pass to the callback.

Returns 0 if successful, negative errno code if failure.

3.2. PCF85263A Shell Commands

The Customized Asset Tracker v2 application provides a set of Zephyr shell commands for PCF85263A RTC, defined in rtc_app_shell.c:

Command

Parameters

Comments

rtc_app set

<YYYY-MM-DDThh:mm:ss> | <YYYY-MM-DD> | <hh:mm:ss>

Set RTC time

rtc_app get

 

Get current RTC time

rtc_app set_alarm

<hh:mm:ss>

Set alarm time and callback

rtc_app get_alarm

 

Get alarm time

rtc_app clear_alarm

 

Disable RTC alarm

4. Validating RTC PCF85263A Operations

  1. Put Jumpers on the JP1 and JP2 headers on the SOM-NRF9151-BSB board.

  2. Plug the battery into P3 on the SOM-NRF9151-BSB board.

  3. Power up the board from the USB Type-C.

  4. From the serial console, set the RTC time and date to the current wall time:

    uart:~$ rtc_app set 2025-02-27T17:27:43
  5. Validate that the RTC returns correct wall time:

    uart:~$ rtc_app get2025-02-27T17:28:02
  6. From the serial console set the RTC alarm for 15 minutes from now:

    uart:~$ rtc_app set_alarm -1:43:-1 Setting alarm time: 00:43:00 Alarm mask: hour: not set min: set sec: not set

Use negative values (-1) to ignore certain fields (hours, minutes, seconds) when setting the RTC alarm from Zephyr shell.

e.g. the rtc_app set_alarm -1:52:36 command doesn’t set hours for the RTC alarm, and the alarm will be triggered every hour at 52:36.

  1. Remove JP2 jumper from SOM-NRF9151 board. Let the board sit unpowered for at least 15 minutes.

  2. Wait for the RTC alarm to trigger the trigger the interrupt and verify that the alarm handler prints out correct time to the console:

    [15:15:18.459,136] <inf> rtc_app: Alarm callback for dev: pcf85263a@51, alarm ID: 0 [15:15:18.459,167] <inf> rtc_app: Current time: 2025-02-27T17:43:00
  3. Return the JP2 jumper to the SOM-NRF9151-BSB board.

  4. Validate that the RTC time and date continue to match the current wall time:

    uart:~$ rtc_app get 2025-02-27T17:43:25

Related content