Yahoo Groups archive

AVR-Chat

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

Thread

AT-Mega8535

AT-Mega8535

2008-06-04 by Riccardo Castellani

I have both AVR STK-500 board and AVR ISP mkII in-system programmer.
I know some electronic science, C language but no microcontrollers. Now I'm
reading AVR book "programming, customizing AVr microcontrollers" which I
bought in Amazon. I'm going to use AT-Mega8535 chip.
My idea is to design electronic timer to rain my garden driving two
electrovalves. It's necessary calendar which covers 7 days; I'd like raining
my garden twice a day.

What do you suggest me to start ?

1- to having experience on stk500 board or directly building simple circuit
with breadboard using ISP programmer ?
Other suggestions please ?


[Non-text portions of this message have been removed]

Re: [AVR-Chat] AT-Mega8535

2008-06-05 by John Samperi

At 06:02 AM 5/06/2008, you wrote:
>1- to having experience on stk500 board or directly building simple circuit
>with breadboard using ISP programmer ?

The STK500 is a good tool to start off with, especially if
you don't have a lot of experience in bread boarding.

You may need a mix of the 2. As you are likely to misprogram
some fuses, that STK500 will help you in getting things working
again.

A Dragon (or better a JTAG Mk2, more expensive) would be very
handy for debugging your code. The AVRISP is not really needed
as the STK can do your ISP and HVPP programming (when disaster strikes).






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: AT-Mega8535

2008-06-05 by Graham Davies

--- In AVR-Chat@yahoogroups.com, "Riccardo Castellani" 
<ric.castellani@...> wrote:

> What do you suggest me to start ?
> ... on stk500 board or directly
> building simple circuit with
> breadboard using ISP programmer ?
> Other suggestions please ?

As John says, the STK500 will be a good start.  If you mess up the 
fuses (almost a rite of passage), you can rescue the chip with high 
voltage programming.  I don't think there is on-chip debug on the 
ATmega8535, so an AVR Dragon won't buy you anything.

To construct the extra circuits you need for your application, you 
might consider the STK500 Expansion Board:
http://www.ecrostech.com/AtmelAvr/Stk500Exp/index.htm
which is now in stock again after a hiatus.

Full disclosure: this is my product, so I'm advertising at the same 
time I'm giving advise.  While I'm at it, I might as well mention 
that there is now a version of the STK500 Expansion Board with a 
footprint for a 2 line by 16 character LCD module.

Graham.
http://www.ecrostech.com

Re: AT-Mega8535

2008-06-05 by Graham Davies

--- In AVR-Chat@yahoogroups.com, John Samperi <samperi@...> wrote:

> [An AVR Dragon] will be useful once
> he moves up to Mega164p etc.
> or even Tinyes with DW.

Absolutely.  It's always on the tip of my tongue to yell "No!  That one 
has no on-chip debug!  Throw it away!", but I know that some people get 
along just fine without it.  I think the AVR Dragon is great value for 
money, but I must stop before I begin advertising again ... !

Graham.

Re: [AVR-Chat] Re: AT-Mega8535

2008-06-06 by John Samperi

At 10:42 AM 6/06/2008, Graham Davies wrote:
>I don't think there is on-chip debug on the
>ATmega8535, so an AVR Dragon won't buy you anything.


OOPS... but it will be useful once he moves up to Mega164p etc.
or even Tinyes with DW.



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
********************************************************

AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-07 by Cat Hotmail

Hi,

I'm having this weird problem whereby I am able to debug, and to step 
through the program, but it just ignores/skips some of the lines.

In the code below, I'll show the skipped lines with \\<<< at the end.

Any ideas, please?

Thanks,

Cat


#include <inttypes.h>
#include <avr/io.h>
#include <stdio.h>



volatile uint8_t iMotorPosition[9] = {0, 0b110110, 0b100110, 0b110101, 
0b010101, 0b111001, 0b101001, 0b111010, 0b011010};
volatile uint8_t iOldInput = 0;
uint8_t iBitsChanged = 0;	//moved here because AVRstudio gives "Location not 
valid" when inside "ReadInput"
int8_t iStepX = 1;			//The steps will become negative when direction changes
int8_t iStepY = 1;				//or I'll set them according to the actual HI/LO value
int8_t iStepZ = 1;
int8_t iCurrentStepX = 1;
int8_t iCurrentStepY = 1;
int8_t iCurrentStepZ = 1;


