USBASP

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

I have a Atmega 32 having a 16 MHz crystal connected.

When I use averdude  it gives an error with this command

-c usbasp -p m32 -P usb -B 0.5

avrdude.exe: set SCK frequency to 1500000 Hz
avrdude.exe: error: programm enable: target doesn't answer. 1
avrdude.exe: initialization failed, rc=-1
             Double check connections and try again, or use -F to override
             this check.

avrdude.exe done.  Thank you.

 

but when I give this command

-c usbasp -p m32 -P usb -B 20.96 this is the response

 

avrdude.exe: set SCK frequency to 32000 Hz
avrdude.exe: AVR device initialized and ready to accept instructions

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

avrdude.exe: Device signature = 0x1e9502

avrdude.exe done.  Thank you.

 

The first instruction gives no error with the 28 pin Atmel 8/328 devices (with 16 MHz) crystals.

what can be wrong in the Atmega 32 setup?

 

Regards.

 

 

This topic has a solution.
Last Edited: Mon. Nov 24, 2014 - 01:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have the atmega32's fuse bits been programmed to use the 16MHz crystal?

 

- S

 

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

Fuse bits are

Low   0xFF; High 0x99

 

 

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

karanbir wrote:
Fuse bits are

Low   0xFF; High 0x99

Those fuse bits select for a crystal oscillator running between 3.0 and 8.0 MHz.

 

The fuse bits for 16 MHz are L:0xFF H:0x89 (the only difference is the CKOPT fuse)

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Thanks.

I will try it in the evening and update on this post.

 

smiley

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

I set the fuses with this instruction

-c usbasp -p m32 -B 20.96 -U lfuse:w:0xFF:m -U hfuse:w:0x89:m

The response is

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

avrdude.exe: set SCK frequency to 32000 Hz
avrdude.exe: AVR device initialized and ready to accept instructions

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

avrdude.exe: Device signature = 0x1e9502
avrdude.exe: reading input file "0xFF"
avrdude.exe: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude.exe: 1 bytes of lfuse written
avrdude.exe: verifying lfuse memory against 0xFF:
avrdude.exe: load data lfuse data from input file 0xFF:
avrdude.exe: input file 0xFF contains 1 bytes
avrdude.exe: reading on-chip lfuse data:

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

avrdude.exe: verifying ...
avrdude.exe: 1 bytes of lfuse verified
avrdude.exe: reading input file "0x89"
avrdude.exe: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude.exe: 1 bytes of hfuse written
avrdude.exe: verifying hfuse memory against 0x89:
avrdude.exe: load data hfuse data from input file 0x89:
avrdude.exe: input file 0x89 contains 1 bytes
avrdude.exe: reading on-chip hfuse data:

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

avrdude.exe: verifying ...
avrdude.exe: 1 bytes of hfuse verified

avrdude.exe done.  Thank you.

 

I get this response

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

avrdude.exe: set SCK frequency to 93750 Hz
avrdude.exe: error: programm enable: target doesn't answer. 1
avrdude.exe: initialization failed, rc=-1
             Double check connections and try again, or use -F to override
             this check.

avrdude.exe done.  Thank you.

 

when this instruction is used

-c usbasp -p m32 -B 8.0

 

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

avrdude.exe: set SCK frequency to 32000 Hz
avrdude.exe: AVR device initialized and ready to accept instructions

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

avrdude.exe: Device signature = 0x1e9502

avrdude.exe done.  Thank you.

 

It works  till 32000 Hz

 

Regards.

Last Edited: Mon. Nov 24, 2014 - 07:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am a little confused.    Most USBASPs will have come from China and been sold on Ebay.

These generally auto-select the best SCK frequency.    They do not support -B

 

The publicly available source code from www.fischl.de/usbasp supports -B

Obviously kits from fischl.de or home-made USBASP are likely to use the fischl.de firmware.

 

Your examples seem to "connect / initialise" to the AVR at any speed and read the Signature successfully.

 

So I find it difficult to understand how the hardware SPI (>=93kHz) fails but the software SPI (<=32kHz) works.

After all,   it would have used this speed to read the Signature.

 

Are you using some home-made firmware?

