CONTENTS

Home
Updates
Software
Electronics
Android / iOS
Music
Resume
Contact


YouTube
Twitter
GitHub


Atmel ATmega168 RS232

Introduction

I've decided to try out the Atmel microcontrollers to replace the PICMicro I used in a previous project I've been working on and off 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.

Explanation

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.

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)

Schematic

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

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.

Conclusion

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-2021 - Michael Kohn