| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Heart Rate Monitor
This information applies to the following SoftDevices: S212, S332

This module implements the Heart Rate Monitor ANT+ device profile. The API for this module is available here: Heart Rate Monitor profile

During initialization, the module configures the selected channel and resets the profile data.

# Compile time configuration options

The module traces profile-specific information to UART using the logger.

The following configuration options are available at compile time to assist in the development phase of the HRM Receiver implementation:

- TRACE_HRM_GENERAL_ENABLE: Output page number of the current page.
- TRACE_HRM_PAGE_0_ENABLE: Output page 0 data.
- TRACE_HRM_PAGE_1_ENABLE: Output page 1 data.
- TRACE_HRM_PAGE_2_ENABLE: Output page 2 data.
- TRACE_HRM_PAGE_3_ENABLE: Output page 3 data.
- TRACE_HRM_PAGE_4_ENABLE: Output page 4 data.

The above macros must be defined on the project settings level.

# HRM Receiver

The following code snippets show how to initialize the HRM Receiver:

HRM_DISP_CHANNEL_CONFIG_DEF(m_ant_hrm,
HRM_CHANNEL_NUMBER,
WILDCARD_TRANSMISSION_TYPE,
WILDCARD_DEVICE_NUMBER,
ANTPLUS_NETWORK_NUMBER,
HRM_MSG_PERIOD_4Hz);
ant_hrm_profile_t m_ant_hrm;
uint32_t err_code;
err_code = ant_hrm_disp_init(&m_ant_hrm,
HRM_DISP_CHANNEL_CONFIG(m_ant_hrm),
ant_hrm_evt_handler);
APP_ERROR_CHECK(err_code);
err_code = ant_hrm_disp_open(&m_ant_hrm);
APP_ERROR_CHECK(err_code);
err_code = ant_state_indicator_channel_opened();
APP_ERROR_CHECK(err_code);

After opening the profile instance channel, the module keeps the profile structure updated.

Three different message periods are supported:

- HRM_MSG_PERIOD_4Hz
- HRM_MSG_PERIOD_2Hz
- HRM_MSG_PERIOD_1Hz

The sample application that uses the Heart Rate Monitor Profile is available here: Receiver

# HRM Transmitter

The following code snippets show how to initialize the HRM Transmitter:

void ant_hrm_evt_handler(ant_hrm_profile_t * p_profile, ant_hrm_evt_t event);
HRM_SENS_CHANNEL_CONFIG_DEF(m_ant_hrm,
HRM_CHANNEL_NUMBER,
CHAN_ID_TRANS_TYPE,
CHAN_ID_DEV_NUM,
ANTPLUS_NETWORK_NUMBER);
HRM_SENS_PROFILE_CONFIG_DEF(m_ant_hrm,
true,
ANT_HRM_PAGE_0,
ant_hrm_evt_handler);
static ant_hrm_profile_t m_ant_hrm;
uint32_t err_code;
err_code = ant_hrm_sens_init(&m_ant_hrm,
HRM_SENS_CHANNEL_CONFIG(m_ant_hrm),
HRM_SENS_PROFILE_CONFIG(m_ant_hrm));
APP_ERROR_CHECK(err_code);
m_ant_hrm.HRM_PROFILE_manuf_id = HRM_MFG_ID;
m_ant_hrm.HRM_PROFILE_serial_num = HRM_SERIAL_NUMBER;
m_ant_hrm.HRM_PROFILE_hw_version = HRM_HW_VERSION;
m_ant_hrm.HRM_PROFILE_sw_version = HRM_SW_VERSION;
m_ant_hrm.HRM_PROFILE_model_num = HRM_MODEL_NUMBER;
err_code = ant_hrm_sens_open(&m_ant_hrm);
APP_ERROR_CHECK(err_code);
err_code = ant_state_indicator_channel_opened();
APP_ERROR_CHECK(err_code);

After opening the profile instance channel, the module broadcasts the data from the profile structure. The user application should keep this structure updated. Users can configure which main data page is used (page 0 or 4) and whether page 1 is present.

The sample application that uses the Heart Rate Monitor Profile is available here: Transmitter

Note
  The application must propagate ANT stack events to the ANT Heart Rate Monitor module by calling ant_hrm_tx_evt_handle() or ant_hrm_rx_evt_handle() from the ant_event_handler callback.

Warning
  The ant_event_handler is called from an interrupt. Therefore, the profile structure is changed asynchronously.