Or an Indian USBASP?

 

David.

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

Or a very long programming cable?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

I have two USBASPs. one purchased from ebay and the other purchased from www.extremeelectronics.co.in

I flashed the latest fimware onto the ebay USBASP (Downloaded from fishcl.de website).

Firmware on the other is from fiscl.de website. the Atmega chip can be flashed with latest firmware. May I give it a try( Atmega chip can be removed)?

Both of these programmers display same behaviour.

They work fine on Amega 8/328 micros upto 1.5 MHz but when programming a Atmega 32 it goes upto 32 KHz only.

Even chip detection is successful till 32 KHz for Atmega 32.

The target devices are independently powered.

Thanks for your response. What can be the cause for this?

 

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

Probably better to ask your two suppliers.

 

Ross McKenzie ValuSoft Melbourne Australia

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

programming cable is <= 4 inches.

 

Will try the Atmega 32 on the breadboard setup and see.

 

Thanks.

 

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

david.prentice wrote:

 

 

 

Your examples seem to "connect / initialise" to the AVR at any speed and read the Signature successfully.

 

 

 

David.

No the connect/initialise to the AVR happens at speeds upto 32 KHz

 

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

david.prentice wrote:

 

 

 

Your examples seem to "connect / initialise" to the AVR at any speed and read the Signature successfully.

 

 

 

David.

No the connect/initialise to the AVR happens at speeds upto 32 KHz only!

 

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

I would have been happier if you had used the Chinese USBASP to program the Indian USBASP.

Unfortunately,  most Chinese firmware is locked.    So there is no way to restore it.

 

However,   at least we now know which firmware is running.    I presume it is the 2011 fischl.de version from the website.

 

I normally use my own firmware.    I will see if I can reproduce your symptoms with the fischl.de firmware.

 

Please can you post a photo / link to your Ebay USBASP board.    Then I can flash the firmware to the same hardware.

 

David.

Last Edited: Tue. Nov 25, 2014 - 07:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well,   I flashed the 2011 firmware onto a regular Chinese board (LcSoft).    It worked just fine.

 

Now,   I seem to remember people having problems with the Fischl.de firmware.    They needed to unplug-replug the USBASP.

If you initialise the hardware SPI peripheral,   it starts with SPCR and SPSR as zero.

 

If you stop the SPI subsequently,   you can leave it with SPIF or WCOL bits set.

The "safe" way to enable is:

void spiHWenable() {
	SPCR = sck_spcr;        // use previous speed setting
	SPSR = sck_spsr;        // SPI2X 
	SPSR;			// clear WCOL
 	SPDR;			// clear SPIF
}

I can't understand how you can get a bad response from a fresh USB plug insertion.

 

David.

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

 

The pics are attached. The black one is the ebay purchase. I have flashed the firmware by shorting the self prog pins on the board.

this is also showing the response described above for the Atmega 32. it is fine for the atmega 8/328 boards.

 

Regards.

 

 

Attachment(s): 

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

Have you verified that the atmega32's crystal is indeed running at 16MHz?

 

- S

 

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

What do you suggest?

Where do I include the code suggested by you? I have the firmware files downloaded from fishchl.de website. This set of files have compiled hex files for Atmega8/88. I had used the hex file for Atmega 8 and flashed it to the ebay usbasp using Arduino uno board.

Regards.

 

Last Edited: Tue. Nov 25, 2014 - 01:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Chinese USBASP looks like a regular betemcu.cn pcb.    It is probably made by a different company than betemcu

 

So I would be reasonably confident about the quality / reliability of the Chinese hardware.

 

Does it read the red Indian board ok?

If it works with the red board as target,   then it should work with your mega32 board.
 

If it is unreliable with the mega32 target,   this implies that you have got bad wiring / crystal / capacitors on the mega32 board.

 

Please post a photo of the Chinese USBASP connected to the mega32 board.

 

David.

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

I changed the XTAL with a new one. Still same response. The two 22 PF caps are also connected.

To rule out wrong wiring on the Atmega 32 Board I will setup a bare AVR on a breadboard.

Regards.

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

Explain the behaviour.  e.g. the exact command line and the response from avrdude (using the Chinese dongle).

 

