Hi,
I am using Beagle bone black board in Linux Ubuntu, i am new to BBB, i
tried to check the programing of UART peripheral in the BBB..
Exact C - programs i am not able to found. like simple c program to
initialize the UART with baud rate and other information and writing some
data using buffer and i should see the data printing on to the mini com..
please help me...
The UARTs are connected to /dev/ttySn:
UART0 (console header) /dev/ttyS0 -- note: /sbin/agetty is running on this port
UART1 P9.24,P9.26 /dev/ttyS1
UART2 P9.21,P9.22 /dev/ttyS2
UART3 P9.42 (tx only) /dev/ttyS3
UART4 P9.13,P9.11 /dev/ttyS4
UART5 P8.37,P8.38 /dev/ttyS5
In C, these are "files" and can be accessed via file I/O functions:
At a "lowlevel: open(), read(), write(), close(), and ioctl()/termios().
At a "highlevel: fopen(), fread()/fscanf()/fgets(),
fwrite()/fprintf()/fputs(), and fclose().
Unfortunately, the "man" command is not installed in my BBB image, but it
should be there on your Ubuntu machine and all of the C functions listed above
are well documented.
Really simple C program (assumes BB-UART1-00A0.dtbo has been loaded by uBoot
and you have connected to P9.24 and P9.26):
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#define ERRORCHECK(cmd,message) \
if ((cmd) < 0) {\
int err = errno; \
perror(message); \
exit(err); \
}
int main(int argc, char *argv)
{
int ttyfd;
struct termios saved, current;
ttyfd = open("/dev/ttyS1",O_RDWR);
ERRORCHECK(ttyfd,"Open of /dev/ttyS1 failed:")
ERRORCHECK(tcgetattr(ttyfd,&saved),"tcgetattr (saved) of /dev/ttyS1 failed:")
ERRORCHECK(tcgetattr(ttyfd,¤t),"tcgetattr (current) of /dev/ttyS1 failed:")
ERRORCHECK(cfsetspeed(¤t,B115200),"cfsetspeed (current) failed:");
ERRORCHECK(tcsetattr(ttyfd,TCSANOW,¤t),"tcsetattr (current) failed:");
ERRORCHECK(write(ttyfd,"Hello World\r\n",13),"write failed");
ERRORCHECK(tcsetattr(ttyfd,TCSADRAIN,&saved),"tcsetattr (saved) failed:");
ERRORCHECK(close(ttyfd),"close failed");
exit(0);
}