Expansion Board Compatible for Raspberry Pi URAT Code
/*
* Project name:
UART
* Copyright
(c) Researchdesignlab.com
* Test configuration:
BOARD: RASPBERRY PI & BEAGLEBONE
Software: ECLIPSE
*/
#include <stdio.h>
#include <stddef.h>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
unsigned char rx_buffer[10];
unsigned char test[64];
unsigned char number[64];
int count,i,flag,k;
int main()
{
FILE *ofp_uart1_tx, *ofp_uart1_rx;
termios uart1;
int fd,f;
int m,n,d,e,a,b,c,q,r,x,y,z,t,u,o;
//IN CASE OF RASPBERRY PI THE FILE NAME IS /dev/AMA0
if((fd = open("/dev/ttyO1", O_RDWR | O_NOCTTY )) < 0)
{
printf("Unable to open uart1 access.\n");
}
if(tcgetattr(fd, &uart1) < 0)
{
printf("Could not get attributes of UART1 at ttyO1\n");
}
if(cfsetospeed(&uart1, B9600) < 0)
{
printf("Could not set baud rate \n");
}
else
{
printf("Baud rate: 9600\n");
}
uart1.c_iflag = 0;
uart1.c_oflag = 0;
uart1.c_lflag = 0;
tcsetattr(fd, TCSANOW, &uart1);
tcflush(fd,TCIFLUSH);
d = write(fd, "HELLO", 5);
rx_buffer[0]=0;
while(rx_buffer[0]!=13) //wait till enter
{
read(fd, rx_buffer, (1)); //receive the character & store the character in buffer
write(fd,rx_buffer[0], 1); //transmit the character back
}
close(fd);
}