Electronic – AVR ATMEGA328p Blinking Example

atmegaavr

I wanted to test a simple blinking script on my ATMEGA328p. The breadboard setup (tested and works fine). But the LED does not blink. I probed the voltages across the board and they are showing up with 5V as expected. The avrdude response is also expected. Just the LED does not blink. I switched the chip too, but this doesn't have any effect. Do you have any ideas?

I also measured the LED pin but there is 0V on the pin and I would expect it changing to 5V with the code provided.

enter image description here

code.c

#ifndef F_CPU
#define F_CPU 1000000UL
#endif

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

int main(void) {
  DDRB = 0b00000001;

  while (1) {
    PORTB = 0b00000001;
    _delay_ms(1000);
    PORTB = 0b00000000;
    _delay_ms(1000);
  }

  return 0;
}

I created a compile script:

compile

#!/bin/bash
avr-gcc -g -Os -mmcu=atmega328p -c code.c
avr-gcc -g -mmcu=atmega328p -o code.elf code.o
avr-objcopy -j .text -j .data -O ihex code.elf code.hex
avr-size --format=avr --mcu=atmega328p code.elf

and flashed file to the ATMEGA

avrdude -c usbtiny -p m328p -U flash:w:code.hex

the AVRDUDE output:

avrdude: Version 6.3, compiled on Sep 21 2018 at 19:15:33
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/usr/local/Cellar/avrdude/6.3_1/etc/avrdude.conf"
         User configuration file is "/Users/sebastianscharf/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbtiny
avrdude: usbdev_open(): Found USBtinyISP, bus:device: 020:012
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: Using SCK period of 10 usec
avrdude: reading input file "code.hex"
avrdude: input file code.hex auto detected as Intel Hex
avrdude: writing flash (178 bytes):

Writing | ################################################## | 100% 0.29s

avrdude: 178 bytes of flash written
avrdude: verifying flash memory against code.hex:
avrdude: load data flash data from input file code.hex:
avrdude: input file code.hex auto detected as Intel Hex
avrdude: input file code.hex contains 178 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.21s

avrdude: verifying ...
avrdude: 178 bytes of flash verified

avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:D9, L:62)

avrdude done.  Thank you.

Best Answer

By accident I found out when measuring with the multimeter that the breadboard had a connectivity issue, by accidently touching the LED and the PB0 pin. Now changed the breadboard and all works. Thanks everyone.