Dont see the outout on LED pins..

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include 

int main (void)
{
  DDRB = 0xFF; // Set all LEDs as output

  
  PORTB |= 0xFF; //  the LED

       
}

Hi guys, I was testing my atmega32 development board with the above code to glow the LED's that are connected to PB4, PB5, PB6, PB7.

After I flash the code using avrdude, I dont see the LEDs glow at all. If I check the Port B's pins with a multimeter, I read around 3.5V on the pins 4,5,6,7 of portB and 0.5V in the remaining of the portB pins..

I have no clue why I dont read high on all the portB pins. I have another code written in assembly, whose hex I've attached with this post.. This hex could glow the LEDs..

Can anyone tell me what is the possible reason..?

Quote:
avr-gcc -mmcu=atmega32 aim.c -o aim.hex

is the options I use to build the hex file.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are yor LEDs connected to be active high or active low? As for the port bits, I cannot think of why only half the pins went high, my guess is you have an error in assembly of your board or possibly a design error if you made the lard yourself.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yaswanth2008 wrote:
Quote:
avr-gcc -mmcu=atmega32 aim.c -o aim.hex
You can't create a hex file with that command, it will be a elf file with a strange name.

Use a IDE or make with a makefile.

Edit: object -> elf, since there is no -c.

Last Edited: Mon. Oct 1, 2012 - 06:41 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for the advice.

I had to convert the file to herx using this command. and it seems like working until I never see the LEDs glow ..

Quote:
avr-objcopy -O ihex aim2.o aim2.hex

By the way, my LEDs are connected active low, does that mean, Im supposed to set the pins as inputs in DDRB ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Im supposed to set the pins as inputs in DDRB
No, it means that you write a ZERO to the port bit instead of a ONE. And I hope you have series resistors with your leds.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@js,
Thanks for the help. Yea I have series resistors with my leds. its a dev board, they made sure that all these trivialities are taken care of..
By the way, I got my leds Glowing, blinking and all sorts of things.. Now, its time to turn some DC motors..

Thanks a lot guys, I will keep my doubts posted..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
avr-objcopy -O ihex aim2.o aim2.hex 

A very bad idea - no .data initialisers so as soon as you use initialised globals you will have problems.

Why type theses commands by hand? That's the whole point of using a Makefile and it will have sensible rules adding the necessary -R's or -j's to the objcopy command.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

avr-objcopy -O ihex aim2.o aim2.hex 

A very bad idea - no .data initialisers so as soon as you use initialised globals you will have problems.

No -R and no -j means "everything" and that includes .data.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK then the other way round - as soon as he uses EEMEM he is stuffed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

... if you made the lard yourself.

http://www.spain-in-iowa.com/201...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you lost me on that one Lee

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yaswanth2008 wrote:

#include 

int main (void)
{
  DDRB = 0xFF; // Set all LEDs as output
  
  PORTB |= 0xFF; //  the LED
       
}

First, you shouldn't let main return - put an infinite loop in main so the function never returns. That's standard embedded practice.

Second, it's better when testing these things to write both 1s and 0s to the LED port. For example, you could write PORTB = 0x03. Then either 6 LEDs would turn on (LEDs are active low) or 2 LEDs would turn on (LEDs are active high). Saves a lot of confusion if you're not 100% sure of the LED polarity.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

you lost me on that one Lee


;) Hey, I grew up on a farm, and participated in hog butcherings. One of the activities was to render the lard.

Now, I'd assume that the quote intended "board" but came out "lard".

I probably haven't done it for nearly 50 years but the discussion in the link of the "leaf fat" brought back memories.

If the lard rendering makes you queasy then you probably don't want to know too much about "head cheese"...
http://www.cooks.com/rec/view/0,...
http://www.wisegeek.com/what-is-...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey Guys.. This is the code I used to blink the LEDs

#include 

int main (void)
{
   DDRB |= (1 << 5); // Set LED as output

  TCCR1B |= (1 << CS10); // Set up timer
  int sleep = 0;
 

   while(1)
   {
      // Check timer value in if statement, true when count matches 1/20 of a second
      if (TCNT1 >= 59999 )
      {
         TCNT1 = 0; // Reset timer value
         if (sleep == 10)
	 {
           sleep =0;
           PORTB ^= (1 << 5);
	 
         }
         else
           sleep ++;      
      }
    
   } 
}

And can anyone share with me a link or article on how to write a makefile for avr projects ? Is there a tutorial on our forum ?

Thank you

Last Edited: Wed. Oct 3, 2012 - 10:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
how to write a makefile
Are you not using Studio? If so why do you want the additional headache of understanding a makefile when Studio does it for you?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
"a link or article on how to write a makefile for avr projects ?"

