您尚未登录。

楼主 # 2025-03-19 08:55:21

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,405
积分: 1369.5

ml307a csdk,串口打印数和预想的不一样。

搜了下,好像用的是freertos。
在我自己建的一个任务里调用这个函数,每调用一次,sampleIndex自加一。结果用uartPrintf()打印currentAdd和sampleIndex和预想的不一样。
currentAdd和sampleIndex,都声明为全局变量。

    currentAdd += sampleIndex;      //暂时这样计数显示,需要改
    uartPrintf("sampleIndex:%d ", sampleIndex);
    uartPrintf("currentAdd:%d ", currentAdd);
    uartPrintf("sampleIndex:%d, currentAdd:%d ", sampleIndex, currentAdd);
    uartPrintf("sampleIndex:%d ", sampleIndex);
    uartPrintf("currentAdd:%d ", currentAdd);
    uartPrintf("currentAdd:%d, sampleIndex:%d \r\n", currentAdd, sampleIndex);
sampleIndex:0 currentAdd:0 sampleIndex:0, currentAdd:0 sampleIndex:0 currentAdd:0 currentAdd:0, sampleIndex:0 
sampleIndex:1 currentAdd:0 sampleIndex:1, currentAdd:1 sampleIndex:1 currentAdd:0 currentAdd:0, sampleIndex:1 
sampleIndex:2 currentAdd:0 sampleIndex:2, currentAdd:3 sampleIndex:2 currentAdd:0 currentAdd:0, sampleIndex:3 
sampleIndex:3 currentAdd:0 sampleIndex:3, currentAdd:6 sampleIndex:3 currentAdd:0 currentAdd:0, sampleIndex:6 
sampleIndex:4 currentAdd:0 sampleIndex:4, currentAdd:10 sampleIndex:4 currentAdd:0 currentAdd:0, sampleIndex:10 
sampleIndex:5 currentAdd:0 sampleIndex:5, currentAdd:15 sampleIndex:5 currentAdd:0 currentAdd:0, sampleIndex:15 
sampleIndex:6 currentAdd:0 sampleIndex:6, currentAdd:21 sampleIndex:6 currentAdd:0 currentAdd:0, sampleIndex:21 
sampleIndex:7 currentAdd:0 sampleIndex:7, currentAdd:28 sampleIndex:7 currentAdd:0 currentAdd:0, sampleIndex:28 

而且,多次打印,前后uartPrintf()打印的都不一样。

最近编辑记录 Gentlepig (2025-03-19 08:56:08)

离线

楼主 #1 2025-03-19 13:02:45

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,405
积分: 1369.5

Re: ml307a csdk,串口打印数和预想的不一样。

void uartPrintf(char *str, ...)
{
    static char s[600];        //这个需要根据实际情况修改
    va_list args;
    int len;
    if ((str == NULL) || (strlen(str) == 0))
        return;
    va_start(args, str);
    len = vsnprintf((char*)s, 600, str, args);
    va_end(args);
    cm_uart_write(OPENCPU_MAIN_UART, s, len, 1000);
}

这是参照例程写的uartPrintf函数。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn