Problem with simple Hello World

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

Hi,

 

After a number of Arduino Uno projects I decided to move on to programming an ATMega328p MCU. So I am still a total noob at this. I'm having issues with hello world. The code I am using is the following

#define F_CPU 1000000UL

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
    DDRB |= _BV(DDB0); 

    while(1) 
    {
        PORTB ^= _BV(PB0);
        _delay_ms(500);
    }
}

I understand what it does but it doen't seem to blink the LED. My setup is as follows

setup

 

So the black wire is attached to GND. The red wire is attached to PB0. In order to program the MCU I'm using the AVRISPmkII and I am executing the following commands in order to get it on the chip.

avr-gcc -Os -Wall -mcall-prologues -mmcu=atmega328p -fno-exceptions -o main main.c
avr-objcopy -R .eeprom -O ihex main main.hex
avrdude -p m328p -P usb -c avrispmkII flash:w:main.hex

The output of running this is

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Thanks for your help!

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

Well it seems like I was using wrong commands. I changed them to

avr-gcc -Wall -Os -mmcu=atmega328p -o main main.c                  
avr-objcopy -j .text -j .data -O ihex main main.hex                    
sudo avrdude -c avrisp2 -p atmega328p -P usb -U flash:w:main.hex:i

and now it seems to work (as long as I dont disconnect my AVRISPmkII). anyway sorry about that. I tried deleting my post but I don't know how.

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

Congratulations on your quick success and welcome to the New AVRfreaks forum

Imagecraft compiler user