Programming a microcontroller is not as difficult as it sounds to most people when they’re just starting out with microcontrollers. In fact, with proper hardware and a few connections, you can easily burn your code and then lay back and watch your microcontroller execute what you desire(obviously not everything :D). Though microcontroller programming is easy, there are many ways to do it. You can program it using ISP programmers, USB to TTL converters, RS232 and many more. You can also use an Arduino as an ISP. However, in this article, I’ll be explaining how you can program your microcontroller using RS232 along with MAX232 IC.
It is important to note that you will be able to successfully burn the code using this method only if your IC is already bootloaded.
Before proceeding to the actual interfacing, it is important to understand what MAX232 IC is, and what role it plays in programming the microcontroller using RS232 communication protocol.
Computers can communicate serially using the serial port which follows the TIA/EIA-232-F standards (RS232 levels) i.e. up to -25V for logic 0 and up to +25V for logic 1. It is generally between ±3V to ±15V, whereas microcontrollers understand and communicate using TTL logic level which is +5 volts and 0 Volts. So to accomplish the communication between the two devices you need to convert the RS232 level to the TTL logic level and vice-versa. This is where the MAX232 IC comes into the picture.
A MAX232 is a 16 pin IC which consists of 2 drivers and 2 receivers and offers a maximum data rate of 120kbps. It can handle maximum input voltage up to ±30V. It uses a charge pump circuit which requires 4 external capacitors to derive the positive and negative voltages from TTL logic level. A bypass capacitor is connected between pin 16(Vcc) and ground. The Vcc voltage should be connected to the same power source used for logic device and should be between 4.5V to 5.5V. Below given is the pinout diagram for MAX232.
Interfacing of 8051 with max232
- In all, you will require five 1uF capacitors.
- Connect the +ve leg of the 1uF capacitor to C1+ and –ve leg of the same capacitor to C1-
- Do the above, for pins 4 and 5 i.e. C2+ and C2-.
- Connect the +ve leg of the capacitor to Vs+ (2) and –ve leg of the same capacitor to ground.
- Connect the -ve leg of the capacitor to Vs- (6) and the +ve leg of the same capacitor to ground.
- Finally connect the last capacitor in between Vcc and ground with the positive leg being connected to Vcc.
- Pins T1IN, T2IN have the same functionality. Similarly, pins (T1OUT, T2OUT), (R1IN, R2IN), (R1OUT, R2OUT) have the same functionality as well.
- You can either use T1IN, T1OUT – R1IN, R1OUT or T2IN, T2OUT – R2IN, R2OUT.
- T1IN – It is an input pin to MAX232. It accepts input from the microcontroller in TTL logic level.
- T1OUT – It is an output pin. It outputs RS232 level from MAX232 to the DTE (computer).
- R1IN – It is an input pin to MAX232. It takes input from DTE (Computer) in the form of RS232 level.
- R1OUT – It is an output pin. It provides output in the form of TTL logic level to the microcontroller.
The above schematic shows the interfacing of MAX232 to 8051 and serial port (DB9).
Remember all the capacitors in the above schematics are of 1uF. Out of 9 pins provided on DB9 only 3 are used for this purpose. i.e RXD, TXD and Ground. If you want insight on other pins, simply search DB9 connector and you’ll find them.
If you have trouble understanding the connections, let us know in the comments.
4 Comments
Arjun Gopkumar · March 15, 2019 at 10:36 am
What software do you use to burn a hex code?
Moiz · March 15, 2019 at 4:20 pm
For 8051, I use flash magic to burn the code.
Rony Halder · November 28, 2019 at 10:55 pm
8051ah doesn’t work with flash magic. does AT89C51 works with flash magic?
Moiz · November 29, 2019 at 11:05 am
Flash magic supports NXP. You can try using FLIP software for AT89C51.