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.

RTOS: How generate the Battery value with PinInterrupt CC1310

Tool/software: TI-RTOS

Hi, I'm trying to study all the registers and examples that TIRTOS offers. I'm trying to generate the battery value by pressing two buttons. That is, if the battery level is greater than 3.3V, turn on the green LED if the red LED is lower. I added the appropriate library for the battery, but something is wrong. Where am I wrong?

#include <unistd.h>

/* Driver Header files */
#include <ti/drivers/PIN.h>
#include <ti/devices/cc13x0/driverlib/aon_batmon.h

/* Example/Board Header files */
#include "Board.h"

/* Pin driver handles */
static PIN_Handle buttonPinHandle;
static PIN_Handle ledPinHandle;

/* Global memory storage for a PIN_Config table */
static PIN_State buttonPinState;
static PIN_State ledPinState;

/*
 * Initial LED pin configuration table
 *   - LEDs Board_PIN_LED0 is on.
 *   - LEDs Board_PIN_LED1 is off.
 */
PIN_Config ledPinTable[] = {
    Board_PIN_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW  | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    PIN_TERMINATE
};

/*
 * Application button pin configuration table:
 *   - Buttons interrupts are configured to trigger on falling edge.
 */
PIN_Config buttonPinTable[] = {
    Board_PIN_BUTTON0  | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
    Board_PIN_BUTTON1  | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
    PIN_TERMINATE
};

/*
 *  ======== buttonCallbackFxn ========
 *  Pin interrupt Callback function board buttons configured in the pinTable.
 *  If Board_PIN_LED3 and Board_PIN_LED4 are defined, then we'll add them to the PIN
 *  callback function.
 */
void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {
   Bat = AONBatMonBatteryVoltageGet()*0.00389;

    /* Debounce logic, only toggle if the button is still pushed (low) */
    CPUdelay(8000*50);
    if (!PIN_getInputValue(pinId)) {
       if(!PIN_getInputValue(Board_PIN_BUTTON0) && !PIN_getInputValue(Board_PIN_BUTTON1)){
           if(Bat>3300){
              PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, 1);
              _delay_cycles(2*240000000*1000);
              PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, 0);
            }
           if(Bat<3200){
              PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, 1);
              _delay_cycles(2*240000000*1000);
              PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, 0);
            }
     }
    }
}

/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{

    /* Open LED pins */
    ledPinHandle = PIN_open(&ledPinState, ledPinTable);
    if(!ledPinHandle) {
        /* Error initializing board LED pins */
        while(1);
    }

    buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
    if(!buttonPinHandle) {
        /* Error initializing button pins */
        while(1);
    }

    /* Setup callback for button pins */
    if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) {
        /* Error registering button callback function */
        while(1);
    }

    /* Loop forever */
    while(1) {
        sleep(1000);
    }
}

Thanks :)