Forum Index > Projects > Other projects
 New guy trying to blink a led
 |  Printable Version
By: Anonymous: Joe () on Sunday, August 08 2010 @ 06:28 PM PDT (Read 4080 times)  
Anonymous: Joe

I'm trying to learn this embedded stuff, using a 2313 target board, and I'm having a hard time figuring out what I'm doing wrong. I've been a software developer for 20+ years now, mostly with some kind of Unix/linux, so this is a new world for me. Sorry if I'm doing something dumb.

Anyway, I'm trying to run the following program, copied from the Adafruit tutorial

PHP Formatted Code

00003 #include <avr/io.h>
00004
00005 // define what pins the LEDs are connected to.
00006 // in reality, PD6 is really just '6'
00007 #define LED PD6
00008
00009 // Some macros that make the code more readable
00010 #define output_low(port,pin) port &= ~(1<<pin)
00011 #define output_high(port,pin) port |= (1<<pin)
00012 #define set_input(portdir,pin) portdir &= ~(1<<pin)
00013 #define set_output(portdir,pin) portdir |= (1<<pin)
00014
00015 // this is just a program that 'kills time' in a calibrated method
00016 void delay_ms(uint8_t ms) {
00017   uint16_t delay_count = F_CPU / 17500;
00018   volatile uint16_t i;
00019
00020   while (ms != 0) {
00021     for (i=0; i != delay_count; i++);
00022     ms--;
00023   }
00024 }
00025
00026 int main(void) {
00027   // initialize the direction of PORTD #6 to be an output
00028   set_output(DDRD, LED);  
00029
00030   while (1) {
00031     // turn on the LED for 200ms
00032     output_high(PORTD, LED);
00033     delay_ms(200);
00034     // now turn off the LED for another 200ms
00035     output_low(PORTD, LED);
00036     delay_ms(200);
00037     // now start over
00038   }
00039 }
 



I fixed the misplaced semicolon at line 21, but didn't change it otherwise.

I've tried it with a led connected to the right pin, but nothing happens. I've also checked the pins with my multimeter and the only ones which show any voltage are vcc and reset. Avrdude says it programs the chip successfully, but that's all the good news I get.

So I've been doing some reading and I'm wondering if I need some kind of bootloader on the chip to load the program. How is this supposed to work?

Thanks for any enlightenment.

Joe





       
   
By: Windell (offline) on Monday, August 09 2010 @ 02:34 AM PDT  
Windell

I presume that you're using an ISP programmer like the USBtinyISP, or some such; no bootloader is needed.

You can certainly start a lot simpler than that. How about something like

PHP Formatted Code
#include <avr/io.h>
int main(void) {
DDRD = 255;
PORTD = 255;
}


or the same, but with PORTD set low? Those kinds of tests will eliminate most of the things that can go wrong in the code. If your chip is programmed with that, you should definitely see the PORTD pins all go high, or low, such that you can read it with the multimeter. And that will eliminate most of the things that can go wrong in hooking up an LED.

You should also know that the AVR pins can put out enough current to break most standard LEDs-- depending how you hook up your LED things may go well or not.



Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: Anonymous: Joe () on Monday, August 09 2010 @ 02:53 PM PDT  
Anonymous: Joe

Quote by: Windell

I presume that you're using an ISP programmer like the USBtinyISP, or some such; no bootloader is needed.

You can certainly start a lot simpler than that. How about something like

PHP Formatted Code
#include <avr/io.h>
int main(void) {
DDRD = 255;
PORTD = 255;
}




Yes, I'm using a USBtiny. I tried this program too, but still none of the pins registers voltage. Would I need to set fuse bits or anything like that? I've got one of your 2313 business-card-size target boards. I'm pretty sure I didn't mess up the soldering, and I am getting voltage showing on the VCC and reset pins.

Do I need to add something to the board besides the six-pin header and the chip itself? I also added some .1uF capacitors if that matters.

Thanks

Joe





       
   
By: Windell (offline) on Monday, August 09 2010 @ 04:08 PM PDT  
Windell

You shouldn't need anything besides the chip, header, and a power source for this to work. Not even the cap.

Your fuses should be set to the default values. It's certainly possible to mess things up with a "proper" choice of fuse settings.

There's very little that can go wrong here, so forgive me if I suggest some obvious stuff:
1) I don't know what (if anything) is in your makefile. Could be bad stuff in there, potentially. Our Larson Scanner kit is based on the '2313 and features an LED from PD6 to ground, you might try it and its known-working makefile for compiling and programming your chip:

http://www.evilmadscientist.com/source/ix/larson.zip

2) I have on occasion failed to notice a compile error. Make sure to "make clean" between attempts at programming to avoid this.

3) Any chance that avrdude is secretly reporting an error, and you've just not detected it?


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: Anonymous: Joe () on Monday, August 09 2010 @ 06:32 PM PDT  
Anonymous: Joe

Quote by: Windell

You shouldn't need anything besides the chip, header, and a power source for this to work. Not even the cap.

Your fuses should be set to the default values. It's certainly possible to mess things up with a "proper" choice of fuse settings.

There's very little that can go wrong here, so forgive me if I suggest some obvious stuff:
1) I don't know what (if anything) is in your makefile. Could be bad stuff in there, potentially. Our Larson Scanner kit is based on the '2313 and features an LED from PD6 to ground, you might try it and its known-working makefile for compiling and programming your chip:

http://www.evilmadscientist.com/source/ix/larson.zip

2) I have on occasion failed to notice a compile error. Make sure to "make clean" between attempts at programming to avoid this.

3) Any chance that avrdude is secretly reporting an error, and you've just not detected it?



Ah, I've got PB4 PA0 and PA1 showing voltage now. Not sure I understand the code quite yet (I'm still learning to read data sheets), but I've got something that works to go from.

I notice that the fuse setting changed after running the makefile. lfuse was previously 64, and now it's 62, whatever that means.

Anyway, thanks very much. I really appreciate the help.

Joe





       
   
By: Windell (offline) on Tuesday, August 10 2010 @ 03:23 PM PDT  
Windell

I'm glad to hear that you've got it working.

The fuse change moved it from using the 8 MHz internal oscillator to the 4 MHz internal oscillator, with the divide-by-8 enabled. In other words, this configuration gives it an ultra-low-power 512 kHz clock source. (Power consumption is typically linear with clock rate.)

Check out http://www.engbedded.com/fusecalc for help with configuring AVR fuses. Big Grin


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   



 All times are PDT. The time is now 02:55 PM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to Post 
Filtered HTML Allowed 
Censored Content 

Evil Mad Scientist Forum Archives — Read only!

Please visit our new forums for new discussions.


DIY Hardware for Electronic Art


The Original Egg-Bot Kit


Octolively
Interactive LED kits


Meggy Jr RGB
LED matrix game
development kit.


Business-card sized
AVR target boards


Peggy 2
LED Pegboard kits

My Account






Lost your password?