The first solution (js's one) is to have a makefile automagically and reliably written... It is the best solution if one doesnot intend to edit/maintain many makefiles...

Another solution is to start from a well written makefile, understand it and modify it if needed (I usually add three options -for avrs and PCs- , "archive" -based on tar and date- "joli"/ "pretty" (based on indent) and "imprime" -print based on a2ps and ps2pdf- to existing makefiles).

The point is to understand what exists:

* wikipedia (in English) is quite clear to begin...

* http://www.gnu.org/software/make... is very well written (ca 192 pages) and exhaustive.

* and I am lucky enough to have http://gl.developpez.com/tutorie... (in French -google can translate it, I suppose, but there is a copyright...- , less than 25 pages with examples : I could not find a good tutorial in English).
Nota : examples may be felt redundant when one starts with an existing makefile...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alternatively look at using Mfile. This comes with a pre-written template that covers 99.9% of everything you might usually want to do in an avr-gcc project. There is also a GUI interface program that runs in both Windows and Linux (it's written in Tk/Tcl). It loads the template then through a series of menu entries you can go through the items that need to be edited for a project (type of AVR, speed, name of source files, name of output project) and it fills in the right fields in the template. Finally you save the output as "Makefile" and you are good to go. For example its rule for making the .hex file is:

# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
	@echo
	@echo $(MSG_FLASH) $@
	$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@

So it's already thought out the right -R's to use here for example.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is a small/tiny issue if one uses Mfile and has an at90usb162 mcu (other, more powerful at90usb-s might be affected, too) , as it is not supported in their menu -I launch it without any problem from cygwin wish85 mfile.tcl
I believe the fix is trivial - add a line to a tcl entity named "devicelist" I did not see any weird generation of Makefile... but it might shy away.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I believe the fix is trivial - add a line to a tcl entity named "devicelist"

Or just edit in the -mmcu type in the maefile by hand. MFile even has an option to allow for manual editing of the file. Yes, you need to know what you're doing but if you're careful then I believe you could do the -mmcu fix by hand.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Or just edit in the -mmcu type in the maefile by hand. "
This is not the best choice, as one often has the same kind of mcu, making menu driven softs interesting (I adapted Makefiles for other MCUs to my at90usb162 : I know it can be done but typos are unpleasant to correct -likely to be detected by avr-gcc, anyway-..)

I verified it did the -mmcu fix... and nothing else.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll put in a plug for my LUFA build system here - it's modular, documented and (theoretically at least) tracks dependencies properly (where the old WinAVR template doesn't). You just need the folder here:

https://github.com/abcminiuser/l...

And then you can write makefiles like this:

https://github.com/abcminiuser/l...

Which should be fairly easy to follow. Advantages of my scripts over the WinAVR template:

- Modular design, so you can update or add your own modules
- Tracks dependencies better, so changes to the makefile force a rebuild as expected
- Supports more programming utilities and bootloaders
- Simpler user application makefiles
- Automatic generation of possible targets as modules are added
- Ability to lump in all source files together, and have the build module sort out C/C++/ASM code
- Much more human friendly errors (instead of the infamous "no rule to make target [x]" error, you get "Source file [x] does not exist")
- Support for parallel building under Linux
- Supports UC3, XMEGA and AVR8 architectures

If you aren't using LUFA, you can just dummy out the LUFA specific parameters.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yaswanth2008:
Your last code will not blink the Led.
Try this

#include 

#define prescaler1 1024

// timer1_top = time[sec] *  F_CPU / prescaler
#define timer1_top  (0.5 * F_CPU / prescaler1) // for 0.5 second


//----------------- MAIN ------------------
int main (void)
{
   DDRB   |= (1<<5);              // Set LED as output
   TCCR1B |= (1<<CS10)|(1<<CS12); // Set up timer, prescale=1024

   while(1)
   {
      // Check timer value, true after 0.5 sec
      if (TCNT1 >= timer1_top )
      {
         TCNT1 = 0;               // Reset timer value
         PORTB ^= (1<<5);         // Invert PORTB.5
      }
   }
} 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
Are you not using Studio? If so why do you want the additional headache of understanding a makefile when Studio does it for you?

I started working on my linux machine as a part of learning open source program. I dont think AVRstudio works on Linux.
Even if it works, I would still try to write my own makefile, which gives me more insight on what Im doing..

And, I think my code blinks the LED. Just a small glitche.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I dont think AVRstudio works on Linux.

Maybe not but this archive containing Mfile does:

http://www.wrightflyer.co.uk/avr...

(you may also need to "sudo apt-get install tk" to be able to execute ./mfile.tcl)