void SetupPorts (void);
void ReadInput(void);


int main (void)
{
	SetupPorts();                    \\<<<
	while(1)
	{
		ReadInput();
	}
}

void ReadInput(void)
{
	uint8_t iNewInput = PIND & 63;	//<<<Read port D and mask (keep) only the 
lower 6 bits \\<<<
	if (iNewInput == iOldInput)
		return;
//Set Step signs
	iStepX = bit_is_set(iNewInput, 0) ? 1 : -1;
	iStepY = bit_is_set(iNewInput, 2) ? 1 : -1;
	iStepZ = bit_is_set(iNewInput, 4) ? 1 : -1;

//Find out which bits changed and act accordingly
	iBitsChanged = iNewInput ^ iOldInput;				//We use "^" (XOR) to check which 
bits have changed
	iOldInput = iNewInput;								//Save New input as Old for next time

//Mask direction bits in iBitsChanged MAYBE NOT NEEDED
	iBitsChanged &= 0b101010;

	if (bit_is_set(iBitsChanged, 1))		//If X-step changed
	{
		if (bit_is_set(iNewInput, 1))		//And if it changed to HI
		{
			iCurrentStepX +=iStepX;
			if (iCurrentStepX == 9)
				iCurrentStepX = 1;
			if (iCurrentStepX == 0)
				iCurrentStepX = 8;
			PORTA = iMotorPosition[iCurrentStepX];
		}
	}

	if (bit_is_set(iBitsChanged, 3))		//If Y-step changed
	{
		if (bit_is_set(iNewInput, 3))		//And if it changed to HI
		{
			iCurrentStepY +=iStepY;
			if (iCurrentStepY == 9)
				iCurrentStepY = 1;
			if (iCurrentStepY == 0)
				iCurrentStepY = 8;
			PORTB = iMotorPosition[iCurrentStepY];
		}
	}

	if (bit_is_set(iBitsChanged, 5))		//If Z-step changed
	{
		if (bit_is_set(iNewInput, 5))		//And if it changed to HI
		{
			iCurrentStepZ +=iStepZ;
			if (iCurrentStepZ == 9)
				iCurrentStepZ = 1;
			if (iCurrentStepZ == 0)
				iCurrentStepZ = 8;
			PORTC = iMotorPosition[iCurrentStepZ];
		}
	}
}

void SetupPorts(void)
{
	DDRD = 0;				//PortD ->Input
	DDRA = 0xFF;			//PortA ->Output X
	DDRB = 0xFF;			//PortB ->Output Y
	DDRC = 0xFF;			//PortC ->Output Z

}

Re: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-07 by Cat Hotmail

Hmmm, I think I figured it out:  It was the optimization setting.
I changed it to "0" and now my lines... work :-)

Cat

--------------------------------------------------
From: "Cat Hotmail" <catalin_cluj@hotmail.com>
Sent: Saturday, June 07, 2008 4:13 PM
To: <AVR-Chat@yahoogroups.com>
Subject: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon 
problem debugging C code (jtag)
Show quoted textHide quoted text
> Hi,
>
> I'm having this weird problem whereby I am able to debug, and to step
> through the program, but it just ignores/skips some of the lines.
>
> In the code below, I'll show the skipped lines with \\<<< at the end.
>
> Any ideas, please?
>
> Thanks,
>
> Cat
>
>

Re: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-07 by dpharris@telus.net

Cat-

Yes, I have had the same problem.  I wish someone in the know would comment.  

Firstly, the compiler appears to optimize out pieces of code that are required,
and without so much as a warning.  It is possible that the compiler move the
your setting of iStepX etc further on in the code to reduce the use of
temporaries.  However, at least in the development phase it is useful to see
what the values are during debugging, and short statements used solely to
monitor a variables value are often optimized out. 

Secondly, the compiler defaults to maximum optomization, which would seem to be
a poor choice since most projects surely start in the debug phase!

David


Quoting Cat Hotmail <catalin_cluj@hotmail.com>:
Show quoted textHide quoted text
> Hmmm, I think I figured it out:  It was the optimization setting.
> I changed it to "0" and now my lines... work :-)
> 
> Cat
> 
> --------------------------------------------------
> From: "Cat Hotmail" <catalin_cluj@hotmail.com>
> Sent: Saturday, June 07, 2008 4:13 PM
> To: <AVR-Chat@yahoogroups.com>
> Subject: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon 
> problem debugging C code (jtag)
> 
> > Hi,
> >
> > I'm having this weird problem whereby I am able to debug, and to step
> > through the program, but it just ignores/skips some of the lines.
> >
> > In the code below, I'll show the skipped lines with \\<<< at the end.
> >
> > Any ideas, please?
> >
> > Thanks,
> >
> > Cat
> >
> >
>  
> 
> 
> ------------------------------------
> 
> Yahoo! Groups Links
> 
> 
> 
>

