This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2F定时器接口

Other Parts Discussed in Thread: CC2640R2F

工程师们,你们好,我在使用CC2640R2F进行开发串口接收到数据统计,要做一个超时检测功能,在一段时间内没有接收到数据则回复一个错误,请问可以使用定时器吗?这个定时器在串口收到数据后重新装载,重新计数,请问我该使用什么接口?我看了论坛里的一些帖子,有一个GAPTimer的接口,在配置结构体的时候有一个Hwip的配置,这个接口好像不太对,麻烦解答一下,谢谢(蓝牙5.0)

  • 定时器的话是用GPTimer,使用方法请参考:C:\TI\simplelink_cc2640r2_sdk_3_30_00_20\docs\tidrivers\doxygen\html\_g_p_timer_c_c26_x_x_8h.html
  • GPTimerCC26XX_Handle hTimer;

    static GPTimerCC26XX_Value ReloadValue = 0; //这个值用来重装

    void timerCallback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
    //触发中断事件,向串口打印完成并关闭定时器
    {
    UART_Handle MyUart = GetUartHandle();
    UART_write(MyUart, "Finish", 6);
    GPTimerCC26XX_stop(hTimer);
    }

    void UartTimeOutTimer_Start(void) //开启定时器
    {
    GPTimerCC26XX_start(hTimer);
    }

    void UartTimeOutTimer_Init(void) //定时器初始化
    {
    GPTimerCC26XX_Params params;
    GPTimerCC26XX_Params_init(&params);
    params.width = GPT_CONFIG_16BIT; //16bit width timer
    params.mode = GPT_MODE_PERIODIC; //Period timer
    params.direction = GPTimerCC26XX_DIRECTION_UP; //Timer's direction up
    params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF; //No debug stall mode
    while(1)
    {
    hTimer = GPTimerCC26XX_open(CC2640R2_LAUNCHXL_GPTIMER0, &params); //Open timer
    if(hTimer == NULL) {
    continue; //If open failed, retry again
    }
    else
    break;
    }
    Types_FreqHz freq;
    BIOS_getCpuFreq(&freq);
    ReloadValue = freq.lo - 1; //47999999,这里为其赋上期望值

    GPTimerCC26XX_setLoadValue(hTimer, ReloadValue);
    GPTimerCC26XX_registerInterrupt(hTimer, timerCallback, GPT_INT_TIMEOUT);
    }

    void UartTimeOutTimer_ReloadValue(void) //定时时间重置
    {
    GPTimerCC26XX_setLoadValue(hTimer, ReloadValue);
    }

    您好,我的代码定时时间不对(我期望的预设值是1s),我找了很久,找不到问题所在,另外,定时器重装直接用GPTimerCC26XX_setLoadValue接口可以吗?
  • 位宽写错了,定时器重装直接用GPTimerCC26XX_setLoadValue接口可以吗?
  • GPTimerCC26XX_setLoadValue 的设置请参考这边类似帖:e2e.ti.com/.../2234068

  • 谢谢,搞定了(之后的人如果看到上面的代码,要实现定时器类似看门狗的代码,请将上面代码中的位宽和定时器的方向改为GPT_CONFIG_32BIT,GPTimerCC26XX_DIRECTION_DOWN)
  • 感谢提供反馈
  • 您好,我已将这份代码(修改后)放到simple_peripheral中,并能正常运行,连接移植前simple_central后正常收发,但是我将这份代码移植到simple_central的时候(移植过程中在main中增加了定时器初始化,与simple_peripheral相同),出现了如下问题:

    simple_central串口在接收数据后,能够通过事件到达APP(simple_central和simple_peripheral已经连接完成,simple_peripheral向simple_central发送数据正常),但是simple_central此时却无法将数据成功下发到simple_peripheral。

    调试时发现如下代码中返回的status并不是SUCCESS,并且在之后串口无法工作,协议栈其他部分正常(simple_peripheral发送数据到simple_central时返回值是SUCCESS)
    //Send message
    status = GATT_WriteCharValue(dstConnHandle, &req, selfEntity);
    if ( status != SUCCESS )
    {
    GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
    }

    请问这个问题的原因是什么?能提供我一个大概问题的方向吗?