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.

CC2340R5: Need Battery Monitoring example code

Part Number: CC2340R5

Tool/software:

Hi Forum,

 I want to monitor battery level, i am looking for API docs. i see 4 files, which file i need to refer? It is confusing both files have set of different APIs.

Also, can you please share example code or how flow should be for this.

is there any to get battery level on demand (without callback)?

Regards

Vaibhav

  • Hi Vaibhav,

    Those are the Battery Monitor TI Driver source files.  You should be able to find BatteryMontior.h in the "drivers" folder of that directory.

    You're essentially going to repurpose the temperatureNotify example to support BatteryMonitor APIs.

    Here's some pseudo-code from a previous project I developed:

    #include <ti/drivers/BatteryMonitor.h>
    //...
    #define THRESHOLD_DELTA_MILLIVOLT 200
    BatteryMonitor_NotifyObj rangeNotifyObject;
    //...
    void deltaNotificationFxn(uint16_t currentVoltage,
                              uint16_t thresholdVoltage,
                              uintptr_t clientArg,
                              BatteryMonitor_NotifyObj *notifyObject) 
    {
        int_fast16_t voltageStatus;
        voltageStatus = BatteryMonitor_registerNotifyRange(notifyObject,
                                            currentVoltage + THRESHOLD_DELTA_MILLIVOLT,
                                            currentVoltage - THRESHOLD_DELTA_MILLIVOLT,
                                            deltaNotificationFxn,
                                            (uintptr_t)NULL);
        if (voltageStatus != BatteryMonitor_STATUS_SUCCESS) {
            while(1);
        }
    }
    //...
    /* Configure the Battery Monitor */
    uint16_t batVoltage;                        // Initial battery voltage level 
    
    BatteryMonitor_init();
    batVoltage = BatteryMonitor_getVoltage();
    deltaNotificationFxn(batVoltage, 0,(uintptr_t)NULL, &rangeNotifyObject);

    It is definitely possible to use BatteryMonitor_getVoltage when you need instead of using the "deltaNotificationFxn" callback.

    Regards,
    Ryan