Skip to main content

Code for RS232 Communication

I was using mikroC for the coding because programming microcontrollers in C is much easier than using Assembly. The C code for RS232 communication is pretty easy.

 void main(){  
   USART_init(9600); // initialize USART module  
        // (8 bit, 9600 baud rate, no parity bit...  
   while (1){  
     if (USART_Data_Ready()){ // if data is received  
       i = USART_Read(); // read the received data  
       USART_Write(i); // send back via USART  
     }  
   }  
 }  

You only need four methods to use the USART module (Universal Synchronous/Asynchronous Receiver/Transmitter). USART_init() method initializes the USART module and sets the bit rate etc. USART_Read() and USART_Write() methods can read and write one Byte of data at a time. USART_Data_Ready() is used to check whether the data has arrived.

What this simple program does is read the data send by the computer and repeat it back to the computer one character at a time. While this program alone is not much of a use in practice, the same theory can be used to do something useful.

What caught my attention is that since a single microcontroller chip can both send and receive data; two microcontrollers can communicate with each other with the same protocol, without the need of a computer or any other interface between them. And since this is serial communication, only one data line is needed. So, we can connect two microcontrollers with just two wires and send any command or data between them.

I know that theoretically this should work, so I'm putting together the circuit to test it practically. I'll post the progress of it as it goes along.

Comments

Popular posts from this blog

Selecting the Correct Gauge Wires for your RC Models

When we are building RC models (aircrafts, multicopters etc.), something we typically overlook is what type of wires to use to distribute power in them. Usually, we try to reduce the weight of the model, so we tend to go with smaller wires. But, we cant expect to put in small circuit-wires and have them handle the amount of power needed. If you look at the wires that comes in the output leads of a Li-Po, or the wires that comes on a standard XT Jack, you'll notice that they're quite huge. Large gauge wires on a Li-Po and XT connectors These need to be huge to handle the amount of amperage that goes through them. So, we should also consider the amperage, and the length of wire needed when selecting the size (gauge) of the wires.

What do the prop size numbers mean?

Have you been trying to shop for propellers - either online or at a hobby shop - and got confused of the numbering used to denote the size of the propellers? You see things like " 10 x 4.5 CW ", or " 8055 CCW ". What do these numbers mean? A 8 x 4.5 CW and CCW Propeller Set It's actually quite simple once you figure it out. The first number denotes the diameter of the prop (length from tip-to-tip). The second number denotes the pitch of the prop. Here, the pitch is denoted as a length, not a angle. Let's see how that works.

Li-Po Batteries Explained - Part 2

I explained about Li-ion batteries (the predecessor of Li-Po) in my earlier post ( Li-Po Batteries Explained - Part 1 ). Now let's see what these 'Lithium Polymers' are. Lithium-Polymer Batteries - The real ones Li-Po batteries - also known as Li-Poly, Pi-Pol, PLI and PLI - are a type of rechargeable batteries that uses same types of electrodes as the Li-ion batteries. The difference is with the electrolyte it uses. Instead of the liquid solvent used in Li-ions, Li-Po uses a polymer electrolyte. In the original design, which dates back to the 1970's, the electrolyte is a dry, plastic-like, thin film. It doesn't conduct electricity, but allows the exchange of ions between the electrodes. Theoretically, with this design, batteries could be made very thin (less than 1 millimeter) and to a variety of form factors. And because of the electrolyte being dry, the manufacturing process can be simplified and the safety of the battery will be higher because of no risk in