This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541: Battery Level Status

Part Number: CC2541

Hi All, 

I'm working with CC2541 with BLE stack 1.5.1.1 where I need to show the battery percentage on my APP. I am using 3.7V 6000 mAh battery. After adding the code for ADC Values. I'm getting 64 value in return nothing else. 

I'm sure something is wrong here and I need help on this.

Regards,

Yatin Baluja 

  • Hi,

    I have assigned an expert to comment.

    Regards,
    Michael

  • okay thanks Michael. 

    I have a question. Is it possible to create stopwatch kinda thing in CC2541 ?? Like I want to create the timer inside the firmware using CC2541 which will act as a stopwatch. If I pause the timer it will pause and when I resume it, it will resume where it got paused.

    Regards,

    Yatin Baluja

  • Hello Yatin,

    1)

    First you need to verify correct ADC setup. Perhaps you can also test with the isolated ADC example to make sure you configured it correctly:

    https://www.ti.com/lit/zip/swrc257 

    Also maybe this thread might be of use:

    https://e2e.ti.com/support/wireless-connectivity/bluetooth/f/538/p/910759/3366592

    2) Yes, it should be possible to create something similar to a stopwatch. Maybe you can find inspiration from 

    16  TimeApp- BLE Watch  and use osal_timers.c (osal_start_timerEx/osal_stop_timerEx). You can also try to utilize the HW timer directly.

  • Already try to help you in your another duplicate post.

  • Yes, YK Chen

    There is few things I want to confirm. 

    Firstly, Adding 8th Bluetooth Characteristics, I am getting "too many initializers values".

    Secondly, I have one push button, so pressing that button for 2 seconds - device will be ON and after pressing that button again one led will be ON and pressing again that button second LED will be ON. So, how to implement that as I already tried but not sure it is correct or not.

    //***************************************************
    if (events & SBP_KEY_EVT)
    {
    if (KEY==0)
    {
    key_dptr++;
    if((key_dptr>=2) && (device_start_stop == DEVICE_STOP))
    {
    if(KEY == KEY_LOW)
    {
    POWER=1;
    key_dptr=0;
    device_start_stop = DEVICE_START;
    LED=1;
    First_Part(0,0);
    Second_Part(0,0);
    Third_Part(0,0);
    Fourth_Part(0,0);
    Fifth_Part(0,0);
    //osal_stop_timerEx( simpleBLEPeripheral_TaskID, SBP_KEY_EVT);
    osal_set_event( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT );
    return (events ^ SBP_KEY_EVT);
    }
    }

    else if((key_dptr>=1)&& (device_start_stop == DEVICE_STOP))
    {
    if(KEY == KEY_LOW)
    {
    key_dptr=0;
    device_start_stop = DEVICE_START;
    First_Part(1,0);
    Second_Part(1,0);
    Third_Part(1,0);
    Fourth_Part(1,0);
    Fifth_Part(1,0);
    osal_stop_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT);
    // osal_stop_timerEx( simpleBLEPeripheral_TaskID, SBP_KEY_EVT);
    return (events ^ SBP_KEY_EVT);
    }
    }

    else if((key_dptr>=1)&& (device_start_stop == DEVICE_STOP))
    {
    if(KEY == KEY_LOW)
    {
    key_dptr=0;
    device_start_stop = DEVICE_START;
    First_Part(0,1);
    Second_Part(0,1);
    Third_Part(0,1);
    Fourth_Part(0,1);
    Fifth_Part(0,1);
    osal_stop_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT);
    //osal_stop_timerEx( simpleBLEPeripheral_TaskID, SBP_KEY_EVT);
    return (events ^ SBP_KEY_EVT);
    }
    }
    else if((key_dptr>=1)&& (device_start_stop == DEVICE_START))
    {
    if(KEY == KEY_LOW)
    {
    key_dptr=0;
    device_start_stop = DEVICE_STOP;
    First_Part(0,0);
    Second_Part(0,0);
    Third_Part(0,0);
    Fourth_Part(0,0);
    Fifth_Part(0,0);
    POWER=0;
    osal_stop_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT);
    //osal_stop_timerEx( simpleBLEPeripheral_TaskID, SBP_KEY_EVT);
    return (events ^ SBP_KEY_EVT);
    }
    }
    }
    else
    {
    osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_KEY_EVT, SBP_KEY_EVT_PERIOD );
    return (events ^ SBP_KEY_EVT);
    }
    }
    //Periodic Event
    if ( events & SBP_PERIODIC_EVT )
    {
    if(IN_5V == 1) // if battery charging is going ON
    {
    LED =1;
    First_Part(0,0);
    Second_Part(0,0);
    Third_Part(0,0);
    Fourth_Part(0,0);
    Fifth_Part(0,0);
    }
    ADC_handle();
    osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
    return (events ^ SBP_PERIODIC_EVT);
    ADC_handle();
    IEN2 |= 0x10;

    if(IN_5V == 0)
    {
    POWER =1;
    LED =0;

    }
    osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
    return (events ^ SBP_PERIODIC_EVT);
    }

    // Discard unknown events
    return 0;
    }

     

  • 1. There must be something wrong in your code to cause "too many initializers values".

    2. After button press is detected, you can start a timer event to check button GPI pin and count how long it holds.

  • 1. For the first part, I followed the similar pattern as for other 7 characteristics.

    2. Do you have any reference link or code to check that 

    Regards,

    Yatin Baluja  

  • In the past you said to increase the array size but I'm not sure where I need to increase the array size.. Regarding the first point

    Regards,

    Yatin Baluja 

  • I have told you how to solve this issue in e2e.ti.com/.../3391966