Hi,
    I am unable to do simple uart communication in BBB. I have set device 
tree

uart2_pins: uart2_pins {
pinctrl-single,pins = <
0x154 0x01
0x150 0x31
>;
};

&uart2 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&uart2_pins>;
};

then I configure the UART Port

stty -F /dev/ttys0 cstopb -evenp ispeed 115200

Then I made a user space application for reading and writing data to
device file. I have attached the application program

I connected Tx and Rx pin in same BBB.(Loop back mode)

But  I am not able to do simple UART communication in loop back
mode. Do am I missing something? Please help me


-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
//Filename: uart.c
//
//Project : UART
//Author  : Jay Kothari
//Contact : [email protected]
//Date    :



#include <stdio.h>
#include <stddef.h>
#include <time.h>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>


int pauseNanoSec(long nano);
void pauseSec(int sec);


int main(int argc, char *argv[])
{
	char buf[30] = "/dev/minettyO1";
	
	//UART config using termios
	struct termios uart1,old;
	int fd;
	unsigned char buf2 = 0xA7;
	fd = open(buf, O_RDWR | O_NOCTTY);
	if(fd < 0) printf("port failed to open\n");

	while(1)
	{
		write(fd,&buf2,1);
		pauseNanoSec(5000000);
		if(read(fd,&buf2,1) > 0)
			printf("%c",buf2);
		pauseNanoSec(5000000);
	}

	close(fd);

	return 0;
}

int pauseNanoSec(long nano)
{
	struct timespec tmr1,tmr2;

	tmr1.tv_sec = 0;
	tmr1.tv_nsec = nano;

	if(nanosleep(&tmr1,&tmr2) < 0)
	{
		printf("Nano second pause failed\n");
		return -1;
	}
}

void pauseSec(int sec)
{
	time_t now,later;

	now = time(NULL);
	later = time(NULL);

	while((later - now) < (double)sec)
		later = time(NULL);
}

Reply via email to