I’ve been trying for days to get my atmega32 to output bytes to the PC through the RS232. I’m using the olimex development board with the Max232 chip. I’m pretty sure that I wired the MAX232 Tx/Rx correctly to the atmega UART pins. I’ve set the baudrate to 51 (9600 for a 8Mhz external crystal) and I’ve checked the fuse bits and they are correct. I tried using the example code from the avrlib library (uart.h), and I’ve also tried using the example code from the atmega32 manual. I’ve done a loopback on the serial cable, as well as on the max232 chip. I’ve even checked the transmit output of the microcontroller with an oscilloscope and it is putting out something. However, the terminal still doesnt print out anything. I’m using Tera Term Pro right now, with the standard settings (9600, 8 data, 1 stop, no flow control). I also tried using hyperterminal. I just dont understand why its not outputting anything. Any help would be appreciated, sooner rather than later hopefully!
There’s about a gazillion things that could cause it not to work, I’ll throw some ideas out that you havent already mentioned
Make sure you’re not setting the U2X bit in your code, if so, the correct value for UBRR is 103, rather than 51
Verify output on the rs-232 connector side with your oscilloscope, to make sure it is getting thru the MAX232. I’ve had problems where insufficient power to the board (i.e. using a depleted 9v battery battery) caused the MAX232 to not function properly, even though the microcontroller still chugged along.
Make sure the fuse bits on the controller are set to use the external crystal for the processors clock, and not the internal oscillator. I think by default the chips come set up to use an internal clock, which may be at 4mhz.
On the baud rate constant in the UART - beware syntax for a hex versus decimal constant.
You say that the 'scope shows data coming out of the Mega32? Is there data on the output of the MAX232? And I’m sure you paid attention to DCE/DTE and the need for a null modem (TX from Mega32 to RX on PC) - depending on how you cable this.
If you are still having problems, I can send you a .hex file for a Mega32 at 8MHz which does work here. You can just flash it and see if it works. That will eliminate the chance for software errors (assuming there’s not some sort of mistakenly set fuses).
steve
i using the ATMEGA32 and WinAVR.
im having the exact same problem. ive spent two days now trying to figure it out. should i be using RTS or DTS? i bought the 40pin development board (http://www.sparkfun.com/commerce/produc … ucts_id=31)
i have a 8mhz crystal on the board thats already connected. i set the following:
lfuse: ff (11111111)
hfuse: 99 (10011001)
heres the simplest form of a UART test i could come up with…this doesnt seem to work. all i get is a blinking LED. jumping the TX and RX wires and typing in the terminal works.
#include <stdio.h>
#include <avr/io.h>
#define FOSC 8000000
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1
void init(void);
void delay_ms(uint16_t x);
int main(void)
{
init(); //Setup IO pins and defaults
while(1)
{
//Blink LED
PORTB = 0xFF;
delay_ms(500);
PORTB = 0x00;
delay_ms(500);
//UART
while(UCSRA == 0 & (1 <<UDRE) == 0);
UDR = 'a';
}
}
void init (void)
{
//Initialize Output PortB
DDRB = 0b11111111;
//Initialize UART
UBRRH = MYUBRR >> 8;
UBRRL = MYUBRR;
UCSRB = (1<< RXEN)|(1<<TXEN);
UCSRC = (1<<URSEL)|(3<<UCSZ0);
}
void delay_ms(uint16_t x)
{
uint8_t y, z;
for ( ; x > 0 ; x--){
for ( y = 0 ; y < 80 ; y++){
for ( z = 0 ; z < 40 ; z++){
asm volatile ("nop");
}
}
}
}
RTS/CTS, no. Just TXD and RXD. Make sure that the PC’s RXD connects to the Transmit data coming out of the AVR and through the RS232 level shifter, and vice-versa for the PC’s TXD. If you are unsure, disconnect the cable to the PC and use a volt meter to ground. TXD will have voltage (-8V or so) and RX will be zero.
The nice utility called AVRcalc.exe (download it) calculates for 8MHz a UBBRL value of 0x33 for 9600baud. Here’s some initialization code
UCSRB = (1<<TXEN) | (1<<RXEN); // Async no parity 1 stop bit; Tx, Rx enabled
UCSRC = (1<<URSEL) | (3<<UCSZ0); // URSEL to write USART control, 3 -> 8 bit chars
This
while(UCSRA == 0 & (1 <<UDRE) == 0);
doesn’t seem correct to me. Don’t you want
while ((UCSRA & (1<<UDRE)) == 0)
;
to loop until the transmit output register is empty and can accept the first/next character.
--------=
PS: That delay routine you have - most all the C compilers come with a library that has delay() or wait() or some such so you don’t have to code this.
well there it is everyone, RX and TX on the AVR were NOT connected to the MAX232. nub mistake i will admit.
what makes me made is the wiring for the DB9 connector which came with the board. im not sure what it’s set up for, but i had to make some jumpers.
thanks everyone! im off to implement a GPS solution on one of those cheap nokia LCDs and possibly log the GPS data onto a MMC flash card. wish me luck!