This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Any flag to know it's under UART mode or HRM mode when BLE is connected ?

I encounter a problem to switch to DFU mode from UART when BLE is connected and one 5ms timer keeps running for heart rate sensing alg. Maybe it's the reason keeps BLE busy and missed the signal I send for switing to DFU mode for OTA the firmware. Thus, any flag or command I can use to know which mode I'm running ? i.e. if I'm under UART , then no need to run the timer and OTA should be no problem.

Thank you

Parents
  • Hi David

    When you are connected to a device that implements both UART service and a Heart Rate Service, then you can read and/or write values to characteristics that belong to either of these services. A client device can however enable independently e.g. notifications on these services in order to have the device send service messages periodically to the client. The application on the nRF51 can be notified when the client enables and disables notifications.

    If you open e.g. the ble_app_hrs example in the SDK, go to the services_init function in the main function. This function initializes all the different services in the application. You can register an event handler for e.g. the heart rate service with defining

    hrs_init.evt_handler                 = hrs_evt_handler;
    

    and then implement the handler as follows

    static void hrs_evt_handler (ble_hrs_t * p_hrs, ble_hrs_evt_t * p_evt)
    {
    		if(p_evt->evt_type == BLE_HRS_EVT_NOTIFICATION_ENABLED)
    		{
    				bsp_indication_set(BSP_INDICATE_ALERT_3);
    		}
    		else if(p_evt->evt_type == BLE_HRS_EVT_NOTIFICATION_DISABLED)
    		{
    				bsp_indication_set(BSP_INDICATE_ALERT_OFF);
    		}	
    }
    

    This will turn on LED_3 on the nRF51-DK when you enable notifications on the heart rate service from a client and turn off LED_3 when you disable the heart rate service. To try this out, do the following in i.e. Master Control Panel for Windows.

    • Connect to the device from master control panel
    • Press "discover services"
    • Press "enable services". You should see LED_3 on the nRF51-DK light up
    • Press "disable services". You should see LED_3 turn off
    • Write value 0100 to the ClientCharacteristicConfiguration (CCCD) of the heart rate service, and LED_3 should light up.
    • Write value 0000 to the ClientCharacteristicConfiguration (CCCD) of the heart rate service, and LED_3 should turn off.
Reply Children
No Data
Related