Re: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-08 by Cat Hotmail

Thank David, it works good now.

Cat

--------------------------------------------------
Show quoted textHide quoted text
From: <dpharris@telus.net>
Sent: Saturday, June 07, 2008 5:15 PM
To: <AVR-Chat@yahoogroups.com>
Subject: Re: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon 
problem debugging C code (jtag)

> Cat-
>
> Yes, I have had the same problem.  I wish someone in the know would 
> comment.
>
> Firstly, the compiler appears to optimize out pieces of code that are 
> required,
> and without so much as a warning.  It is possible that the compiler move 
> the
> your setting of iStepX etc further on in the code to reduce the use of
> temporaries.  However, at least in the development phase it is useful to 
> see
> what the values are during debugging, and short statements used solely to
> monitor a variables value are often optimized out.
>
> Secondly, the compiler defaults to maximum optomization, which would seem 
> to be
> a poor choice since most projects surely start in the debug phase!
>
...

Re: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-08 by John Samperi

At 09:15 AM 8/06/2008, you wrote:
>Secondly, the compiler defaults to maximum optomization, which would 
>seem to be
>a poor choice since most projects surely start in the debug phase!

In the avrfreaks.net site, home of winAvr, it has been claimed the
opposite by people "who know". It was a request by some of these people
that made the latest versions default to -Os instead of the original -O0.

By the way with -O0 some of the stuff does not work.

If things get "optimized" away, or TERMINATED as I claim, probably
something has not been declared volatile. It seems to fix 99% of
the problems.

Ah the joys of working with assembler. :-)


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] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-08 by David Kelly

On Jun 7, 2008, at 5:13 PM, Cat Hotmail wrote:

> I'm having this weird problem whereby I am able to debug, and to step
> through the program, but it just ignores/skips some of the lines.


As you have found when -Os is changed to -O0 all your "lines" appear  
as expected in the debugger. You didn't say whether "skipped" lines  
were executed or not, I suspect they were. Just optimized to where the  
debugger couldn't single out and associate assembly code with source  
code.

To some extent you could use more volatile modifiers to create  
distinct source code line demarcations that will single step debug.

--
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Re: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-09 by Cat Hotmail

Thanks Kelly,
I'm not sure of all that "volatile" does (I know I need it for variables 
that I use both in interrupts and out).
The lines may have been executed, but it's very... not nice when 10 XOR 00 = 
00 because another line has been executed without me knowing.
I may turn optimization back on after I'm finished debugging, I'll see if it 
still works.

Thanks again,

Cat

--------------------------------------------------
From: "David Kelly" <dkelly@hiwaay.net>
Sent: Sunday, June 08, 2008 12:19 PM
To: <AVR-Chat@yahoogroups.com>
Subject: Re: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon 
problem debugging C code (jtag)
Show quoted textHide quoted text
>
> On Jun 7, 2008, at 5:13 PM, Cat Hotmail wrote:
>
>> I'm having this weird problem whereby I am able to debug, and to step
>> through the program, but it just ignores/skips some of the lines.
>
>
> As you have found when -Os is changed to -O0 all your "lines" appear
> as expected in the debugger. You didn't say whether "skipped" lines
> were executed or not, I suspect they were. Just optimized to where the
> debugger couldn't single out and associate assembly code with source
> code.
>
> To some extent you could use more volatile modifiers to create
> distinct source code line demarcations that will single step debug.
>
> --
> David Kelly N4HHE, dkelly@HiWAAY.net
> ========================================================================
> Whom computers would destroy, they must first drive mad.
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

Re: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-09 by David Kelly

On Jun 8, 2008, at 7:00 PM, Cat Hotmail wrote:

> I'm not sure of all that "volatile" does (I know I need it for  
> variables
> that I use both in interrupts and out).


Volatile informs the compiler that the object may change between the  
compiler's uses. Therefore the compiler has to read it immediately  
before use if its value is needed. That it can't trust a copy of the  
variable laying around in a register. And when changing the value it  
must write it out immediately. And not merge the access across  
multiple statements.

