5 Replies Latest reply on Jul 19, 2020 11:27 PM by YiZ_31

    FX3/CX3  定时器中断怎么实现?

    YaXi_4492421

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

      我之前从资料上看到说,可以通过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 中断,我的代码是否有问题啊?

      // 非常期待老师的回答