fingertouch 发表于 2015-4-17 15:38:39

CSR8670 ADK3.5中自带的button(part1)实例运行无法检测button事件,求原因

小弟我安装ADK3.5后,运行目录下的apps\tutorials\buttons\part1实例,可以运行,但是检测不到button事件,各位高手帮忙看看,附上代码:/* Copyright Cambridge Silicon Radio Limited 2008-2014 */
/* Part of BlueLab-6.5.2-Release */

/*
* Buttons Tutorial: Part 1 - PIO messages
*/

#include <pio.h>
#include <stdio.h>
#include <message.h>

#define BUTTON_A      (1 << 0)      /* PIO0 is BUTTON_A */
#define BUTTON_B      (1 << 1)      /* PIO1 is BUTTON_B */
#define BUTTON_C      (1 << 2)      /* PIO2 is BUTTON_C */
#define BUTTON_D      (1 << 3)      /* PIO3 is BUTTON_D */

typedef struct
{
    TaskData    task;   /* task is required for messages to be delivered */
} appState;

appState app;

/* Function prototypes */
static void app_handler(Task task, MessageId id, Message message);
static void handle_pio(Task task, MessagePioChanged *pio);

int main(void)
{
    /* Set app_handler() function to handle app's messages */
    app.task.handler = app_handler;

    /* Set app task to receive PIO messages */
    MessagePioTask(&app.task);

    /* Setup PIO interrupt messages */
    PioDebounce32(BUTTON_A | BUTTON_B,/* PIO pins we are interested in */
                2, 20);               /* 2 reads and 20ms between them */

    MessageLoop();
   
    return 0;
}

static void app_handler(Task task, MessageId id, Message message)
{
    switch (id)
    {
    case MESSAGE_PIO_CHANGED:
      handle_pio(task, (MessagePioChanged*)message);
      break;

    default:
      printf("Unhandled message 0x%x\n", id);
    }
}

static void handle_pio(Task task, MessagePioChanged *pio)
{
    if (pio->state & BUTTON_A) printf("Button A pressed\n");
    if (pio->state & BUTTON_B) printf("Button B pressed\n");   
}

/* End-of-File */



JasonChing 发表于 2017-5-12 07:37:44

你的按键不是连接在PIO0,1,2,3上吧,你看一下你的电路图,把对应的pio改一下应该可以
#define BUTTON_A      (1 << 0)      /* PIO0 is BUTTON_A */
#define BUTTON_B      (1 << 1)      /* PIO1 is BUTTON_B */
#define BUTTON_C      (1 << 2)      /* PIO2 is BUTTON_C */
#define BUTTON_D      (1 << 3)      /* PIO3 is BUTTON_D */
就是这个

页: [1]
查看完整版本: CSR8670 ADK3.5中自带的button(part1)实例运行无法检测button事件,求原因