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 |
---|---|---|
|
| Enables the |
|
| LPS22HH slave address on the I2C bus, which will be used by the driver to communicate with the RTC. |
|
| Number of alarms supported by RTC device. The number of alarms defaults to 0, which indicates that the RTC has no alarms. |
|
| RTC INTA pin output mode. |
|
| 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 |
| Set RTC time. |
Returns 0 if successful, negative errno code if failure. |
| Get current RTC time. |
Returns 0 if successful, negative errno code if failure. |
| Get alarm fields supported by RTC. |
Returns 0 if successful, negative errno code if failure. |
| Get RTC alarm time. |
Returns 0 if successful, negative errno code if failure. |
| Set RTC alarm time. |
Returns 0 if successful, negative errno code if failure. |
| Set RTC alarm 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 |
|
| Set RTC time |
|
| Get current RTC time |
|
| Set alarm time and callback |
|
| Get alarm time |
|
| Disable RTC alarm |
4. Validating RTC PCF85263A Operations
Put Jumpers on the JP1 and JP2 headers on the SOM-NRF9151-BSB board.
Plug the battery into P3 on the SOM-NRF9151-BSB board.
Power up the board from the USB Type-C.
From the serial console, set the RTC time and date to the current wall time:
uart:~$ rtc_app set 2025-02-27T17:27:43
Validate that the RTC returns correct wall time:
uart:~$ rtc_app get2025-02-27T17:28:02
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.
Remove JP2 jumper from SOM-NRF9151 board. Let the board sit unpowered for at least 15 minutes.
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
Return the JP2 jumper to the SOM-NRF9151-BSB board.
Validate that the RTC time and date continue to match the current wall time:
uart:~$ rtc_app get 2025-02-27T17:43:25