[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] uart problem with atmega 128 -> Solution
From: |
Jean François BOUTILLON |
Subject: |
[avr-gcc-list] uart problem with atmega 128 -> Solution |
Date: |
Sun, 16 Nov 2003 18:54:20 -0000 |
Thanks to tod, I found the solution. I was using a IAtWorf from bergmann
electronic, with pony prog to program my atmega.
The problem was in the fuses the were indicating the the atmega was in 103
compatibility mode.
To change the fuses with ponyprog, just go to the menu "command/security and
configuration bits".
Thanks to tod
/*************************************************************/
Hi all.
I have a problem with my uart on atmega 128.
I try to make s simple program that just echoes the character it receives.
The soure of the program is belox.
The program works ok (the =charactes are echoed) BUT thr program restarts
each time a character is sent (the green led blinks each time a character
is
sent).
Does anyone knows why the orogram restarts ?
Thanks a lot
Jeff
Source of the code :
/************************************************************/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#define ON(X) outp(1<<(X), PORTB)
#define OFF() outp(0, PORTB)
#define F_CPU 16000000 /* 16Mhz */
#define UART_BAUD_RATE 9600 /* 9600 baud */
#define PAUSE() {unsigned char i,j;for(i=0;i<255;i++)for(j=0;j<255;j++);}
#define UART_BAUD_SELECT (F_CPU/(16*UART_BAUD_RATE)-1)
typedef unsigned char u08;
typedef char s08;
SIGNAL(SIG_UART0_RECV)
{
u08 recu=inp(UDR0);
outp(recu,UDR0);
}
int main(void)
{
// Port B as output
outp(0xff ,DDRB);
// initialize UART
outp((1<<UCSZ01)|(1<<UCSZ00),UCSR0C);
outp((u08)UART_BAUD_SELECT, UBRR0L);
outp((1<<RXEN0)|(1<<RXCIE)|(1<<TXEN0),UCSR0B);
sei();
// Make green led blink once
ON(4);PAUSE();OFF();
for (;;)
{
// make red led blink
PAUSE();PAUSE();ON(6);PAUSE();PAUSE();OFF();
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-gcc-list] uart problem with atmega 128 -> Solution,
Jean François BOUTILLON <=