堆栈溢出,
我迫切需要从C程序中获取Beaglebone Black UART的帮助. 下面列出了我try 使用的代码.密码来自德里克·莫洛伊的《比格尔伯恩》一书的第八章.
代码编译时没有任何警告或错误,并且似乎可以运行.该程序通过了内置在下面的C代码中的健全性判断.程序以打印"已完成发送消息,正在退出"结束.到控制台.
我认为UART4没有发送数据的根本原因是,当我用一个很好的数字O‘Scope进行监测时,我在P9/13上没有看到任何活动.我还try 过通过运行终端程序的PC来监控端口.
我确信C程序正确地读取了我的命令行消息(例如"Testing123").我修改了代码以将消息打印到控制台,它按预期打印了消息.我还修改了在循环中运行的代码,使其更易于使用O‘Scope监视P9/13.O‘Scope在P9/13上显示恒定的3.3VDC.
我还盲目地try 了下拉电阻.这个端口不能提供太多电流.2k欧姆电阻将端口加载到约0.2伏.
我验证了ttyO4和ttyS4在/dev中,不管这意味着什么.
我不知道我使用的是什么版本的Debian.我监视了J1的"header"输出,发现了这个: Debian GNU/Linux 9 ebb ttyS0 BeagleBoard.org Debian Image 2019-08-03
此外,我还发现了这个: 机器ID:229f313330aab6c19873bdc15d4645c7 bootstrap ID:b74381516ae64aefa37415709164f0e4 操作系统:Debian GNU/Linux 9(Stretch) 内核:linux 4.14.108-ti-r113 架构:ARM
我是否需要启用UART端口或引脚?如果是,我如何执行此操作以及如何确认已成功完成?我是否需要硬连线控制线(例如CTS、RTS)?我需要编辑uEnv.txt文件吗?
我几乎可以肯定,我的董事会是一名牧师.
最后,我try 了一种类似于《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;