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

  • Hi David

    Thank you for you question.

    I do not fully understand your scenario. 1) Your 5 ms timer, does it trigger a BLE transmission? 2) What is your connection interval? 3) Do you trigger DFU with the DFU service, i.e. over BLE? 4) What is your UART, is that the UART service or just receiving/sending bytes over UART?

    If you use a DFU service, there is data written into GPREGRET that is written by the DFU service. This data tells if the bootloader should start the application or stay in bootloader mode.

    For an unmodified bootloader: If the application that you have uploaded is not valid for any reason, then the device will start up in bootloader mode after power on reset. The bootloader will also read the GPREGRET register in order to know if a peer device (central device) wants to initiate bootloader mode or not. Perhaps you need to debug the bootloader code in order to know what is going on in your case.

  • hi, thanks for your reply, I think I'm not clear enough. My question should be how to get to know if BLE is connected with UART service or HRM service ? Because I have to stop a timer init when connected under UART service.

  • 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.
Related