Things you will need:
The breadboard setup as shown on the main page | A RS-232 level converter | ||
If a RS-232 dongle isn't available, wire up a MAX232 next to the Atmega chip on the breadboard following the schematic below. For that you will need a MAX232 chip, 5 1uf capacitors and a female DB9 connector.
1) Connect the +5v and GND leads from the RS232 dongle to the breadboard regulated supply.
2) Connect the TX wire from the RS232 dongle to the RX (pin2) of the Atmega.
3) Connect the RX wire from the RS232 dongle to the TX(pin3) of the Atmega.
The basic setup should look similar to the images below.
The ISP programmer hookup can be seen at the rear.
4) Download the sample code and load it into the Atmega using your favorite download software. The specifics of programming the Atmega are not covered here since there are several different ways to do it.
5) Program the fuse settings as follows:
lfuse = 0x62, hfuse = 0xDF, efuse = 0xF9
6) Connect the MAX232 to the serial port on your pc and start up a terminal program with the settings of 2400 8 N 1 and power up the Atmega.
You should see this on your terminal if it was successful:
C Example Code Section
/* RS232 Test
For an Atmega 48 88 or 168
Atmega168 DIP TX PD1 (pin3)
Atmega168 DIP RX PD0 (pin2) */
#define F_CPU 1000000UL
#define UBRR_1200 51
#define UBRR_2400 25 // for 1Mhz
// #define UBRR_2400 207 // for 8Mhz with .2% error
// #define UBRR_9600 51 // for 8Mhz with .2% error
// #define UBRR_19200 25 // for 8Mhz with .2% error
#include <avr/io.h>
#include <util/delay.h>
/* Initializes the USART (RS232 interface) */
void USART_init( unsigned int ubrr )
{
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char)ubrr;
UCSR0B = (1 << TXEN0); // Enable RX, TX & RX interrupt
UCSR0C = (3 << UCSZ00); //asynchronous 8 N 1
}
/* Send some data to the serial port */
void USART_tx_string( char *data )
{
while ((*data != '\0'))
{
while (!(UCSR0A & (1 <<UDRE0)));
UDR0 = *data;
data++;
}
}
/* MAIN */
int main(void)
{
USART_init(UBRR_2400);
_delay_ms(250);
USART_tx_string("Connected!\r\n");
_delay_ms(250);
while (1) // do until finished or broken
{
USART_tx_string("U"); //show me the test
_delay_ms(250); // wait .25 seconds
USART_tx_string("T");
_delay_ms(250); // wait .25 seconds
}
}
C Source code for this project.