Tag Archives: UART

Serial Communication with PIC16F877A

This article series aims at teaching serial communication between a PIC microcontroller and a PC. We first introduce you with what is serial communication is and how it can used. Then we tell you how to perform serial communication using PIC microcontroller and how we use the USART peripheral for the purpose. We will tell you how our usart library for PIC16F series can be used for easy serial communication, in this part we also discuss how to set up a MPLAB X project for using the USART library. After that we will build a demo project to explore the library. Finally we will burn this demo in a PIC16F877A and establish a serial communication with PC. Serial Communication Their are several serial communication standards like RS232, SPI, I2C etc. Of which RS232 is a asynchronous method. That means it does NOT have a synchronizing clock line. One way data requires only one conductor line. Since it is a two way communication their are two lines between the two device. One for sending data called the Tx and one for receiving data called the Rx. The communication is full duplex, that means data can be sent at the same time data is being received. generally other serial communication like SPI and I2C are used for short range communication like between […]

eXtreme Burner – AVR 1.3 Beta Test

Hi All, I was adding support for some chips with big flash memory (like ATmega2560 etc.) in my Programmer Software eXtreme Burner – AVR. But right now I do not have any ready setup with ATmega2560 so I ask anyone of you who have got a ATmega2560 (or ATmega128) setup to please carry out a simple test. Just download the eXtreme Burner AVR 1.3 Beta. And try to flash the following hex files. Test Hex File for ATmega128 and ATmega2560. And update me the details via a comment on this page. Serial Interface. Now your USBasp can double as a USB to serial converter at NO extra cost! We now have a basic serial terminal integrated in the eXtreme Burner AVR ! The terminal can be launched from the Tool Menu. But you need a modified USBasp Firmware to use the terminal. It is available from here. USBasp Firmware with UART Support. eXtreme Burner AVR v1.3 Beta !

PC Controlled Robot

In this tutorial we will discuss a simple PC controlled robot. The Robot PC link will be a RS232 serial line. The robot will have only five commands. Move forward (RS232 char ‘F’ or ‘f’) Move backward (RS232 char ‘B’ or ‘b’) Turn Left (RS232 char ‘L’ or ‘l’) Turn Right (RS232 char ‘R’ or ‘r’) Stop (RS232 char ‘S’ or ‘s’) To keep things as simple as possible, in this example we will use terminal software RealTerm for sending commands to the robot. Later on a dedicated software can be written on PC end to control the robot. The Robot’s Hardware The robot’s hardware will be a simple differential drive using two 200RPM DC Gear motor mounted on a HQ Metal Chassis with a front castor wheel. On the back motors we have mounted plastic wheels. More about differential drive is explained in this tutorial. Gear Motors   Wheels   Metal Chassis   Remove motor’s nut   Insert the motor   Fasten the nuts again   Both motors installed   Front Castor wheel   Installing the front castor   Mounting hole for wheels screw   Mounting the wheels   Chassis is ready! The Electronics The robot is controlled using xBoard v2.0 which has ATmega32 as main CPU and integrated motor drivers. We have connected xBoard v2.0 with PC using […]

Digital Humidity Sensor

Digital Humidity sensors are of great help in maintaining suitable environmental condition in places such as ware houses, green houses, factories, smart homes etc. They are also very easy to interface with MCU and PC. When coupled with a PC or Microcontroller they can be used in wide variety of smart automation. One such sensor I will present today is a serial humidity sensor. The interface is very simple. The communication is done over a standard asynchronous serial line. The interface parameters are as follows. UART 9600 bps. Start bit: 1 Stop bit: 1 Parity Bit : 0 (No parity bit) No Flow Control. Fig.: Serial Humidity Sensor.   Command Set All commands are begin by "$sure" followed by space (ascii 32) All UART Command are in ASCII Commands are NOT case sensitive. All commands ends with a CR LF pair (ascii \r\n in C language). Get Current Temperature in Degree Centigrade Command : $sure temp -c Returns: XXXCentigrade Where XXX is current temperature. Example in C UWriteString("$sure temp -c\r\n"); Get Current Temperature in Degree Fahrenheit Command : $sure temp -f Returns: XXXFahrenheit Where XXX is current temperature. Example in C UWriteString("$sure temp -f\r\n"); Get Current Humidity Command : $sure humidity Returns: XXX%RH Where XXX is current relative humidity. Example in C UWriteString("$sure humidity\r\n"); Get Current Status Command : $sure […]

Using the USART of AVR Microcontrollers.

Welcome to the third part of my RS232 serial communication tutorial. Till now we saw the basics of RS232 communication and made our level converter. Now its time to understand the USART of AVR microcontroller and write the code to initialize the USART and use it to send and receive data. Like many microcontrollers AVR also has a dedicated hardware for serial communication this part is called the USART – Universal Synchronous Asynchronous Receiver Transmitter. This special hardware make your life as programmer easier. You just have to supply the data you need to transmit and it will do the rest. As you saw serial communication occurs at standard speeds of 9600,19200 bps etc and this speeds are slow compared to the AVR CPUs speed. The advantage of hardware USART is that you just need to write the data to one of the registers of USART and your done, you are free to do other things while USART is transmitting the byte. Also the USART automatically senses the start of transmission of RX line and then inputs the whole byte and when it has the byte it informs you(CPU) to read that data from one of its registers. The USART of AVR is very versatile and can be setup for various different mode as required by your application. In this […]

RS232 Communication – The Level Conversion

Hello and welcome back. Continuing our discussion on RS232 serial communication in this part we will make a RS232 level converter. In the last tutorial we saw that how RS232 level signals differs from normal logic signals. So to interface RS232 level signals to our MCUs we need a "Level converter". And in this tutorial we will make one. What a level converter will do is to convert RS232 level signals (HIGH=-12V LOW=+12V) from PC to TTL level signal (HIGH=+5V LOW=0V) to be fed to MCU and also the opposite. Fig – Working of RS232 level converter       As RS232 is such a common protocol there is a dedicated IC designed for this purpose of "Level Conversion". This IC is MAX232 from Maxim. By using charge pumps it generates high voltages(12V) and negative voltages(-12V). Now lets make it! Things you need S.No Item Value Qty 1 MAX232 IC 1 2 Capacitors 1uF 4 3 10uF 1 4 DB9 Female Connector 1 5 General Purpose PCB 1 6 Some Wires – –   Fig – Stuffs required for RS232 level converter.     Now having all the stuffs in our working table lets begin. The Schematic Fig – Schematic for RS232 level converter.     Assembly Assemble the circuit according to the schematic on a small piece of general […]