help needed programming atmega328 using USBAsp

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

Hello guys, i am new here and new with avr programming in general. I do have some basic C knowledge and at the moment im having a hard time getting started with AVR programming.

 

I have a bare-metal factory default Atmega328P which i want to program using the internal 8 mhz oscillator with a chinese UsbASP programmer with the name: Van Ooijen Technische Informatica shared ID for use with libusb

 

 

I connected the usbasp according to online schematics. My usbasp has a ISP10Pin which i don't use! But instead im using the 6 ICSP pins which i have connected to SCK, MISO, MOSI, RESET, VCC to + and GND to - on my breadboard. I will post a picture tomorrow if needed

My base program:

#include <avr/io.h>

//#define F_CPU 4000000UL
#define F_CPU 8000000UL
#include <util/delay.h>

int main()
{
	DDRC = 0xFF;		// Configure port C as output

	while(1)
	{
		PORTC = 0xFF;	// Turn ON LEDs
		_delay_ms(250); // Wait 250ms
		PORTC = 0x00;	// Turn OFF LEDs
		_delay_ms(250);	// Wail 250ms
	}

	return 0;
}

 

 

I compiled the file with:
avr-gcc -g -Os -mmcu=atmega328 -c blink.c
avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex
 

AND trying to upload with:
sudo avrdude -c usbasp-clone -p m328 -U flash:w:blink.hex lfuse:w:0x62:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m -F -v 

 

 

The output:
 

avrdude: auto set sck period (because given equals null)
avrdude: error: program enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x886b2e
avrdude: Expected signature for ATmega328 is 1E 95 14

avrdude done.  Thank you.

 

 

So, am i missing something? What am i doing wrong? Is it the programmer, my code? am i missing configurations or something else regarding the Oscillator or the CPU frequency?

This topic has a solution.
Last Edited: Wed. Jul 26, 2017 - 01:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the avrdude command, try using ...-c usbasp ...   instead of  ... -c usbasp-clone...   Then, check your wiring, and check it again.  Then try moving off of a plug-in "breadboard" and onto a point-to-point-wired "sea-of-holes" protoboard.

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

as a bare bones new chip, the internal r/c clock runs at 8MHz, but the clock is divided by 8, so it runs at 1MHz.

To change this, in your program you can change the clock speed using the CLKPR register, or clear the clk/8 fuse, but this is trickier for a novice to do.

So just run it at 1MHz for a few projects then when your ready to go faster, ask how to change the clock fuses.

 

By the way, an Arduino Uno is a great beginners system and even us pro's use them all the time.

 

Good luck and welcome to the Freaks site.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

Thanks for your response! I already tried arduino before but got no response from the chip. It seems like the same problem. And i like to work with universal methods to get deeper insight on chip programmi

in the atmega328p_datasheet i found i have to set the CLKPR register to CLKPR=0x80;

 

So i changed my code to: (Is this how its done?)

