我的捕获中断好像进不来,不知道那个环节少了什么?
是否有捕获中断的参考例程?
#include <ti/drivers/timer/GPTimerCC26XX.h>
#include <ti/drivers/gpio/GPIOCC26XX.h>
#include <ti/drivers/pin/pincc26xx.h>
#include "Board.h"
#define TIMER_PERIOD 1000000 // 定时器周期,单位为微秒,这里设置为 1 秒
#define TIMER_WIDTH GPT_CONFIG_32BIT
GPTimerCC26XX_Handle hTimer; // 声明为全局变量
GPIO_PinConfig capturePinConfigs[] = {
/* ant2_capture */
GPIOCC26XX_DIO_24 | GPIO_CFG_IN_NOPULL | GPIO_CFG_IN_INT_BOTH_EDGES,
};
void captureCallback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
{
uint32_t captureValue = GPTimerCC26XX_getValue(hTimer);
// 在这里处理捕获的脉宽值(captureValue)
// 根据需要执行其他操作
}
void capture_Init(void)
{
GPTimerCC26XX_Params timerParams;
GPTimerCC26XX_Params_init(&timerParams);
timerParams.width = GPT_CONFIG_16BIT;
timerParams.mode = GPT_MODE_EDGE_COUNT;
timerParams.direction = GPTimerCC26XX_DIRECTION_UP;
timerParams.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
hTimer = GPTimerCC26XX_open(Board_TIMER1, &timerParams);
if (hTimer == NULL)
{
// 处理定时器打开失败的情况
while (1)
;
}
PIN_State capturePinState;
PIN_Handle capturePinHandle;
capturePinHandle = PIN_open(&capturePinState, capturePinConfigs);
// 配置为捕获模式
GPTimerCC26XX_PinMux pinMux = GPTimerCC26XX_getPinMux(hTimer);
PINCC26XX_setMux(capturePinHandle, PIN_ID(GPIOCC26XX_DIO_24), pinMux);
GPTimerCC26XX_setCaptureEdge(hTimer, GPTimerCC26XX_BOTH_EDGES);
// 注册捕获中断回调函数
GPTimerCC26XX_registerInterrupt(hTimer, captureCallback, GPT_INT_CAPTURE);
// 设置定时器周期
GPTimerCC26XX_setLoadValue(hTimer, TIMER_PERIOD);
// 启动定时器
GPTimerCC26XX_start(hTimer);
}