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.

CCS/CC2640R2F: How to wake up the chip ahead of time in standby mode

Part Number: CC2640R2F
Other Parts Discussed in Thread: CC2640

Tool/software: Code Composer Studio

In the example:

ti\simplelink_cc2640r2_sdk_3_30_00_20\examples\nortos\CC2640R2_LAUNCHXL\drivers\pinInterrupt,

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);
}
}

When the chip enters the external interrupt,Initialize I2C,read and write.

The program will stop in the function :cc26xxI2C_config[CC2640R2_LAUNCHXL_I2C0].fxnTablePtr->transferFxn(cc2640_I2C_Handle,&transaction);

How to deal with this problem?

Or When the interrupt operation is completed, how to make the chip no longer enter the standby mode?

  • Do you init and do I2C transfer in ISR function? If so, you shouldn’t do that. You should post an application event to application to do I2C actions.

  • thank you。

    But the chip is in the standby mode, such as sleep (100), when it enters the interrupt in 50 seconds, at this time, an application event is posted. Does the application need to wait for 100 seconds to execute?

    Can I execute the application immediately? Do not wait until the time in sleep (time) is up.

    Sorry, my English is not very good. Can you understand what I mean?

  • If you post event to application immediately, application task should process it immediately.

  • Sorry,I don't know how to do it.

    void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {
    uint32_t currVal = 0;

    /* Debounce logic, only toggle if the button is still pushed (low) */
    CPUdelay(8000*50);
    if (!PIN_getInputValue(pinId)) {
    /* Toggle LED based on the button pressed */
    i2c_read(0xae >> 1,16,bbuf, 50);                       //
    switch (pinId) {
    case Board_PIN_BUTTON0:
    currVal = PIN_getOutputValue(Board_PIN_LED0);
    PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, !currVal);
    break;
    default:
    /* Do nothing */
    break;
    }
    }
    }

    /*
    * ======== mainThread ========
    */
    void *mainThread(void *arg0)
    {
    i2c_init();
    /* 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);
    }
    }

    When  press the key, the program stops at the function :i2c_read(0xae >> 1,16,bbuf, 50).

    If i put ”i2c_read“in the main function, the chip will always be in sleep.

    Can you give a simple example according to the above code?

    Thank you.

  • I suggest you to refer to how PZ_BUTTON_DEBOUNCED_EVT works in project_zero example.

  • Sorry,I don't know how to transplant this example into nrtos, but thank you all the same.

  • I think it would be easier if you could try to explain what exactly you want to do (do you want to transfer something on I2C everytime you get an interrupt on a pin?). If we understand what you try to do, we can suggest how you can do it.

    Siri

  • Yes ,In my project, the chip works in standby mode, wakes up every 20 seconds, runs for 20ms and enters standby mode again. When I get a interrupt,I need to transmit some data through I2C in time.

    Now I put the I2C transport in the callback function, it doesn't work,Could/ Would you give me some suggestions, please?

    My project is based on the example of nortos.

  • Hi

    I would recommend that you use the nortos pinInterrupt example as a starting point, and then re-write it to use semaphores. You need to include the SemaphoreP.h file from ti/drivers/dpl and add SemaphoreP_nortos.c to the project.

    Below are some code showing how to use the semaphores to get out of sleep on pin interrupts:

    static SemaphoreP_Struct buttonSemaphore;
    static SemaphoreP_Handle buttonSemaphoreHandle;
    
    
    void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId)
    {
        /* Debounce logic, only toggle if the button is still pushed (low) */
        CPUdelay(8000*50);
        if (!PIN_getInputValue(pinId))
        {
            switch (pinId)
            {
                case Board_PIN_BUTTON0:
                    SemaphoreP_post(buttonSemaphoreHandle);
                    break;
    
                default:
                    break;
            }
        }
    }
    
    void *mainThread(void *arg0)
    {
    
        /* Initialize semaphore */
        buttonSemaphoreHandle = SemaphoreP_construct(&buttonSemaphore, 0, NULL);
    
        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, and wait for button interrupt */
            SemaphoreP_pend(buttonSemaphoreHandle, SemaphoreP_WAIT_FOREVER);
             
            /* Do i2c stuff */
        }
    }
    

    In the code above, the device will sleep forever (SemaphoreP_WAIT_FOREVER) or until an interrupt occurs and the semaphore is posted.

    The SemaphoreP_WAIT_FOREVER can be replaced by a timeout (in ClockP ticks) to wait for the semaphore to be posted.

    BR

    Siri