[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Strangeness with UART Baud Rate
From: |
User Tomdean |
Subject: |
Re: [avr-gcc-list] Strangeness with UART Baud Rate |
Date: |
Sun, 24 Jul 2005 21:25:26 -0700 (PDT) |
Thanks for the reply. That was the problem.
tomdean
# echo Makefile
#
# $Id$
#
.ifdef ATMEGA8515
_MACH_CPU=atmega8515
.else
_MACH_CPU=atmega16
.endif
_CPUCFLAGS=-mmcu=$(_MACH_CPU)
CFLAGS+=-Os
SRCS=echo.c
PROG=echo.elf
INTEL_HEX=$(PROG:.elf=.hex)
CC=avr-gcc
all: $(PROG) $(INTEL_HEX)
PROG: $(OBJS)
echo.hex: $(PROG)
avr-objcopy -j .text -j .data -O ihex $(PROG) $(INTEL_HEX)
NOMAN=1
dump: $(PROG)
avr-objdump -d $(PROG)
map: $(PROG)
avr-gcc -g -Wl,-Map,echo.map -mmcu=atmega16 -o $(PROG) $(OBJS)
program: $(INTEL_HEX)
avrdude -p m8515 -P/dev/cuaa0 -c stk500 -U flash:w:$(INTEL_HEX):i
include /usr/share/mk/bsd.prog.mk
================================================================
#include <avr/io.h> /* io definitions like PORTB, etc */
void serial_init (void);
unsigned char serial_recv (void);
void serial_send (unsigned char);
void serial_print (const char *);
/* initialize the serial port */
void serial_init(void) {
#define BAUD 3686400/16/9600-1
UBRRH = (BAUD >> 8); /* high order bits */
UBRRL = BAUD; /* low order bits */
/* enable tx and rx */
UCSRB = (1 << RXEN) | (1 << TXEN);
UCSRC = (1 << URSEL) | (1 << USBS) | (1 << UCSZ1) | (1 << UCSZ0);
return;
}
/* Wait for a character on the serial line and return it. */
unsigned char serial_recv (void) {
/* wait for rx char */
while (!(UCSRA & (1 << RXC)));
/* return the char */
return UDR;
}
/* Send the character on the serial line. */
void serial_send (unsigned char c) {
/* wait for tx buffer empty */
while (!(UCSRA & (1 << UDRE)));
/* send the char */
UDR = c;
return;
}
/* Send the buffer on the serial line. */
void serial_print (const char *msg) {
while (*msg != 0)
serial_send (*msg++);
return;
}
int main() {
unsigned char c;
DDRA=0xff; /* all output */
DDRB=0xff; /* all output */
/* if bit is low, led is on */
PORTB = 1; /* all led's on */
serial_init();
c = serial_recv(); /* get in sync */
for (c=' '; c<'X'; c++) serial_send(c);
serial_send('\n');
for (c='X'; c<'~'; c++) serial_send(c);
serial_send('\n');
serial_send('\n');
serial_print("0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
serial_print("0123456789-abcdefghijklmnopqrstuvwxyz\n");
serial_print("0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
serial_print("0123456789-abcdefghijklmnopqrstuvwxyz\n");
while(1) {
c = serial_recv(); /* get char */
serial_send(c); /* and echo it */
}
return 0;
}