int main()
{
	CLKPR=0x80;
	DDRC = 0xFF;		// Configure port C as output

	while(1)

 

I also changed avrdude to -c usbasp instead of usbasp-clone. But with both changed i get the same error

avrdude: auto set sck period (because given equals null)
avrdude: error: program enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x88abd4
avrdude: Expected signature for ATmega328 is 1E 95 14

avrdude done.  Thank you.

 

My wiring looks like this.

I also moved the jumper to LowCLK And im using as seen on the picture the bottom 6 ICSP pins (From left to right) MISO, VCC, SCK, MOSI, RESET, GND. (But it seems that im not getting any power when connecting a led to the vcc and gnd
 

Attachment(s): 

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

The AVR would appreciate a 100nF capacitor across vcc/vdd.

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

Hi Zerco,

 

The first problem I spot is:

avrdude: error: program enable: target doesn't answer. 1 

This usually is a wiring error or when trying to program the AVR too fast.

You can try to add "-B20" to the avrdude command line, even though I suspect this is not your problem because your version of usbASP seems to support the auto set sck function.

(You also seem to use a jumper for the "slow clock" option, which makes it even more unlikely this will help).

 

I was a bit suprised that avrdude didn't stop there, because it can't program a chip if it can't communicate with it.

Please remove the "-F" parameter to stop forcing avrdude to do silly things.

You can see that the read device signature 0x88abd4 is completely wrong.

 

Your usbASP programmer looks unfamiliar to me so it's hard to check for wiring faults.

Have you checked that Vcc works? (with a volt meter).

From your photo It looks like the pinout of your USBasp is:

MISO
VCC
SCK
MOSI
^Reset
GND

Breadboards are notoriously unreliable (but also very handy sometimes) So double check for broken wires, bad connections etc.

 

Next is that the ATmega328 is another processor than the ATmega328p.

So if you have the 'p' version then compile & program for that cpu.

You can find a (pretty big) list of configuration parameters in the file /etc/avrdude.conf

 

I am also not a fan of messing around with the fuses.

Atmel has made a big mess of them with lots of sub combinations and partial tables and the info about them is also spread around all over the datasheets.

My advise is to use a virgin m328p (which runs on 1MHz internal RC oscillator) and remove all fuse parameters from the avrdude command.

Then later only change fuses if you need to change them, not on every program iteration.

If you've changed fuses to an external crystal then you need to add a crystal before you can do anything (inclusive reprogramming) the target uC.

 

I also see no decoupling caps on your breadboard. This is a big NoNo.

Add 2 ceramic capacitors (usually 100nF) between Vcc and GND close to the uC and the 2nd to AVcc &GND)

(Sometimes I solder them directly to pins 7+8 and pins 22+20 for a uC for breadboard use.)

 

At this point I see no need to mess around with CLKPR (though it's harmless).

First get the programmer working.

Also for later:

I see you use sudo avrdude.

A neater way will be to make an udev rule.

You can do this by copying the line below (change "paul" to your user/group) to the file: /etc/udev/rules.d/10-avr.rules

SUBSYSTEM=="usb", ATTR{idVendor}=="16c0", ATTR{idProduct}=="05dc", GROUP="paul", MODE="0666"

I also want to stronly advise to buy a logic analyser.

These are often more usefull for debugging uC circuits and you can get one for about EUR5.

A good search term on Ali is: "24m 8ch" and you will find saleae clones.

https://www.aliexpress.com/item/...

These work with the opens ource Sigrok / Pulseview combination.

http://sigrok.org/wiki/Main_Page

 

Or one of these. They work with 16 channels in sigrok, but do not have input protecton (add yourself).

https://www.aliexpress.com/whole...

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

zerco wrote:
(But it seems that im not getting any power when connecting a led to the vcc and gnd

This can very well be correct.

Sometimes the Vcc pin is used to power the USBasp from the target board.

Sometimes it is an open connection to avoid power supply conflicts between the (usb powered) USBasp and the power supply of the target board.

Sometimes there is a jumper on the USBasp board so the choice is up to the human operator.

 

So first add a led (+ series resistor!) to your breadboard and make Vcc working.

Then move the led to PORTC so you can see it blink if you've finally got your blinking led progarm working.

It's always so satisfieng to see the first blinking led of a new project...

 

Edit:

You seem to have an unpopulated VTRG jumper on your USBasp for this.

PCB trace seems to go to the 4th pin however, so I'm having doubts about your wiring / pin layout.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Wed. Jul 19, 2017 - 10:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey Paul,

 

Thanks for your detailed reply!! I will get one of those logic analyzers. I'm actually still hopelessly trying to program the chip, i reconnected everything on the breadboard to avoid any bad links.
So i populated the VTRG jumper and put a cable on the 10 PINS! ISCP and got power and ground from it.

 

 

Check attachment for scheme. its my first time using this kind of program to produce it.

 

Even though i think the connections are correct (The atmega328P and the usbasp connectors on the top right on the scheme) I still get the same error which is without the -F 

avrdude: auto set sck period (because given equals null)
avrdude: error: program enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

 

 

Attachment(s): 

Last Edited: Wed. Jul 19, 2017 - 12:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the photo, I don't see where the power pins on the top(opposite) side are connected!   All VCC (AVCC) and all GND pins must be powered and have 100nF bypass caps.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

They are connected to the VCC and GND of the USBASP. And they are all connected to 1 100nf capacitor 

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

Ah, I see the power connections now, thanks, BUT

Each VCC/GND pair needs its own 100nF cap and placed as close to the chip as possible!

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

okay now i have 2 100nF capacitors just next to the chip on both VCC/GND (Both sides of the Atmega328P). I also removed the CLKPR and compiled the blink.c specifcally for the atmega328P.

The whole output atm: Is there something obvious there that i don't know?

sudo avrdude -c usbasp -p atmega328p -U flash:w:blink.hex -v  -b 19200 -P usb

avrdude: Version 6.2
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/zerco/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         Overriding Baud Rate          : 19200
         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 : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

 

Last Edited: Wed. Jul 19, 2017 - 02:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you try:

- A virgin m328p without changing any fuses?

- Adding a crystal (should be with cap's, but breadboard capacitance is usually big enough to make it oscillate (although unreliably))).

What else have you tried from my suggestions of the previous post?

 

How much experience do you have with general electronics?

Do you know enough to not connect led's backwards, use (correct) current limiting resistors, etc?

Do you have (access to) an oscilloscope?

 

Next step will be verify that you can toggle pins on your m328p.

Connect the led (+resistor) to the reset output of your programmer.

The ^Reset should be low during programming (verifieing, etc).

Or connect led (Polarity!) to Vcc and the reset pin. You should see at least a brief flash of the led when the ^Reset pin goes low.

(Verify you connected the led right by making the pin low yourself).

 

Adding some counter chip (such as 74HC93 CD4060) can help in verifying that the SCK is being toggled by the programmer.

 

Do you have access to a PC with an old fashioned parallel port or an Raspi / Beaglebone / Cubieboard / etc.

AVRdude supports (emergency / bootstrap) programming via general I/O pins.

 

Your USBasp progammer also looks a bit strange and it's not a bad Idea to have a spare one.

Maybe support Tomas by buying an "official" one for EUR10 http://www.fischl.de/usbasp/

Or one (a few) of the chinese clones.

 

This seems to be the cheapest:

https://www.aliexpress.com/item/...

But I haven't got experience with that version.

Most I have come from "Baite" with the dark silkscreen and the 45 degree rotated avr chip on hem.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

I didn't try a brand new m328p thats not fused.
I did try adding a crystal, 20 Mhz.. with 22 pf caps i think.

Unfortunately my experience in electronics is very very low. I do know the + and - on a led.. 

I'm actually a web/desktop C# Programmer where i don't see any electronica but have some basic C knowledge (Not in Electronics)

I have a some development boards where i never really used before.

I have the Arduino Uno, Raspberry Pi (first edition) and Zero , STM32L152c-Discovery (A STM32 Development board with ST/Link). Never really had time to do advanced stuff beyond the hello world, led blinking

I dont have other chips, so no 74HC93.

 

I tried to program this chip from the arduino and i've seen so many arduino schemas doing this on the official arduino website but without any luck. I'm also confused when to use the TX/RX connections to the chip and MOSI, SCK, MISO to 13, 12, 11 on Arduino..

Is it possible to program avr using one of the other boards i already have? I can order a usbasp but i'll need to wait a few days 

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

What other hardware do you have?

You seem to have some arduino stuff.

Lot's of arduino boards also have a programming connector (such as the 6-pin header below).

https://www.aliexpress.com/item/...

This can help in eliminating wiring errors.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

You mean the 2x3 header? That one is available on the arduino Uno.
I dont have anything else except some electronic components like the oscilator, buttons a simple LCD screen and a bunch of resistors

 

 

You mean the 6 pins on the bottom (ICSP for Atmega328)? 

 

Btw, in the attachments you can see the boards i have, dont know if its useful, i've seen its possible programming an AVR with the ST/Link

Attachment(s): 

Last Edited: Wed. Jul 19, 2017 - 03:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zerco wrote:
I'm also confused when to use the TX/RX connections to the chip and MOSI, SCK, MISO to 13, 12, 11 on Arduino..

 

TX/RX are usually for serial uart communication and not for direct programming. (But they can be used for programming if the target has a bootloader programmed in it.

MOSI, SCK, MISO (and Reset) are the 4 pins needed to directly program an AVR, but the target must also have valid Vcc and a working clock.

Clock could be internal RC, external Crystal, etc.

 

I asked for a "virgin" m328p because I know that works from the internal RC oscillator.

I suspect you might have overwritten the fuses with some invalid setting.

 

Below is the output of your avrdude command on my system (I don't need sudo and changed the target to a m8 because that is what is connected).

 

paul@dualcore ~/projects/avr/mumarnet/hx711 $ avrdude -c usbasp -p atmega8 -U flash:w:blink.hex -v  -b 19200 -P usb

avrdude: Version 6.0.1, compiled on Oct 21 2013 at 15:55:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/paul/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega8
         Chip Erase delay              : 10000 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         4    20   128    0 no        512    4      0  9000  9000 0xff 0xff
           flash         33    10    64    0 yes      8192   64    128  4500  4500 0xff 0x00
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e9307
avrdude: safemode: lfuse reads as FC
avrdude: safemode: hfuse reads as D1
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: auto set sck period (because given equals null)
avrdude: reading input file "blink.hex"
avrdude: error opening blink.hex: No such file or directory
avrdude: input file blink.hex auto detected as invalid format
avrdude: can't open input file blink.hex: No such file or directory
avrdude: read from file 'blink.hex' failed

avrdude: safemode: lfuse reads as FC
avrdude: safemode: hfuse reads as D1
avrdude: safemode: Fuses OK (H:FF, E:D1, L:FC)

avrdude done.  Thank you.

The important difference between yours and mine output is in the line where I have:

avrdude: AVR device initialized and ready to accept instructions

you have the error:

avrdude: error: program enable: target doesn't answer. 1

It means that you do not have any communication between avrdude and your target processor.

It also means you do have communication between avrdude and your USBasp (else you will get vid / pid not found errors).

 

zerco wrote:
Is it possible to program avr using one of the other boards i already have?

Yes. Lots of options:

 

Option 1).

You can wire up USBasp to your Arduino Uno via the 6 pin connector on the nano.

Disadvantage is you might loose the bootloader programmed in your Uno.

Easy work around is to only read the flash of the Uno via your USBasp.

The goal here is to get past the "Target doesn't answer" error.

 

Option 2).

You can use the Uno as a programmer to program another AVR

Tutorial:

https://www.arduino.cc/en/Tutori...

 

Option 3).

avrdude can use the I/O pins of the Raspberry Pi to program an avr.

https://duckduckgo.com/html?q=%2...

http://blog.stevemarple.co.uk/20...

 

 

 

 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

Add -v to the avrdude command to make it more verbose. Keep adding more -v to make it more and more verbose. You can have up to 4. It should give you more detail about what is/isn't happening - what it is transmitting what it is/isn't receving.

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

I used this website to set the fuses, i can reset it if needed.. (I used the default for the atmega328P): http://www.engbedded.com/fusecalc/

 

With verbose using the USBASP:
 

avrdude -c usbasp -p atmega328p -U flash:w:blink.hex -v  -b 19200 -P usb -v -v -v 

avrdude: Version 6.2
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/zerco/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         Overriding Baud Rate          : 19200
avrdude: usbasp_open("usb")
avrdude: seen device from vendor ->www.fischl.de<-
avrdude: seen product ->USBasp<-
         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
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: usbasp_initialize()
avrdude: usbasp_transmit("USBASP_FUNC_GETCAPABILITIES", 0x00, 0x00, 0x00, 0x00)
         <= [01] [00] [00] [00] 
avrdude: usbasp_spi_set_sck_period(0)
avrdude: auto set sck period (because given equals null)
avrdude: usbasp_transmit("USBASP_FUNC_SETISPSCK", 0x00, 0x00, 0x00, 0x00)
         <= [00] 
avrdude: usbasp_transmit("USBASP_FUNC_CONNECT", 0x00, 0x00, 0x00, 0x00)
avrdude: usbasp_program_enable()
avrdude: usbasp_transmit("USBASP_FUNC_ENABLEPROG", 0x00, 0x00, 0x00, 0x00)
         <= [01] 
avrdude: error: program enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: usbasp_close()
avrdude: usbasp_transmit("USBASP_FUNC_DISCONNECT", 0x00, 0x00, 0x00, 0x00)

avrdude done.  Thank you.

 

 

Wiring up the Arduino to the Breadboard with the external atmega328P (With the base atmega328P still ON the arduino) and running that with arduino instead of usbasp gives:
 

avrdude -c arduino -p atmega328p -U flash:w:blink.hex -v  -b 19200 -v -v -v
avrdude: Version 6.2
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/zerco/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyS0
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
avrdude: ser_open(): can't set attributes for device "/dev/ttyS0": Inappropriate ioctl for device

avrdude done.  Thank you.

 

I might give the raspberry a try. Even though i thought it would be easy getting this done with the arduino. 

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

/dev/ttys0 ? An old fashioned serial interface? Surely these days it's going to be a "USB serial" not a physical UART in the PC? So something more like /dev/ttyUSB0 or something ? Maybe try a "-P /dev/ttyUSB0" in there or similar (but first check to see where the CDC-ACM link from the Arduino has actually appeared in /dev)

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

clawson wrote:

/dev/ttys0 ? An old fashioned serial interface? Surely these days it's going to be a "USB serial" not a physical UART in the PC? So something more like /dev/ttyUSB0 or something ? Maybe try a "-P /dev/ttyUSB0" in there or similar (but first check to see where the CDC-ACM link from the Arduino has actually appeared in /dev)

 

That did something!!! 

I checked the Arduino IDE where it recognizes /dev/ttyACM0

So i did -P /dev/ttyACM0

 

avrdude -c arduino -p atmega328p -U flash:w:blink.hex -v  -b 19200 -v -v -v -P /dev/ttyACM0

avrdude: Version 6.2
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/zerco/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

avrdude done.  Thank you.

It sends and then it doesn't respond..

 

I used this scheme and removed the rest (The arduino still includes its own atmega328p)

 

I remember reading something about having to setup a specific conf in the /arduino/hardware because im using the Internal clock... Could that be a possible solution to this?

Last Edited: Wed. Jul 19, 2017 - 04:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrdude sertainly got more verbose, but you are further from a working solution then you were before.

The error you now have is:

avrdude: ser_recv(): programmer is not responding

The error you had before was:

avrdude: error: program enable: target doesn't answer. 1

Which means that avrdude can communicate with your USBasp programmer, but the the USBasp can not communicate with the AVR target processor (m328p).

To get this to work you first have to program your Uno to act as a programmer.

 

Note that our posts are out of sync because you posted in the time that I was typing my own reply.

In #17 Option 1). I mean exactly what you write in #16

Connect your USBasp to the 6-pin connector labeled ICSP (In Circuit Serial Programming) on the Arduino Uno.

Then Try to Read or Verify some data in the Arduino Uno.

At this point we just want to see *ANY" communication between USBasp and the target uC.

 

The 6-pin ICSP connector is also nothing special, it is just a breakout in a convenient (standarised?) pinout for a 6-wire programming cable.

With a DMM you will find that the MOSI pin is connected directly to the MOSI pin of the processor and to the MOSI pin on the "Arduino" header (Pin 12), etc.

 

At this point my best guess is that somewhere in your efforts you've written a bad fuse combination to your (only?) m328p and it does not work any more.

A notorious fuse is  the fuse to disable the reset pin, which also disables all further serial programming.

This is wy I've asked (several times) to connect a new unused processor.

This also excludes hardware failure on th m328p.

You've put signals on MISO / MOSI / SCK etc without the m328p having a proper Vcc.

This means that the Vcc of the m328p was taken from the I/O pins which is not good and could be the cause of a  hardware failure.

 

---

Trying to use the ST-Link to progam an AVR is also a sort of last resort effort.

But if you can get your ST-Link to program a blinking led on your ARM processor you probably have a more capable board then the m328p.

 

 

 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

Are you actually getting voltage (+5 or +3.3) on the mega328's Vcc pins?  There is no jumper on the PRG header located on the USBASP board.  This might be the bridge that connects the USBASP's power to the target CPU (the mega328).  With no jumper, there may be no power actually getting to the mega328, even though the LEDs on the USBASP are lighted.  That would explain why the mega328 is not responding.

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

Paulvdh wrote:

At this point my best guess is that somewhere in your efforts you've written a bad fuse combination to your (only?) m328p and it does not work any more.

A notorious fuse is  the fuse to disable the reset pin, which also disables all further serial programming.

This is wy I've asked (several times) to connect a new unused processor.

This also excludes hardware failure on th m328p.

You've put signals on MISO / MOSI / SCK etc without the m328p having a proper Vcc.

This means that the Vcc of the m328p was taken from the I/O pins which is not good and could be the cause of a  hardware failure.

 

 

you are probably right about the bad fuse. I inserted that one m328p in my arduino uno and tried to program but without success. I then put back the original m328p on the Arduino and programmed it with avrdude with my blink.hex and that worked!! The led blinks when connected to PortC! But when i pull out that working m328p chip and place it on the breadboard, it doesn't work ( I think it doesn't use its internal clock...) . So maybe im missing something in my scheme to get the working chip working on the Breadboard.

And secondly i think my UsbASP is bad, so im getting another one from a nearby electronics shop to keep going.

 

The one thing, firstly i used the default values, secondly i read about the reset disable before setting the fuses. So i don't remember i ever set reset disable.

 

I will try to get a usbasp soon and another fresh m328p chip. In the meanwhile i can work with the one i have with Arduino as ISP (I can only program the chip when its inserted into Arduino) But still not via the SCK, MISO, MOSI, RESET wires

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

zerco wrote:
I inserted that one m328p in my arduino uno and tried to program but without success.

Normally the chip on an Arduino board has a bootloader programmed in it.

It is a special piece of software to make it possible to make a chip program itself.

(Do you know what a bootloader is? How it works?)

 

zerco wrote:
I then put back the original m328p on the Arduino and programmed it with avrdude with my blink.hex and that worked!!

How did you program it? AVRdude supports so many different protocols...

zerco wrote:
The led blinks when connected to PortC! But when i pull out that working m328p chip and place it on the breadboard, it doesn't work ( I think it doesn't use its internal clock...)
  Correct. That chip has it's fuses set to use an external crystal and it won't work without a crystal

zerco wrote:
And secondly i think my UsbASP is bad, so im getting another one from a nearby electronics shop to keep going.

Could be, but I still suspect bad wiring Do you have a reference to that board on Internet which states it's pinout / schematic ?

 

I will try to get a usbasp soon and another fresh m328p chip.

What is your budget?

I stronly advise to get at least 5 chips and 2 programmers. This makes it quick and easy to swap hardware if there are suspicious things going on.

You will also make it easier on yourself if you buy for example some Arduino Nano's (USD2 on Ali)

https://www.aliexpress.com/whole...

You can easily ignore the "arduino" part of these boards and repgrogram these boards with USBasp.

This will make the learning curve a lot gentler for you.

Then start working with the bare chips again if you have more confidence and experience to debug problems like in this thread.

I think that investing EUS30 might prevent hours and hours of frustration.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

okay i got it working, i bought a new Atmega328p, the first time it didn't work with the wiring i had, so

I found out the reset and resistor was connected to gnd while it should be connected to +
then i found that you could compile with -DF 8000000UL or whatever frequency you want... and i had to set the -B to 10 or 15

 

my usbasp works! Thats a good thing! I'll try to make my own second programmer and see which hardware i'll get from alibaba

 

these are my gcc and avr commands:

avr-gcc -g -Os -mmcu=atmega328p -c blink.c -DF_CPU=8000000UL

avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex

sudo avrdude -c usbasp -p atmega328p -U flash:w:blink.hex -v -v -v -v -P /dev/ttyACM0 -B 10

 

thanks a lot Paulvdh!! Your replies are of great value! 

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

Always pleased to help :)

 

