Android / iOS


Atmel ATmega168 RS232


I've decided to try out the Atmel microcontrollers to replace the PICMicro I used in the Picarus project I've been working on and off on. This circuit and code will also be used in the Majblomma ][ project that my friend Oliver Hillmann and I have been talking about/working on.

The purpose of this page is to serve as a journal for what I have working with the ATmega168 already and maybe as a guide for other people wanting to use Atmel microcontrollers for RS232 communication.

Atmel Probe is an extension of this project that allows a user to connect to the Ateml chip with rs232 which provides the user with a command prompt allowing reading and writing of SRAM, I/O ports, EEProm, and flash.

Also, I did a bitbanging of this here if anyone's interested in seeing how this would be done without the hardware UART.

Disclaimer: If you get cut, bruised, burn your house down, get diarrhea, contract herpres, die, or any other undesirable thing while imitating or extending this project, I am not at fault.


To use this circuit/software, it should be hooked up to the com port of a PC. When flashing the ATmega168 chip, the CLKSEL fuses should be fused 0010 so that the ATmega's internal clock is used. It should be wired for 8MHz with no clock divide. The computer's serial port should be set to 8N1 @ 19200 baud.

When the circuit is turned on, it will transmit a copyright message over the serial port. After that every character the Atmel receives over the serial port will cause the LED to toggle and the character will be echo'd back to the source.

Resources - Sells the Atmel ATmega168 chips and MAX232 chips. Unfortunately they do not sell the DS275 which can replace a MAX232 without requiring any external capacitors and circuitry. I asked them about it and they said the DS275 was more expensive, but personally I'd rather pay a little more for the DS275 and not have to hook up all kinds of extra capacitors to my circuit. Despite the missing DS275, this is my new favorite site for buying parts :).

Atmel ATmega168 - This is the spec sheet for the ATmega168 microcontroller. - Sells the TOP2048 programmer I've been using to flash my ATmega168 chips. I actually got mine on eBay for about half the price, but if you don't want to bother with eBay, they have them. The biggest downside of the TOP2048 is there is no Linux support (as far as I can see) and the instruction manual is written in an unreadable version of English. - tavrasm is the assembler I used to assemble the code. I'm using the Linux operating system for the development workstation. - I didn't buy anything for this project there, but this is a really nice store also. I think maybe a little more expensive than SparkFun tho, but a big selection of fun stuff :).

Parts Needed

  • Atmel ATmega168 microcontroller
  • DS275 (or MAX232 with 5 capacitors) for 0 to 5v to RS232 voltage conversion
  • LED
  • 330ohm resistors
  • 0.1 µF capacitor
  • 220 µF capacitor
  • 9 pin com port connector
  • Modem serial cable (NULL Modem if pins 2 and 3 of com port are reversed)


I drew a schematic here with dia: atmel_rs232.png. I also have a picture of the board: atmel2.jpeg

My circuit on the breadboard will look a little different than the one in the schematic, mostly in that I have an extra LED that lets me know if there is power on the board and there are two resistors adding up to around 350 instead of just 1. There is also a 4MHz crystal resonator I was originally using, but removed so I could use the 8MHz internal clock instead.

The DS275 chip is used to change TTL voltages (0v = 0, 5v = 1) to RS232 voltages (-5v = 1, +5v = 0). This part of the circuit can be replaced with an ugly and more complex MAX232 chip (along with 5 capacitors).

If you are using a NULL modem cable instead of a straight through cable to the computer, connect pin 3 of the 9pin connector to TXout and pin 2 to RXin instead of the way my schematic wires it.


Download: atmel_rs232.asm

Warning: This code is written for the ATmega168. This processor memory maps the UART registers into SRAM. Other Atmel chips might need in/out instructions instead. Using this as a guide it should be pretty simple.


Well, I must say the ATmega168 is a really freakin' cool chip. I like this so much better than the PICMicro so far. The assembly language is so much more friendly. This is definitely my new microcontroller of choice.

Copyright 1997-2019 - Michael Kohn