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

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

[avr-gcc-list] 163 avr-gcc program problem - resend


From: h c wispell ii
Subject: [avr-gcc-list] 163 avr-gcc program problem - resend
Date: Fri, 17 May 2002 01:41:42 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc2) Gecko/20020510

hi all,

i am having trouble with a simple program running on an atmega163 that echoes any character received on the serial port. the problem is that if the rx/tx portion appears in a separate function, the 163 resets after a few (it varies from 1 to about 15) characters. it works fine if the rx/tx is inline. i am using avr-gcc 3.0.4, binutils-020423 and libc-20020203 on a linux system. the program is compiled with options "-std=gnu99 -Wall -O2 -mmcu=atmega163". to see the problem uncomment cmd() and comment out the inline rx/tx.various combinations of compilation options didn't help. any ideas?


thanks in advance for any help.


clay


#include <io.h>
#include <string.h>
#include <sig-avr.h>
#include <wdt.h>
#include <interrupt.h>


void avr_setup()
{
// disable the UART
outp(0x00, UCSRB);
outp(0x00, UCSRA);

// load the baudrate divisor register; 115200 at 9.216M
outp(4, UBRR);
outp(0, UBRRH);

// enable the UART0 transmitter & receiver
outp(BV(TXEN) + BV(RXEN), UCSRB);

// kill watch dog timer
wdt_disable();

// setup d:7 for led
outp(0x00,PORTD);
outp(0x80,DDRD);

// disable interrupts
cli();

}



void cmd(void);


int main(void)
{
unsigned int i,j;
char *buffer = "avr reset!\n\r";

avr_setup();


// send reset message
for(i=0;i<strlen(buffer);i++)
{
outp(buffer[i],UDR);
loop_until_bit_is_set(UCSRA,TXC);
sbi(UCSRA,TXC);
}


// cheesy led blink
outp(0x80,PORTD);
for(i=0;i<40000;i++)
j=i+1;
outp(0x00,PORTD);


// main loop
while(1)
{
//if(bit_is_set(UCSRA,RXC)) outp(inp(UDR),UDR); // read in character
cmd();
}


return 0; }




void cmd(void)
{
if(bit_is_set(UCSRA,RXC)) outp(inp(UDR),UDR); // read in character
}









avr-gcc-list at http://avr1.org



reply via email to

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