Experiment 02 Ramesh RB Transmitter (Final)
Experiment 02 Ramesh RB Transmitter (Final)
DATE :
Question:
Write a user space program to communicate with the UART in Rugged Board
A5D2x to transmit the data
Algorithm:
1. Initialization:
Include necessary header files for serial communication, input/output, and terminal
control.
Define functions:
set_interface_attribs: Configures the serial port attributes like baud rate, data bits, etc.
uart_transmit: Transmits data over the serial port.
Declare variables:
portname: Stores the serial port device name (/dev/ttyS3 in this case).
fd: File descriptor for the serial port.
input: Character array to store user input (size 100).
Call set_interface_attribs function to configure the serial port with desired settings:
speed: Baud rate (e.g., B9600 for 9600 baud).
Check for errors during configuration. If error occurs, print error message, close the port,
and exit.
After exiting the loop (Ctrl+C or program termination), close the serial port using close
function.
6. uart_transmit Function:
7. set_interface_attribs Function:
This detailed algorithm explains how the program establishes serial communication, reads
user input, transmits data, and handles potential errors.
Program:
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
// Function prototypes
int set_interface_attribs(int fd, int speed);
void uart_transmit(int fd, const char* data, int size);
int main() {
char *portname = "/dev/ttyS3";
int fd;
char input[100]; // Buffer for user input
while (1) {
// Get input from user
fgets(input, sizeof(input), stdin);
input[strcspn(input, "\n")] = '\0'; // Remove newline character
// Transmit data
uart_transmit(fd, input, strlen(input));
cfsetispeed(&tty, (speed_t)speed);
cfsetospeed(&tty, (speed_t)speed);
return 0;
}
Output:
Result:
The above program is run and executed Successfully