If avrdude works with SCK = 32kHz (-B31) ,   it should work with SCK = 187kHz (-B5)

 

Since you say that it reads the Signature ok at 32kHz,   just type:

avrdude -c usbasp -p m32 -B 31 -v

This will tell you (and us) what the current fuse values actually are.

 

My only guess is that you have set the fuses for "External RC" and that it just happens to be oscillating.

After all, you are using proven dongle with proven firmware.

 

David.

Last Edited: Tue. Nov 25, 2014 - 02:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

This is the response

Use atprogram for programming

C:\Users\kssoin\Documents>avrdude -c usbasp -p m32 -B 0.5 -v

avrdude: Version 5.10, compiled on Jan 19 2010 at 10:45:23
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\WinAVR-20100110\bin\avrdude.conf"

         Using Port                    : lpt1
         Using Programmer              : usbasp
         Setting bit clk period        : 0.5
         AVR Part                      : ATMEGA32
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         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  Max
W   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
-- ---------
           eeprom         4    10    64    0 no       1024    4      0  9000  90
00 0xff 0xff
           flash         33     6    64    0 yes     32768  128    256  4500  45
00 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  2000  20
00 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  20
00 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  20
00 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0
 0 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0
 0 0x00 0x00

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

avrdude: set SCK frequency to 1500000 Hz
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x1e9502
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as 89

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as 89
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

C:\Users\kssoin\Documents>

 

This does not work the second time. I unplug and replug and it works.

Same with the Indian board.

How do I use the code suggested by you?

 

Regards.

 

 

 

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

You edit "isp.c" in the fischl.de distribution and re-build the HEX file.   The instructions are all in the ZIP.

 

Does the red USBASP behave in the same way?

 

David.

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

Thanks for your patience and help David, I appreciate it.

I have added

SPSR;   //  clear WCOL
SPDR;   //  clear SPIF

in the ISP.c file.

How do I compile the code?

I will use winavr.

I gave it a try,

the compiler is throwing up errors . I will post my results soon.

Well I did manage to compile the hex file. and uploaded it also

on writing the fuses as lfuse=0xef and hfuse= 0xc9

the atmega 8a froze.

these fuse settings were in the makefile in the distribution files.

 

 

 

Last Edited: Thu. Nov 27, 2014 - 08:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Those fuse values look fine to me.    Your Chinese board has got a 12MHz crystal.   So it should run just fine.

 

Of course,   I could spend hours of my life studying the USBASP readme and Makefile.

But you are the person that shot your own foot.    It is your job to do the reading.

 

I am quite happy to explain or help with a specific question.

 

The real mystery is: "why did you fiddle with a perfectly good Chinese board?"

 

Of course,   you started off with a red board from Extreme Electronics.

If it does not work properly,   you should phone / email the nice people at Extreme Electronics.

 

We can help you with Chinese boards.     It is not possible to help with Indian boards.    You need to ask Indian people.

 

David.

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

You are right David.

I have the chinese board. It is the red board that I shot!

You see the problem has  been zeroed to unplugging and plugging to make the boards run at 1.5 MHz SCK

The atmega 8a on the indian board is not soldered.  I will try to reset the fuses on the Atmega 8A 

I will sure try the recompilation to fix the issue of unplugin and replugging.

Thanks for your help and patience I appreciate it.

 

 

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

No,   you should ask Extreme Electronics for advice about their board.

 

Only an Indian can understand Indian boards.

I am sure that it can work too,   but I cannot help you.

 

David.

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

What do you say,

may I attempt to  flash the Chinese board?

How to check that the compiled file is correct.

There was no error during compile and upload.

 

Your guidance will help me.

Best Regards

 

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

I am saying:

 

1.  If the Chinese board works perfectly,   do not change it.

2.  If the Indian board does not work properly,   ask Extreme Electronics for help.

 

Most Chinese USBASP will give a message "cannot set SCK".    This means you have automatic setting of SCK.    This is good.

If you bought the Chinese board from a Chinese vendor on Ebay,   I bet that it will be 100% perfect.

 

If you bought the Chinese board from an Indian vendor on Ebay,   the gloves are off.    I can't help.