Still using sudo?

Make an udev rule as I explained above.

Thiss wil also stop the need to type your password every time.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

If that's the case then your AVR is possibly (highly probably) fried.  One more of

many reasons why it's not a good idea to build microprocessor circuits on plug-in

breadboards.  If you do, be sure to check that the power lines are presenting Vcc

and Ground to the right pins before plugging in the actual AVR chip.

Last Edited: Tue. Jul 25, 2017 - 09:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Really? Sure looks like this track:

 

 

is connecting the top pin at the right to the right hand pin in the block to the left.

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

Simonetta wrote:

If that's the case then your AVR is possibly (highly probably) fried.  One more of

many reasons why it's not a good idea to build microprocessor circuits on plug-in

breadboards.  If you do, be sure to check that the power lines are presenting Vcc

and Ground to the right pins before plugging in the actual AVR chip.

 

actually, the 2 bottom pins at the right gave me GND and VCC (5V). I couldn't find out what the other 4 pins are

And, VCC is exactly on the other side of the row where you are pointing to PIN 1...

Last Edited: Wed. Jul 26, 2017 - 12:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And then that track dissapears under the pin header and you can not see it anymore.

I positively refuse to guess where that track is going.

 

This beautiful line states 3 different reasons why that pcb track is irrelevant anyway.

zerco wrote:
my usbasp works! Thats a good thing! I'll try to make my own second programmer and see which hardware i'll get from alibaba

This line also confirms he is happy, which gives me a warm fuzzy feeling in return.

Next subject.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

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

I have never seen a pcb like this before. It would be useful to post a link to the website.
.
Most Chinese USBASP have a standard USB connector on one end and a standard 5x2 box header on the other.
The USB fits intimately into your PC. The ribbon cable can only fit one way into the keyed header.
.
Bare pins are fine. But it is wise to mark pin#1 so you know which way to plug your ribbon.
Yes, I know the 5x2 pinout for ISP is a bit obsolete (from STK500 days)
But it is used by both German and Chinese USBASP. 10-way ribbon and connectors are more easy to find than 3x2 components.
.
If they want a non-standard 6x1 header, it would be useful to print the pin names on the pcb.
.
Incidentally, the USBASP is a USB device. There is no point in using a baud rate or COM port name.
.
David.