First attempt on Attiny2313 with Raspberry Pi, LED turned on, but doesn't blink

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

Hi, newbie here

 

i'm trying to program attiny2313 using raspberry pi via SPI connection. Here i'm just trying to blink an LED. The HEX file from my source code is uploaded successfully to the MCU, The LED is turned on but the problem is it's not blinking. I need help finding out the main cause, i've tried changing the F_CPU, but that doesn't work, please help.

 

here's my source code :


#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void) {
    DDRB = 0xff;
    PORTB = 0x00;
    for(;;) {
        PORTB ^= 0xff;
        _delay_ms(1000);
    }
    return 0;
}


 

and this is the makefile :

 

all:
    avr-gcc -Os -mmcu=attiny2313 -Wall -c main.c -o main.o
    avr-objcopy -O ihex main.o main.hex

upload:
    gpio -g mode 22 out
    gpio -g write 22 0
    avrdude -p t2313 -P /dev/spidev0.0 -c linuxspi -U flash:w:main.hex
    gpio -g write 22 1

clean:
    rm -rfv main.o
    rm -rfv main.hex

 

Formatted code for clarity - JGM

This topic has a solution.

Last Edited: Sun. May 24, 2015 - 02:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The program should end with infinite loop put while(1); at the end.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your source code is just fine.   The for(;;) ensures that the loop is repeated forever.   

It is wise to put a catch-all while(1); at the end of a main() but not strictly necessary.    The startup code disables interrupts and provides the catch-all anyway.

 

The biggest problem is your avr-gcc command.

 

Just look at the real avr-gcc commands from a proven IDE or Makefile.

You need to produce an ELF file.

 

David.

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

 

The objcopy is wrong. You either want -j's or -R's

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

Thanks a lot for the advice guys, the LED is finally blinking now yes

 

here are the changes i've made in the makefile :

 

all:
    avr-gcc -g -Os -mmcu=attiny2313 -Wall -c main.c
    avr-gcc -g -mmcu=attiny2313 -o main.elf main.o
    avr-objcopy -j .text -j .data -O ihex main.elf main.hex

upload:
    gpio -g mode 22 out
    gpio -g write 22 0
    avrdude -p t2313 -P /dev/spidev0.0 -c linuxspi -U flash:w:main.hex
    gpio -g write 22 1

clean:
    rm -rfv main.o
    rm -rfv main.hex
    rm -rfv main.elf