微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > CC2650 GPIO 中断问题?

CC2650 GPIO 中断问题?

时间:10-02 整理:3721RD 点击:

最近学习CC2650,参考PIN.h中的事例,自己改写了一个按键输入中断任务,代码如下:

#include <string.h>
#include <xdc/std.h>

#include "ioservice.h"

#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Queue.h> // Needed for util.h

#include "Board.h"
#include "peripheral.h"
#include "sensor.h"
#include "util.h"
#include <ti/drivers/pin/PINCC26xx.h>
#include <ti/drivers/PIN.h>

#include "Max_led.h"

// Max_led
#define Max_Led_Red    IOID_6
#define Max_Led_Green    IOID_7

// Max_Button
#define Max_BTN_1    IOID_13
#define Max_BTN_2    IOID_14

#define ST_TASK_PRIORITY                      1

/* -----------------------------------------------------------------------------
*                           Local variables
* ------------------------------------------------------------------------------
*/
static PIN_Config Max_Pin_led[] =
{
    Max_Led_Red | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN,       /* Max_Led_Red */
    Max_Led_Green | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* Max_Led_Green */
    Max_BTN_1 | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS ,    /* Max_BTN_1 */
    Max_BTN_2 | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS ,    /* Max_BTN_2 */

    PIN_TERMINATE
};

// Pin configuration
static PIN_State Max_pinState;
static Task_Struct Max_taskStart;
uint8_t     Max_taskStartStack[512];

void Max_DoSomething();

void Max_Led_createTask(void)
{
 // Configure startup task
         Task_Params Max_taskParams;
         Task_Params_init(&Max_taskParams);
         Max_taskParams.stack = Max_taskStartStack;
        // taskParams.stackSize = ST_TASK_STACK_SIZE;
         Max_taskParams.stackSize = sizeof(Max_taskStartStack);
         Max_taskParams.priority = ST_TASK_PRIORITY;
         Task_construct(&Max_taskStart, Max_taskStartFxn, &Max_taskParams, NULL);
}

static void Max_taskStartFxn(UArg a0, UArg a1)
{
       // Get handle to this collection of pins
         if (!PIN_open(&Max_pinState, Max_Pin_led)) {
             // Handle allocation error
         }
          Max_DoSomething();
         // Before ending task, make sure to deallocate pins. They will return
         // to the default configurations provided in PIN_init()
         //PIN_close(&Max_pinState);
}


   //## Pin Interrupt ##
 /*  An example that handles pin inputs in the GPIO example above using PIN interrupts
 *  instead:*/
    // volatile variable used to communicate between callback and task
     static volatile int32_t moveDir = 0;    // <0: left, 0: stop, >0 right
 
     // Pin interrupt callback
     void Max_PinIntCb(PIN_Handle handle, PIN_Id pinId) {
         // Ignore pinId and read input from both buttons simultaneously
         uint32_t buttons = PIN_getPortInputValue(&Max_pinState);
         if (buttons&(1<<Max_BTN_1) == 0){     //红色标示的语句不知道是什么意思?可否请大牛帮忙介绍一下。
             moveDir = 1;
         } else if (buttons&(1<<Max_BTN_2) == 0) {
              moveDir = 2;
         } else if (buttons&((1<<Max_BTN_1)|(1<<Max_BTN_2))) {
             moveDir = 0;
         }
     }
 
     void Max_DoSomething() {
         // Running lights on LEDs A-B-C (left to right). Button A causes left
         // movement, button B causes right movement, both simultaneously aborts
         // and disables LED output drivers
 
         // LED initial state (A off, B off, C on). Only our outputs are affected
         moveDir = 1;    // <0: left, 0: stop, >0 right
 
         // Setup pin interrupts and register callback
         PIN_registerIntCb(&Max_pinState, Max_PinIntCb);
         PIN_setInterrupt(&Max_pinState, Max_BTN_1 | PIN_IRQ_NEGEDGE);
         PIN_setInterrupt(&Max_pinState, Max_BTN_2 | PIN_IRQ_NEGEDGE);
 
         while (moveDir) {
             // Update LEDs
             if (moveDir==1) {
                 // Left movement
                // uint32_t t = PIN_getOutputValue(Max_Led_Red);
                 PIN_setOutputValue(&Max_pinState, Max_Led_Red, 1);
                 PIN_setOutputValue(&Max_pinState, Max_Led_Green, 0);
                 //PIN_setOutputValue(&Max_pinState, Max_Led_Red, t);
             } else {
                 // Right movement
                // uint32_t t = PIN_getOutputValue(Max_Led_Green);
                 PIN_setOutputValue(&Max_pinState, Max_Led_Green, 0);
                 PIN_setOutputValue(&Max_pinState, Max_Led_Red, 1);
                // PIN_setOutputValue(&Max_pinState, Max_Led_Green, t);
             }
 
             // Sleep for 3 ms (we will likely go into standby)
             Task_sleep(3000/10);
         }
         // Disable output enable for all pins (only our pins affected)
         PIN_setPortOutputEnable(&Max_pinState, 1);
         // Disable pin interrupts
         PIN_setInterrupt(&Max_pinState, Max_BTN_1 | PIN_IRQ_DIS);
         PIN_setInterrupt(&Max_pinState, Max_BTN_2 | PIN_IRQ_DIS);
     }

测试结果:不管按BTN_1或者BTN_2按键,moveDir 值始终为0,无法进入对应中断?

请大牛帮忙看下代码,指正问题所在,谢谢!

兄弟你这问题解决了吗,我也碰到了和你一样的情况,求指点

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top