cancel
Showing results for 
Search instead for 
Did you mean: 

USB Superspeed Peripherals

YaXi_4492421
New Contributor II

我想实现一个中断定时器,请问怎么实现?

我之前从资料上看到说,可以通过GPIO中断实现,但是并没能产生中断,下面是我的代码:

// 初始化代码:

CyU3PGpioClock_t gpioClock;

CyU3PGpioComplexConfig_t gpioConfig;

CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;

/* Init the GPIO module */

gpioClock.fastClkDiv = 2;

gpioClock.slowClkDiv = 0;

gpioClock.simpleDiv = CY_U3P_GPIO_SIMPLE_DIV_BY_2;

gpioClock.clkSrc = CY_U3P_SYS_CLK;

gpioClock.halfDiv = 0;

apiRetStatus = CyU3PGpioInit(&gpioClock, CyFxGpioIntrCb);

CyU3PGpioComplexConfig_t gpioComplexConfig;

gpioComplexConfig.outValue = CyFalse;

gpioComplexConfig.inputEn = CyTrue;

gpioComplexConfig.driveLowEn = CyFalse;

gpioComplexConfig.driveHighEn = CyFalse;

gpioComplexConfig.pinMode = CY_U3P_GPIO_MODE_STATIC;

gpioComplexConfig.intrMode = CY_U3P_GPIO_INTR_TIMER_THRES;

gpioComplexConfig.timerMode = CY_U3P_GPIO_TIMER_POS_EDGE;

gpioComplexConfig.timer = 0;

gpioComplexConfig.period =  0x00000001;   // Reset after each interrupt

gpioComplexConfig.threshold = 0x00000001; //Generate interrupt every 125us

apiRetStatus = CyU3PGpioSetComplexConfig(GPIO_TIMER, &gpioComplexConfig);

if (apiRetStatus != CY_U3P_SUCCESS)

{

vJackyTestPrintErr("CyU3PGpioSetComplexConfig failed: %d\n",apiRetStatus);

}

/*****************************************************/

// 中断回调函数:

/****************************************************/

void CyFxGpioIntrCb (

uint8_t gpioId /* Indicates the pin that triggered the interrupt */

)

{

if(GPIO_TIMER == gpioId)

{

dwTimeCountNow++;

if(dwTimeCountNow>TIME_COUNT_MAX)

{

dwTimeCountNow = 0;

}

}

}

/*******************************************/

// 请问如何才能产生timer 中断?如果GPIO可以做timer 中断,我的代码是否有问题啊?

// 非常期待老师的回答

0 Likes
Reply
1 Solution
YiZ_31
Moderator
Moderator

给你贴一下我的配置

    gpioConfig.outValue = CyFalse;

    gpioConfig.inputEn = CyTrue;

    gpioConfig.driveLowEn = CyFalse;

    gpioConfig.driveHighEn = CyFalse;

    gpioConfig.pinMode = CY_U3P_GPIO_MODE_STATIC;

    gpioConfig.intrMode = CY_U3P_GPIO_INTR_TIMER_THRES;

    gpioConfig.timerMode = CY_U3P_GPIO_TIMER_POS_EDGE;

    gpioConfig.timer = 0;

    gpioConfig.period = 0x00000001;

    gpioConfig.threshold = 0x00000001;

    apiRetStatus = CyU3PGpioSetComplexConfig(50, &gpioConfig);

    if (apiRetStatus != CY_U3P_SUCCESS)

    {

        CyU3PDebugPrint (4, "CyU3PGpioSetComplexConfig failed, error code = %d\n",

                apiRetStatus);

        CyFxAppErrorHandler(apiRetStatus);

    }

void GPIO_Interrupt(uint8_t gpioId)

{

      CyU3PGpioSetValue(21, CyTrue);

      CyU3PGpioSetValue(21, CyFalse);

}

View solution in original post

0 Likes
Reply
5 Replies
YiZ_31
Moderator
Moderator

我测过了你这样配置可以产生中断啊,这个GPIO脚需要有信号输入。

0 Likes
Reply
YaXi_4492421
New Contributor II

我直接找的PWM使用了一个GPIO的PWM输入,PWM的频率设置为100000hz,但是没有产生时钟中断啊

0 Likes
Reply
YiZ_31
Moderator
Moderator

给你贴一下我的配置

    gpioConfig.outValue = CyFalse;

    gpioConfig.inputEn = CyTrue;

    gpioConfig.driveLowEn = CyFalse;

    gpioConfig.driveHighEn = CyFalse;

    gpioConfig.pinMode = CY_U3P_GPIO_MODE_STATIC;

    gpioConfig.intrMode = CY_U3P_GPIO_INTR_TIMER_THRES;

    gpioConfig.timerMode = CY_U3P_GPIO_TIMER_POS_EDGE;

    gpioConfig.timer = 0;

    gpioConfig.period = 0x00000001;

    gpioConfig.threshold = 0x00000001;

    apiRetStatus = CyU3PGpioSetComplexConfig(50, &gpioConfig);

    if (apiRetStatus != CY_U3P_SUCCESS)

    {

        CyU3PDebugPrint (4, "CyU3PGpioSetComplexConfig failed, error code = %d\n",

                apiRetStatus);

        CyFxAppErrorHandler(apiRetStatus);

    }

void GPIO_Interrupt(uint8_t gpioId)

{

      CyU3PGpioSetValue(21, CyTrue);

      CyU3PGpioSetValue(21, CyFalse);

}

View solution in original post

0 Likes
Reply
YaXi_4492421
New Contributor II

您的GPIO的输入使用的是什么输入?频率是多少?

0 Likes
Reply
YiZ_31
Moderator
Moderator

8kHz的方波

0 Likes
Reply