Skip to main content

Featured Post

Product Design of a 4 wheel differential drive robot

Serial port communication using AVR

 

Serial port communication is pretty much useful and also simple to carry out. There are certain thing you need to get first.

1. A microcontroller (Here Atmega328p).

2. A USB2serial converter.

3. A terminal software.

Modern computers won’t have this rs232 serial ports. So there is no use to go for an rs232 module and get started. Only option left is to communicate through USB ports. Many microcontrollers lack USB support. So there is an easy way. Buy a USB2serial converter or use an old Nokia 1200 or 1680 USB data cable. It has a serial to USB converter. It costs only around 60Rs(India). These are old handsets.

131011-145739If you ain’t find this one, go to eBay and buy this USB To RS232 TTL Converter Adapter Module PL2303HX( Link here). You have to pay around 200 RS for this one.

Let’s get started.

Find the TX pin from datasheet. For Atmega328 it’s pin no: 3. Connect it to RX pin of the USB2serial converter. Then use the given code for sending the word “HELLO” to PC.

Use a terminal to view the output. You can use putty (link here) or HyperTerminal. Putty is free and open source. It’s available for Linux and Windows. HyperTerminal is preinstalled with windows. You can download it for WIN7 or WIN8.

   1: /*
   2:  * Serial_port.c
   3:  *
   4:  * Created: 06-10-2013 11:51:41
   5:  *  Author: ANANTHAKRISHNAN
   6:  */ 
   7:  
   8: #define F_CPU 1000000UL
   9: #define FOSC 1000000 
  10: #define BAUD 4800
  11: #define MYUBRR FOSC/16/BAUD-1
  12:  
  13: #include <avr/io.h>
  14: #include <util/delay.h>
  15:  
  16: void USART_Init( unsigned int ubrr);
  17: void USART_Transmit( unsigned char data );
  18:  
  19: int main(void)
  20: {
  21:     USART_Init(MYUBRR);                                               //Initializing USART
  22:  
  23:     while(1)
  24:     {
  25:         USART_Transmit('H');
  26:         USART_Transmit('E');
  27:         USART_Transmit('L');
  28:         USART_Transmit('L');
  29:         USART_Transmit('O');
  30:         USART_Transmit('\n');
  31:         USART_Transmit('\r');
  32:     }
  33: }
  34:  
  35: void USART_Init( unsigned int ubrr)
  36: {
  37:     /*Set baud rate */
  38:     UBRR0H = (unsigned char)(ubrr>>8);
  39:     UBRR0L = (unsigned char)ubrr;
  40:     //Enable receiver and transmitter */
  41:     UCSR0B = (1<<TXEN0) | (1<<RXEN0);
  42:     /* Set frame format: 8data, 2stop bit */
  43:     UCSR0C = (1<<USBS0)|(3<<UCSZ00)|(1<<UPM01);//Asynchronous 8bit data Even parity 1 stop bit
  44: }
  45:  
  46: void USART_Transmit( unsigned char data ) 
  47: {
  48:    // Wait for empty transmit buffer */
  49:    while ((UCSR0A & (1 << UDRE0)) == 0) {};
  50:    // Put data into buffer, sends the data */
  51:    UDR0 = data;
  52: }
  53:  

The code is self explanatory. If you have any doubts do comment. Don’t forget to add same boad rate and parity in the terminal.


Here is a snapshot of putty displaying the output.


CropperCapture[1]

Comments

Popular posts from this blog

Plymouth theme for Ubuntu

Bored of having the same boot animation screen again and again? There are plenty of Plymouth themes available out there. This is a theme I created by slicing some cool gif files I found online. You can download the theme and find the installation steps on my github account. ( https://github.com/krishnan793/PlymouthTheme-Cat )  The theme is created for Ubuntu 16.04. But this can be installed on previous versions with slight modification. If you have a slow computer then you can watch the whole animation loops. (The VM I used to record the screen was fast though. :))

Getting started with GPIO (Testing GPIO with a multimeter)

There are 65 possible GPIO pins that you can control. Some of the GPIO pins are normally configured to different functions. Let's play with one of them. Go to the beaglebone website and figure out the header pin corresponding to gpio23. The gpio23 is mapped to the 13th header pin. In this tutorial we are testing the gpio23 output using a multimeter (Do not connect an LED directly to BBB IO pin). First go to following directory cd /sys/class/gpio / Then make gpio23 available echo 23 > export A new directory will be created. Open gpio directory. cd gpio23 The direction of IO will be normally set as in (input).  To make it as output, echo out > direction Then set the pin to high using echo 1 > value Measure the voltage at pin 13 of P8 header. If its 3.3 V then you are on the right track. Pin 1 and 2 will be ground. You can connect the negative terminal of multimeter to pin 1 or 2. To set output as zero, echo 0 > value After finished wit...

Remote access your BeagleBone Black using vnc

Before going into how to share desktop with your BBB I assume you have a proper ssh access to your BBB. (through USB) (if not read this ) Also this tutorial is for BBB with Debian installed (type cat /etc/*-release to know which distro you are currently using. Or refer here ) First install the vnc server in BBB.(After logging into BBB) ssh root@192.168.7.2 apt-get install x11vnc Then go to your local computer and open a terminal window. Install a vnc viewer like vinagre. sudo apt-get install vinagre Now its time to start vnc server in BBB. x11vnc -auth /var/run/lightdm/root/:0 -forever This will start a vnc server at port 5900. Note this server setup is temporary. If you want to remotely connect to your BBB after a reboot type the above command again. Go to your local computer and type  vinagre 192.168.7.2::5900 A remote desktop will be shown if all goes well. Try exploring other options in x11vnc using (in BBB) man x11vnc Th...