If you say:

	volatile uint8_t v;

	v = 1;
	v = 0;
	v = 1;

the compiler is not allowed to notice the end result is v = 1 and skip  
the v = 0 step. With full optimization it just might skip those other  
steps. Thats why I asked if it was performing the skipped lines that  
you could not single-step debug.

--
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Re: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-09 by Cat Hotmail

Thanks David, that's helpful.

All the best,

Cat

--------------------------------------------------
From: "David Kelly" <dkelly@hiwaay.net>
Sent: Sunday, June 08, 2008 6:36 PM
To: <AVR-Chat@yahoogroups.com>
Subject: Re: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon 
problem debugging C code (jtag)
Show quoted textHide quoted text
>
> On Jun 8, 2008, at 7:00 PM, Cat Hotmail wrote:
>
>> I'm not sure of all that "volatile" does (I know I need it for
>> variables
>> that I use both in interrupts and out).
>
>
> Volatile informs the compiler that the object may change between the
> compiler's uses. Therefore the compiler has to read it immediately
> before use if its value is needed. That it can't trust a copy of the
> variable laying around in a register. And when changing the value it
> must write it out immediately. And not merge the access across
> multiple statements.
>
> If you say:
>
> volatile uint8_t v;
>
> v = 1;
> v = 0;
> v = 1;
>
> the compiler is not allowed to notice the end result is v = 1 and skip
> the v = 0 step. With full optimization it just might skip those other
> steps. Thats why I asked if it was performing the skipped lines that
> you could not single-step debug.

Re: [AVR-Chat] AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-09 by Robert Adsett

At 07:36 PM 6/8/2008 -0500, David Kelly wrote:

>On Jun 8, 2008, at 7:00 PM, Cat Hotmail wrote:
>
> > I'm not sure of all that "volatile" does (I know I need it for
> > variables
> > that I use both in interrupts and out).
>
>
>Volatile informs the compiler that the object may change between the
>compiler's uses.

It's a little more than that. That's certainly much of the intent.  What it 
actually means though is that access to a volatile variable must take place 
in the order they are specified and exactly as many times as is specified. 
That's why a volatile write only variable makes sense.

As a consequence of that it gives the behaviour you describe.

It will not deal with issues like hardware caches but that's not a concern 
on AVRs anyway.

Robert

"C is known as a language that gives you enough rope to shoot yourself in
the foot."  -- David Brown in comp.arch.embedded
http://www.aeolusdevelopment.com/

Re: AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-09 by Graham Davies

David Kelly wrote:
> Volatile informs the compiler that
> the object may change between the
> compiler's uses ... And when changing
> the value it must write it out
> immediately. And not merge the access
> across multiple statements.

then, Robert Adsett wrote:
> What it actually means though is that
> access to a volatile variable must
> take place in the order they are
> specified and exactly as many times
> as is specified. 

But, that exactly what David wrote!

Graham.

Re: [AVR-Chat] Re: AvrStudio4 (2008), WinAVR (2007-05...) and Dragon problem debugging C code (jtag)

2008-06-10 by Robert Adsett

At 12:49 AM 6/10/2008 +0000, Graham Davies wrote:
>David Kelly wrote:
> > Volatile informs the compiler that
> > the object may change between the
> > compiler's uses ... And when changing
> > the value it must write it out
> > immediately. And not merge the access
> > across multiple statements.
>
>then, Robert Adsett wrote:
> > What it actually means though is that
> > access to a volatile variable must
> > take place in the order they are
> > specified and exactly as many times
> > as is specified.
>
>But, that exactly what David wrote!

Not quite.  "informs the compiler the object may change between uses" can 
be read to guarantee behaviour volatile does not.  In particular volatile 
does not assure atomic access.

The compiler is also allowed to reorder access's to non-volatile variables 
around the volatile accesses, so if you had a set of volatile writes and 
non-volatile writes in a routine the volatile writes could be optimized to 
be placed anywhere in the routine as long as their order remained the same, 
"must write it out immediately" could be taken as a stronger assurance.

Quibbles to be sure but when you are working with volatile such quibbles 
can mean a broken program.

Robert


"C is known as a language that gives you enough rope to shoot yourself in
the foot."  -- David Brown in comp.arch.embedded
http://www.aeolusdevelopment.com/

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.