ruggedBOARD
Tutorial Using Python
Tutorial Using Python
  • Overview
  • Quick Start with RB
    • Pre-Requisite
      • Required Hardware and Software Components
      • Host Setup
      • Linux Commands
    • Power Up your RB
    • Fiddle with RB Command-line
  • Lib-Mraa & UPM Sensor Libraries (Python)
    • First Python Program
    • Know Your Libraries
      • LibMRAA
        • Python Programming using MRAA (SPI)
        • Python Programming using MRAA (PWM)
        • Python Programming using MRAA (gpio_blink)
        • Python Programming using MRAA (Aio)
      • LibUPM
    • Example Programs for Sensors
      • Procedure to interface phyNODE with RB
      • Accelerometer
      • Temperature Sensor
      • Pressure Sensor
      • Humidity Sensor
      • Magnetometer
      • PIR Sensor
      • Ultrasonic Sensor
      • Gas Sensor (MQ5)
    • mikroBUS UPM Sensor
    • Example programs for Communication Protocols
      • GPIO
      • I2C
      • UART
  • Hello World in C language
    • Setting up Environment
    • Transferring Files from Host to Board
    • Write your first C program
  • IoT Implementation
    • What is IoT?
    • IoT Protocols
    • MQTT Setup
  • Peripherals Functionality Testing using C Language
    • Interfaces
      • GPIO(General purpose Input/Output):
      • UART(Universal Asynchronous Receiver-Transmitter)
      • RS232
      • RS485
      • CAN
      • MikroBUS
      • mPCIe
  • Advance RB
    • Preparing SD card in case of OS failure
Powered by GitBook
On this page

Was this helpful?

  1. Peripherals Functionality Testing using C Language
  2. Interfaces

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 ./uartTxRxon the Board's terminal.

PreviousUART(Universal Asynchronous Receiver-Transmitter)NextRS485

Last updated 6 years ago

Was this helpful?