You should obtain help from the Indian vendor.

 

David.

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

Got it David.

I think I will rest the issue here.

 

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

Hi David,

I have ordered another Atmega8 programmed for the Red board.

From another post on AVR Freaks as below I will give compiling the usbasp another try!

And if I change

void spiHWenable() {
        SPCR = sck_spcr;
        SPSR = sck_spsr;
}

in usbasp's isp.c to

void spiHWenable() {
        uint8_t dummy;
        SPCR = sck_spcr;
        SPSR = sck_spsr;
        if (SPSR & (1<<SPIF))
                dummy = SPDR;  // Clear interrupt flag
}

it works every time! Even with -B0.1 (1.5MHz, but it's not really faster that -B1).

It is a post started by s_mack

Programming a AVR Device?

 

 

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

I suggested:

SPSR;   //  clear WCOL
SPDR;   //  clear SPIF

and you have actually used:

        if (SPSR & (1<<SPIF))
                dummy = SPDR;  // Clear interrupt flag

They both do exactly the same thing.   i.e. read SPSR then read SPDR,  discarding any results

These two 'reads' clear the WCOL flag and clear any waiting value that might be pending in the SPDR buffer.

 

The explanation from the data sheet is:

The WCOL bit is set if the SPI Data Register (SPDR) is written during a data transfer. The
WCOL bit (and the SPIF bit) are cleared by first reading the SPI Status Register with WCOL set,
and then accessing the SPI Data Register.

So it does not really matter how you write the statements.    They both do the same job.   Ok,   your version looks more obvious.

 

Regarding the -B# switch.    The number parameter is a minimum time.    i.e. you are saying "use a SCK period of 0.1us if you can"

The USBASP's shortest period is 0.667us (1.5MHz).    So that is what you get.    You would get the same value even if you used -B0.6 or -B0.5

 

If you use -B1.0 then you are asking for 1.0us.    You should get 1.33us (750kHz)

 

Note that a virgin 1MHz AVR needs < 250kHz +-10% i.e. < 225kHz

This corresponds to a period of 4.44us.   e.g. -B4.44 or -B5

 

USBASP will actually use 175kHz because that is the appropriate SCK value.    You would still get 175kHz if you asked for -B5.7 or -B5

 

If you simply used the Chinese USBASP firmware,   you don't need to worry about the -B switch at all !!!

 

David.

Last Edited: Sat. Dec 13, 2014 - 02:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David,

I will try this and post my results. It is the re insertion of the usbasp that I want to avoid.

I will take a few days to post as I am away, but using my IPad to keep myself busy.

Thanks for your prompt response.

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

Hi David,

Merry Christmas and Happy New Year to you and your family!

I found USBASP software on the net I am attaching the zip as I downloaded it.

I flashed the hex file on to the red and the other USBASP programmer.

Now I Do not need to specify the B and it does not need re insertion.

ISP.C has not been modified as you suggested. Since the Hex worked I did not tinker. Something else is the difference.

My board The red one is working now!

Thanks for your prompt responses.

Added

 

The link to this is this

http://www.sciencetronics.com/greenphotons/?p=938

 

Best Regards

Karanbir

Attachment(s): 

Last Edited: Tue. Dec 23, 2014 - 06:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello peopple I am sorry for wrinting again on this topic I am starting eveything from draft and I don't know what to do in such situations. I have bought USBasp and atmega48 device from chinese manufacturer. And when I am trying to check connection using

avrdude -c usbasp -p m48 -F -B 31 -U lfuse:w:0xFF:m -U hfuse:w:0x99:m

 

this code is it is giving me this error "

avrdude: set SCK frequency to 32000 Hz
avrdude: error: programm enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATMEGA48 is 1E 92 05

avrdude done.  Thank you.

 

what am I supposed to do?

I have done everything that is been mentioned above but still no result.

Please help.

IsoAlex

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

You have set fuses for an external crystal. Connect a crystal and two 22pF capacitors and everything should work.
.
Alternatively supply an external clock signal to XTAL1 pin. Then change the fuses back to proper internal RC clock as the chip had when it was new from the factory.
.
David.