KW40z "heart rate sensor" BLE automatically connection problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KW40z "heart rate sensor" BLE automatically connection problem

1,095 Views
chaosmagin
Contributor I

Hello!!

I am programming board KW40Z and implementing some sample code.
In the "heart rate sensor" example, the bluetooth acts as a slaver.

However, while the ble connection is interrupted, it requires to press button SW4 to enable ble listen for new connection.

Can anyone advise me what to do in the code to let ble keep listening for new connection "automatically" as the previous connection is interrupted without pressing button SW4?

Thank you very much!

1 Reply

692 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Chao Smagin

"heart rate sensor" example is set up to use Power Down Mode, and the applications is configured to go to sleep when a event disconnect occurred and not start the BleApp.

If you check the app.c file, in the BLE connection callback you can find the disconnect event defined as:

        case gConnEvtDisconnected_c:
        {
            /* Unsubscribe client */
            Bas_Unsubscribe();
            Hrs_Unsubscribe();

            mPeerDeviceId = gInvalidDeviceId_c;
            
            TMR_StopTimer(mMeasurementTimerId);
            TMR_StopTimer(mBatteryMeasurementTimerId);            

#if (cPWR_UsePowerDownMode)            
            /* UI */
            Led1Off();
            
            /* Go to sleep */
            PWR_ChangeDeepSleepMode(3); /* MCU=LLS3, LL=IDLE, wakeup on swithes/LL */
            PWR_SetDeepSleepTimeInMs(cPWR_DeepSleepDurationMs);
            PWR_AllowDeviceToSleep();
#else
            if (pConnectionEvent->eventData.disconnectedEvent.reason == gHciConnectionTimeout_c)
            {
                /* Link loss detected*/
                BleApp_Start();
            }
            else
            {
              /* Connection was terminated by peer or application */
                BleApp_Start();
            }
#endif               
        }
        break;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

So you here have two options, and it depends in your application and if you want available the Power down mode.

1. You can disable Power Down functionality; in app_preinclude.h you can find the Framework Configuration, and here you can find the Macro definition:

/* Enable/Disable PowerDown functionality in PwrLib */
#define cPWR_UsePowerDownMode           1‍‍

So you can change this to "0", and when the disconnect event occurs it will go to the BleApp_Start() that keep the device in advertising.

2. you can comment this part as:

        case gConnEvtDisconnected_c:
        {
            /* Unsubscribe client */
            Bas_Unsubscribe();
            Hrs_Unsubscribe();

            mPeerDeviceId = gInvalidDeviceId_c;
            
            TMR_StopTimer(mMeasurementTimerId);
            TMR_StopTimer(mBatteryMeasurementTimerId);            

//#if (cPWR_UsePowerDownMode)            
//            /* UI */
//            Led1Off();
//            
//            /* Go to sleep */
//            PWR_ChangeDeepSleepMode(3); /* MCU=LLS3, LL=IDLE, wakeup on swithes/LL */
//            PWR_SetDeepSleepTimeInMs(cPWR_DeepSleepDurationMs);
//            PWR_AllowDeviceToSleep();
//#else
            if (pConnectionEvent->eventData.disconnectedEvent.reason == gHciConnectionTimeout_c)
            {
                /* Link loss detected*/
                BleApp_Start();
            }
            else
            {
              /* Connection was terminated by peer or application */
                BleApp_Start();
            }
//#endif               
        }
        break;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

so you still have available the sleep feature, but just when this specific event occurs (disconnect event), the device will  advertise instead of go to sleep.

Hope this information could help.
Have a great day,
Jorge Alcala

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------