通过 C 程序使用 Beaglebone Black UART 时出现问题

问题描述 投票:0回答:1

堆栈溢出,

我迫切需要帮助让 BeagleBone Black UART 通过 C 程序工作。 下面列出了我尝试使用的代码。该代码来自 Derek Molloy 的“Beaglebone”一书的第 8 章。

代码编译时没有任何警告或错误,并且似乎可以运行。该程序通过了内置于下面 C 代码中的健全性检查。程序通过打印“已完成发送消息,退出”来结束。到控制台。

我认为 UART4 不发送数据的根本原因是,当我用漂亮的数字 O'scope 进行监控时,我在 P9/13 上没有看到任何活动。我还尝试过通过运行终端程序的 PC 来监视端口。

我确信 C 程序正在正确读取我的命令行消息(例如“testing123”)。我修改了代码以将消息打印到控制台,并且它按预期打印了消息。我还修改了循环运行的代码,以便更轻松地使用 O’scope 监控 P9/13。 O'scope 在 P9/13 上显示恒定的 3.3VDC。

我也盲目尝试过下拉电阻。该端口不提供太多电流。 2k 欧姆电阻将端口加载至约 0.2 伏。

我验证了 ttyO4 和 ttyS4 位于 /DEV 中,无论这意味着什么。

我不确定我正在使用哪个版本的 Debian。我监控 J1 的“标头”输出并发现: Debian GNU/Linux 9 退潮 ttyS0 BeagleBoard.org Debian 镜像 2019-08-03

另外,我发现了这个: 机器 ID:229f313330aab6c19873bdc15d4645c7 启动 ID:b74381516ae64aefa37415709164f0e4 操作系统:Debian GNU/Linux 9(延伸) 内核:Linux 4.14.108-ti-r113 架构:手臂

我需要启用 UART 端口或引脚吗?如果是这样,我该如何执行此操作以及如何确认它已成功完成?我需要硬连线控制线(例如 CTS、RTS)吗?我需要编辑 uEnv.txt 文件吗?

我几乎可以肯定我的主板是 rev-c。

最后一点,我尝试了《Bad to the Bone》一书中类似的 C 代码,但也得到了类似的不利结果。

任何帮助将不胜感激。

谢谢,

规范

/* Simple send message example for communicating with the
*  UART that is connected to a desktop PC.  */

#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<termios.h>
#incl`ude<string.h>

int main(int argc, char *argv[]){
   int file, count;
   if(argc!=2){
       printf("Please pass a message string to send, exiting!\n");
       return -2;
   }
   if ((file = open("/dev/ttyO4", O_RDWR | O_NOCTTY | O_NDELAY))<0){
      perror("UART: Failed to open the device.\n");
      return -1;
   }
   struct termios options;
   tcgetattr(file, &options);
   options.c_cflag = B115200 | CS8 | CREAD | CLOCAL;
   options.c_iflag = IGNPAR | ICRNL;
   tcflush(file, TCIFLUSH);
   tcsetattr(file, TCSANOW, &options);

   // send the string plus the null character
   if ((count = write(file, argv[1], strlen(argv[1])+1))<0){
      perror("UART: Failed to write to the output.\n");
      return -1;
   }
   close(file);
   printf("Finished sending the message, exiting.\n");
   return 0;
c uart beagleboneblack
1个回答
0
投票

取决于您的映像和内核...

  1. 尝试/dev/ttyS4
  2. 或者尝试 /dev/bone/uart/4
© www.soinside.com 2019 - 2024. All rights reserved.