1
\$\begingroup\$

I'm learning to program an atmega328p using a usbasp programmer. I'm using this datasheet, page 2, PDIP pin configuration. The usbasp programmer I'm using is this. The armega328p chip I am using is one of these.

My program:

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

int main(void)
{
    DDRB = 0b00000001;

    for (;;) {
        PORTB = 0b00000001;
        _delay_ms(2000);
        PORTB = 0b00000000;
        _delay_ms(2000);
    }

    return 0;
}

which I compiled by doing:

avr-gcc -std=gnu99 -Os -Wall -mmcu=atmega328p -DF_CPU=1000000UL main.c -o main.elf
avr-objcopy -O ihex -j .text -j .data main.elf main.hex

Then tried to upload using:

avrdude -p atmega328p -c usbasp -P usb -D -U flash:w:main.hex:i

which results in

avrdude error: program enable: target does not answer (0x01)
avrdude error: initialization failed, rc=-1
        - double check the connections and try again
        - use -B to set lower the bit clock frequency, e.g. -B 125kHz
        - use -F to override this check

My connections are:

enter image description here

My breadboard looks like:

enter image description here

\$\endgroup\$
8
  • \$\begingroup\$ It's hard to see, but it looks like RESET and SCK are connected the wrong way. \$\endgroup\$
    – MiNiMe
    Oct 27, 2023 at 2:45
  • \$\begingroup\$ The brown (RESET) wire is next to the blue one (with a gap between), the white wire which is SCK, is between the orange and the brown. Orange is the connected to the very last socket. \$\endgroup\$
    – kovac
    Oct 27, 2023 at 2:51
  • \$\begingroup\$ Then perhaps this is what's messing it up: Atmega328p Microcontroller with Uno R3 Bootloader || Isn't that bootloader preset for external 16 MHz oscillator? \$\endgroup\$
    – MiNiMe
    Oct 27, 2023 at 3:03
  • \$\begingroup\$ Oh... if this is the case do I need an external oscillator to do anything with it? Or can I remove the bootloader and perhaps burn a different one? \$\endgroup\$
    – kovac
    Oct 27, 2023 at 3:17
  • \$\begingroup\$ The chip will use the external clock that is 0 MHz, so you have a moment 22. You need an external oscillator circuit for this. One simple solution is using an Uno with socketed 328p, so you can swap in this chip. \$\endgroup\$
    – MiNiMe
    Oct 27, 2023 at 3:22

1 Answer 1

1
\$\begingroup\$

From following the link you provided it gives that the MCU comes with a bootloader for the Uno R3. That means a 16 MHz external oscillator is set and must be used in order to use the MCU.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.