Get Battery Level without external component (CY8CPROTO-063-BLE)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MiTo_4443801
Level 1
Level 1
First like given

Hi,

I'm trying to detect the battery level of my device in order to allow or not the connection of the BLE, I've seen the BLE battery level example but I didn't understand how does it works. I have seen this:

Cy_BLE_GetBatteryLevel, Cy_BLE_GetTemperature...etc. API Ambiguity

ad I have used it in my code using the part of the example code that there is into the discussion, but it doesn't work.

Can anyone explain me how to get the battery level in a simplest way without using external resources?

thanks!

0 Likes
1 Solution

Please refer to below tips with use of Cy_BLE_GetBatteryLevel()

a. You can not pool Cy_BLE_GetBatteryLevel function in "while" loop.Those function is a non-blocking function and value is informed through 'CY_BLE_EVT_RADIO_VOLTAGE_LEVEL' event. Please add some logic to call next time only if previous completed (receive CY_BLE_EVT_RADIO_VOLTAGE_LEVEL) event.

b. the parameter comes with CY_BLE_EVT_RADIO_VOLTAGE_LEVEL event should be generic event.

case CY_BLE_EVT_RADIO_VOLTAGE_LEVEL:

{          

   cy_stc_ble_events_param_generic_t *param = (cy_stc_ble_events_param_generic_t *)eventParam;

           

    if(param->status == 0u)

    {

       DBG_PRINTF("CY_BLE_EVT_RADIO_VOLTAGE_LEVEL: %u \r\n", *(uint16 *)param->eventParams);

    }

   break;

}

c. The voltage measured through Cy_BLE_GetBatteryLevel() is VDDR_HVL, not VDDR.

Let me know if the above helps.

View solution in original post

3 Replies
ShipingW_81
Moderator
Moderator
Moderator
500 replies posted 250 solutions authored 250 replies posted

API Cy_BLE_GetBatteryLevel() occupies no any external resources, and it's work flow is pretty simple.

Could you tell how your code is going with calling the API Cy_BLE_GetBatteryLevel()? Have you ever tried the project attached in thread -

Cy_BLE_GetBatteryLevel, Cy_BLE_GetTemperature...etc. API Ambiguity

0 Likes

Yes I've tried the project but it didn't work, when I call Cy_BLE_GetBatteryLevel () I cannot connect the ble and he gives me an error

Cy_BLE_GetBatteryLevel API Error: 160004

I've found also this other thread How to get Voltage of PSOC 6 without ADC ​but I don't know how the LVD works and in which way I can recall it..

Have you any suggestions or part of code which I can refer to?

0 Likes

Please refer to below tips with use of Cy_BLE_GetBatteryLevel()

a. You can not pool Cy_BLE_GetBatteryLevel function in "while" loop.Those function is a non-blocking function and value is informed through 'CY_BLE_EVT_RADIO_VOLTAGE_LEVEL' event. Please add some logic to call next time only if previous completed (receive CY_BLE_EVT_RADIO_VOLTAGE_LEVEL) event.

b. the parameter comes with CY_BLE_EVT_RADIO_VOLTAGE_LEVEL event should be generic event.

case CY_BLE_EVT_RADIO_VOLTAGE_LEVEL:

{          

   cy_stc_ble_events_param_generic_t *param = (cy_stc_ble_events_param_generic_t *)eventParam;

           

    if(param->status == 0u)

    {

       DBG_PRINTF("CY_BLE_EVT_RADIO_VOLTAGE_LEVEL: %u \r\n", *(uint16 *)param->eventParams);

    }

   break;

}

c. The voltage measured through Cy_BLE_GetBatteryLevel() is VDDR_HVL, not VDDR.

Let me know if the above helps.