avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] uart problem with atmega 128


From: Jean François BOUTILLON
Subject: [avr-gcc-list] uart problem with atmega 128
Date: Fri, 14 Nov 2003 09:49:13 -0000

 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();
  }
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]