Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

What is wrong with this?

What is wrong with this?

2008-01-27 by dlc

Hi all,

   I'm using AVR-GCC 4.0.2 with the most recent avr-libc and a target of 
a 90S2313 with this code for a toy "blink the LED" thing.  It builds, 
avrdude downloads it fine, and it doesn't do a blasted thing.  Similar 
code with Bascom/AVR downloaded using avrdude works fine.  Now, this 
isn't the first AVR target I've done with avr-gcc, they all worked, this 
one doesn't.

   Can someone suggest which god I forgot to make a sacrifice to to get 
this to work correctly?  I'm at a loss here.

thanks,
DLC

/*
  * puky.c  Code file to test working with 90S2313
  *
  */

#undef F_CPU
#define F_CPU 10000000UL

#include <avr/io.h>
#include "puky.h"

#define BAUD 9600L
#define BAUD_RR ((F_CPU/(16L*BAUD)) - 1)

int main(void)
{
	initialize();
	
	PORTB = 255;
	while(1)
	{
		waitms(100);
		PORTB = ~PINB;
	}
}

void initialize()
{
	DDRB = 0xAF;
	DDRD = 0xF8;
	//TMR0
	TCCR0 = 0x03;		// prescale/64 6.4us per tic
	TCNT0 = 0;		// clear the timer
	
	ACSR = 0x80;		// turn off the comparitor
}

void waitms(unsigned char d)
{
	int delay;
	
	TCNT0 = 98;
	for (delay=0;delay<d;delay++)
	{	
		while (TCNT0);
		TCNT0 = 98;
	}
}

-- 
-------------------------------------------------
Dennis Clark          TTT Enterprises
www.techtoystoday.com
-------------------------------------------------

Re: [AVR-Chat] What is wrong with this?

2008-01-27 by John Samperi

At 02:47 PM 27/01/2008, you wrote:
>#define F_CPU 10000000UL

Is it a 10MHz chip? (90S2313-10)
Are you running it at 5V?
I'm guessing you have a 10MHz crystal or it would not program.

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: [AVR-Chat] What is wrong with this?

2008-01-27 by dlc

Yup,

10MHz crystal, 5V Vdd.  One compiler (The Bascom one) works, avr-gcc 
does not.  There is no particular magic involved with an AVR chip and 
I've used these for years with no issue with Bascom and Codevision, I'm 
a bit puzzled why the avr-gcc one doesn't.  The next step is obvious of 
course, time to dig into the assembly to see what was created and see 
what went wrong.  But before I waded into the tangle that most compilers 
make of their code I thought that I'd ask if anyone else has heard of 
such a thing...

Thanks,
DLC

John Samperi wrote:
> At 02:47 PM 27/01/2008, you wrote:
>> #define F_CPU 10000000UL
> 
> Is it a 10MHz chip? (90S2313-10)
> Are you running it at 5V?
> I'm guessing you have a 10MHz crystal or it would not program.
> 
> Regards
> 
> John Samperi
> 
> ********************************************************
> Ampertronics Pty. Ltd.
> 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> Tel. (02) 9674-6495       Fax (02) 9674-8745
> Email: john@ampertronics.com.au
> Website  http://www.ampertronics.com.au
> *Electronic Design * Custom Products * Contract Assembly
> ********************************************************
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 

-- 
-------------------------------------------------
Dennis Clark          TTT Enterprises
www.techtoystoday.com
-------------------------------------------------

Re: [AVR-Chat] What is wrong with this?

2008-01-27 by John Samperi

At 04:08 PM 27/01/2008, you wrote:
>a bit puzzled why the avr-gcc one doesn't.

It probably "optimized" your code away as it thinks
you don't really want some bits and you wrote it just
for fun.

Something about certain things not being declared volatile,
whatever that means....Seems to happen a lot. :-(

Does the same code run with CAVR? (with the proper mods)


Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: [AVR-Chat] What is wrong with this?

2008-01-27 by dlc

I found part of it.  One spot in the AVR plugin was set to Mega16 
instead of 90S2313.  Once that was changed then it compiled, downloaded 
and ran properly.  But NOW it refuses to program again, even with a -F 
(force) in avrdude.  Avrdude defaults (and I don't change this) to 
"safe" mode and won't let you change the fuses unless you explicitly say 
to, so the fuses have not been changed, but I still can't get it to take 
a program now.  Some days are like this...

thanks all,
DLC

dlc wrote:
> Yup,
> 
> 10MHz crystal, 5V Vdd.  One compiler (The Bascom one) works, avr-gcc 
> does not.  There is no particular magic involved with an AVR chip and 
> I've used these for years with no issue with Bascom and Codevision, I'm 
> a bit puzzled why the avr-gcc one doesn't.  The next step is obvious of 
> course, time to dig into the assembly to see what was created and see 
> what went wrong.  But before I waded into the tangle that most compilers 
> make of their code I thought that I'd ask if anyone else has heard of 
> such a thing...
> 
> Thanks,
> DLC
> 
> John Samperi wrote:
>> At 02:47 PM 27/01/2008, you wrote:
>>> #define F_CPU 10000000UL
>> Is it a 10MHz chip? (90S2313-10)
>> Are you running it at 5V?
>> I'm guessing you have a 10MHz crystal or it would not program.
>>
>> Regards
>>
>> John Samperi
>>
>> ********************************************************
>> Ampertronics Pty. Ltd.
>> 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
>> Tel. (02) 9674-6495       Fax (02) 9674-8745
>> Email: john@ampertronics.com.au
>> Website  http://www.ampertronics.com.au
>> *Electronic Design * Custom Products * Contract Assembly
>> ********************************************************
>>
>>
>>
>>  
>> Yahoo! Groups Links
>>
>>
>>
> 

-- 
-------------------------------------------------
Dennis Clark          TTT Enterprises
www.techtoystoday.com
-------------------------------------------------

Re: [AVR-Chat] What is wrong with this?

2008-01-27 by John Samperi

At 02:47 PM 27/01/2008, you wrote:
>                 while (TCNT0);

By the way is the above correct? I don't speak Martian too
well.

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: [AVR-Chat] What is wrong with this?

2008-01-27 by dlc

Yeah, it is a primitive wait routine - It is set to overflow after 1ms, 
it rolls over to zero where the while() fails.  Since this is pretty 
much just banged out I've not been too complete with comments.  ;)

DLC

John Samperi wrote:
> At 02:47 PM 27/01/2008, you wrote:
>>                 while (TCNT0);
> 
> By the way is the above correct? I don't speak Martian too
> well.
> 
> Regards
> 
> John Samperi
> 
> ********************************************************
> Ampertronics Pty. Ltd.
> 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> Tel. (02) 9674-6495       Fax (02) 9674-8745
> Email: john@ampertronics.com.au
> Website  http://www.ampertronics.com.au
> *Electronic Design * Custom Products * Contract Assembly
> ********************************************************
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 

-- 
-------------------------------------------------
Dennis Clark          TTT Enterprises
www.techtoystoday.com
-------------------------------------------------

Re: [AVR-Chat] What is wrong with this?

2008-01-27 by John Samperi

At 04:27 PM 27/01/2008, you wrote:
>  won't let you change the fuses unless you explicitly say
>to, so the fuses have not been changed,

Not many fuses to change in the 90S chips, maybe just the lock bits.

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.