Duo开发板与stm32f103进行uart通信的问题

源码如下(文档中的uart例程):
#include <stdio.h>
#include <unistd.h>

#include <wiringx.h>

int main() {
printf(“code line is: 7\n”);
struct wiringXSerial_t wiringXSerial = {9600, 8, ‘n’, 1, ‘n’};
char buf[1024];
int str_len = 0;
int i;
int fd;
printf(“code line is: 12\n”);
if(wiringXSetup(“duo”, NULL) == -1) {
wiringXGC();
return -1;
}

if ((fd = wiringXSerialOpen("/dev/ttyS4", wiringXSerial)) < 0) {
    printf("Open serial device failed: %d\n", fd);
    wiringXGC();
    return -1;
}

// wiringXSerialPuts(fd, "Duo Serial Test\n");

while(1)
{
    str_len = wiringXSerialDataAvail(fd);
    //printf("str_len is:  %d\n",str_len);
    if (1) {
    
        i = 0;
        printf("i is: %d\n", i);
        while (1)
        {
        	printf("code line is: 35\n");
            buf[i++] = wiringXSerialGetChar(fd);
            printf("Duo UART receive: %s\n", buf);
        }
        
    }
}

wiringXSerialClose(fd);

return 0;

}
但是串口检测不到有数据接收,报错如下:


stm32可以发送数据给电脑,并且可以在串口助手中显示出来。
duo文档中的uart例程也能跑通。
但是将二者接到一起duo就接收不到数据,这是为什么呢?
排除接线原因,波特率也换过不同的试过,但还是不行
跪求大神解答/(ㄒoㄒ)/~~

Upon reviewing your code, I’ve identified a potential oversight regarding the absence of a check to ascertain whether there is data present in the serial port buffer. This omission may lead to attempts to read from the buffer when it is empty, resulting in the output of garbled text. To enhance the robustness and efficiency of your code, I recommend verifying the presence of sufficient data in the buffer before proceeding with any read operations. Implementing such a check can significantly mitigate the issue of reading empty data, thereby improving the overall performance and user experience of your application.

在审查您的代码时,我注意到一个可能的问题点,即似乎没有进行检查以确认串口缓冲区中是否存在数据,这可能导致尝试读取时获取到空数据,并最终输出乱码。建议在进行读取操作之前,先验证缓冲区中是否有足够的数据。这样的做法可以有效避免读取空数据的问题,从而提升程序的整体表现。

谢谢!实际上是因为duo串口的波特率为9600,将其串口的波特率改成与32一样的即可。命令如下:
stty -F /dev/ttyS4 230400