nRF51 SDK - S110 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Heart Rate Application for Eval Board
Sports-and-Fitness.jpg

Heart Rate Application for Evaluation Board

The Heart Rate Application is a firmware example that implements the Heart Rate profile using the Nordic nRF51822 evaluation board.

The source code and project file can be found in the <InstallFolder>\Nordic\nrf51822\Board\pca10001\s110\ble_app_hrs folder.

The application includes the three services in the Heart Rate profile:

In addition, the use of the ADC to measure the battery level is also demonstrated.

When the application starts, two timers are started which control when the heart rate value and battery level should be sent.

Heart rate measurement:

When the peer has enabled notification for heart rate, the application starts sending heart rate with a value that is average of MIN_HEART_RATE and MAX_HEART_RATE defined in main.c. When Button 0 is pressed, the heart rate is incremented by HEART_RATE_CHANGE (defined in main.c). When Button 1 is pressed, the heart rate is decremented by HEART_RATE_CHANGE. If the user presses a button more than once within the time defined by HEART_RATE_MEAS_INTERVAL (in main.c), then the heart rate shall be incremented/decremented that many times before the next notification is sent.

Note
The application will send heart rate measurement with only the Heart Rate Measurement Value field. RR-Interval is not sent. Sensor contact detection is not supported.

Battery level measurement:

When the peer has enabled notification for Battery Level, the application begins sending the battery level as notifications. Note that the measurement is made every 2 seconds. But as per the Battery Service Specification, the notification of battery level will be sent only if the it has changed.

The ADC is used to measure the battery level. Every time a new battery measurement has to be sent, a fresh measurement is made.

Note
The application will stop advertising after 180 seconds and go to system-off mode. Push the button 0 or button 1 to restart advertising.

Compiler Optimization:

This example is optimized for reduced power consumption. Therefore the default optimization level for this example application is 'Level 3', (-O3) and 'Optimize for Time', (-Otime). If the Keil debugger is needed for debugging purposes, then the optimization level should be changed to 'Level 0', (-O0) and 'Optimize for Time' should be removed in order to ease the use of the debugger.

Setup

LED assignments:

  • LED 0: Flashes at the rate of 2 flashes per second while the device is advertising

Buttons assignments:

  • Button 0: In System-Off mode: Wake-up from system-off and restart advertising. During notification: Increment the heart rate value.
  • Button 1: In System-Off mode: Wake-up from system-off, erase all bonds and restart advertising. During notification: Decrement the heart rate value.

Testing

The Heart Rate Application can be tested using the "nRF Toolbox" app, available on both iOS (Apple Store) and Android (Google Play).

It can also be tested using the Master Control Panel as follows:

  1. Compile and program the application.
  2. The LED 0 will be flashing at the rate of 2 flashes per second. This indicates the application is up and is advertising. Note: If no peer connects to this application within 180 seconds (APP_ADV_TIMEOUT_IN_SECONDS), the application will put the chip back in System-OFF mode.
  3. While the LED0 is flashing, connect to the device from Master Control Panel (the device will be advertising as 'Nordic_HRM'), then perform service discovery. Observe that the Advertising LED is off.
  4. Click the 'Enable services' button on the Master Control Panel. Observe that Heart Rate notifications are received every second. Note: Battery Level notifications will be sent by the app ONLY if the battery level changes.
  5. Press Button 0 once and see if the heart rate measurement value in the next notification received is incremented by 2.
  6. Press Button 1 once and see if the heart rate measurement value in the next notification received is decremented by 2.
  7. Press the Disconnect button in the Master Control Panel. Observe that the application is not advertising.