搜了下,好像用的是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)
离线
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函数。
离线