Stack Overflow,
I desperately need help getting a BeagleBone Black UART to work from a C program. The code that I am attempting to use is listed below. The code came from Chapter 8 of Derek Molloy’s “Beaglebone” book.
The code compiles without any warnings or errors and seems to run. The program passes the sanity checks that are built into the C code below. The program finishes by printing “Finished sending the message, exiting.” to the console.
The fundamental reason that I think the UART4 is not sending data is that I see no activity on P9/13 when monitoring with a nice digital O’scope. I have also tried monitoring the port by way of a PC running a terminal program.
I am convinced the C-program is reading my command-line message (e.g. “testing123”) correctly. I modified to code to print the message to the console and it printed the message as expected. I also modified the code run in a loop to make it easier to monitor P9/13 with the O’scope. The O’scope shows a constant 3.3VDC on the P9/13.
I also blindly tried a pull-down resistor. The port does not provide much current. A 2k Ohm resistor loaded the port to about 0.2 Volts.
I verified that ttyO4 and ttyS4 are in /DEV, whatever that means.
I am not certain what version of Debian that I am using. I monitored the “header” output from J1 and found this: Debian GNU/Linux 9 ebb ttyS0 BeagleBoard.org Debian Image 2019-08-03
Also, I found this: Machine ID: 229f313330aab6c19873bdc15d4645c7 Boot ID: b74381516ae64aefa37415709164f0e4 Operating System: Debian GNU/Linux 9 (stretch) Kernel: Linux 4.14.108-ti-r113 Architecture: arm
Do I need to enable the UART port or pins? If so, how do I do this and how do I confirm it was successfully done? Do I need to hardwire the control lines (e.g. CTS, RTS)? Do I need to edit the uEnv.txt file?
I am almost certain my board is a rev-c.
As a final note, I tried a similar C-code from the “Bad to the Bone” book with similar unfavorable results.
Any help will be greatly appreciated.
Thanks,
Norm
/* 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;
Depending on your image and kernel...
Also...I am pretty sure config-pin was available in kernel 4.14.x even though that kernel is EOL from their org.
If you come across /dev/ttyS4 not working, try config-pin for your specific pins used...