# RS232

**To write and test RS232**

**Step1: Create a uart\_txrx.c File**

**Step 2: Write the following code into the File**

```
#include "serial.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h>
int main (int argc, char* argv[])
{
	int i, rv, len, pid;
	char buffer[100], buffer2[10];
	struct termios my_termios, new_termios;
	char dev[20]="/dev/ttyS3";
	int fd = open(dev, O_RDWR | O_NDELAY | O_NOCTTY);
	tcgetattr(fd, &my_termios);
	my_termios.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | INLCR);
	my_termios.c_iflag &= ~(PARMRK | INPCK | ISTRIP | IXON);
	my_termios.c_oflag &= ~(OCRNL | ONLCR | ONLRET | ONOCR);
	my_termios.c_oflag &= ~( OFILL | OLCUC | OPOST);
	my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
	my_termios.c_lflag &= ~(ISIG | ECHOK | ECHOCTL | ECHOPRT);
	my_termios.c_cflag &= ~(CSIZE | PARENB);
	my_termios.c_cflag &= ~CRTSCTS;
	my_termios.c_cflag |= CS8 | CLOCAL;

	my_termios.c_cflag &= ~CBAUD;
	my_termios.c_cflag |= B115200; /* change your baudrate here */
	my_termios.c_cc[VMIN] = 0;
	my_termios.c_cc[VTIME] = 5;
	rv = tcsetattr(fd, TCSANOW, &my_termios);
	tcgetattr(fd, &new_termios);
	while(1)
	{

		printf("enter the string to send \n");
		scanf("%s",buffer);
		len = strlen(buffer)+1;
		write(fd, buffer, len);
		if (read(fd, buffer2, 1) > 0)
			for(i=0;i<len;i++){
				printf("%c\n",buffer2[i]);}
	}
	close(fd);
}
```

**Step 3: Open Terminal and navigate to Toolchain folder.**

**Step 4: Run the "env.sh" file using `. env.sh` to enable the toolchain**\
**To check if the toolchain is enabled type in "arm" and hit the \<TAB> key twice**

**Step 5: Create a binary name "uartTxRx" from the "uart\_txrx" file using**\
`arm-linux-gnueabi-gcc uart_txrx.c -o uartTxRx`

**Step 6: Transfer the compiled binary to the Board using TFTP or SD card**

**Step 7: Run the binary `sudo ./uartTxRx`on the Board's terminal.**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ruggedboard.gitbook.io/ruggedboard/tutorial-using-c/test-interfaces-of-rb/interfaces/rs232.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
