Chinese cloned Arduino Nano as ISP on Atmel Studio-7

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

Folks,  I bought a couple of Chinese cloned Arduino Nanos with the CH340 USB chip on them.  Following a video on YouTube, I downloaded the USB driver, loaded the ISP software onto the Nano (ATMEGA328P) from the Arduino IDE, connected the wires from the Nano to an ATtiny85, and successfully programmed it to blink an LED.

 

I want to program the ATtiny in assembler, which is much better supported in Studio-7, but I'm a bit mystified how to make Studio-7 transfer the hex file to my ATtiny via the ArduinoISP.

Could somebody give some pointers please?  You may need to be a bit explanatory - I've already tried several YouTube-based instructions, but so far without success - so a bit of hand-holding wouldn't go amiss - something at the level of "Mickey's long hand is pointing to ...".  I've about got to grips with writing and debugging ASM in Studio-7, but there's a lot about its setup and configuration that doesn't make much sense to me yet.

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

You already have the hex file? You can always transfer it manually using avrdude, IDK if you can tell Studio to do that automatically (that is, use avrdude as external software).

I don't use ArduinoISP, I prefer ScratchMonkey that appears as a stk500v2 programmer to avrdude. I don't know the programmer type of ArduinoISP, so I don't know what command line to use.

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

Hmmm ... There are instructions on http://www.instructables.com/id/...

You have to hit Next a couple of times to get to page 3.  It isn't working for me yet, but I think I may be making headway.

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

I know what the problem is, but I don't know what to do.

The arguments I am using in tools/external tools are ...

-U lfuse:w:0xe6:m -U hfuse:w:0xd9:m

-e -F -v

-patmega328p

-carduino -PCOM5

-b19200

-D

-Uflash:w:"$(ProjectDir)Debug\$(ItemFileName).hex":i

-C"C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf"

 

The fuses are set correctly, but the transfer of the hex file was failing with "main.hex does not exist", so it seems that $(ItemFileName) is not substituting the right filename.

 

 

Well, it's true that main.hex doesn't exist, so I changed  $(ItemFileName).hex  to  Reg2Scope.hex , which is the actual name of my hex file.

 

After that, it said

 

Writing | ################################################## | 100% 0.14s

avrdude.exe: 84 bytes of flash written
avrdude.exe: verifying flash memory against c:\users\mik\Documents\Atmel Studio\7.0\Reg2Scope\Reg2Scope\Debug\reg2scope.hex:
avrdude.exe: load data flash data from input file c:\users\mik\Documents\Atmel Studio\7.0\Reg2Scope\Reg2Scope\Debug\reg2scope.hex:
avrdude.exe: input file c:\users\mik\Documents\Atmel Studio\7.0\Reg2Scope\Reg2Scope\Debug\reg2scope.hex contains 84 bytes
avrdude.exe: reading on-chip flash data:

Reading | ################################################## | 100% 0.08s

avrdude.exe: verifying ...
avrdude.exe: verification error, first mismatch at byte 0x0000             0x00 != 0x01
avrdude.exe: verification error; content mismatch

avrdude.exe: safemode: hfuse reads as DF
avrdude.exe: safemode: efuse reads as FF
avrdude.exe: safemode: Fuses OK (E:FF, H:DF, L:E2)

avrdude.exe done.  Thank you.

The hex file that it is attempting to send is

:020000020000FC
:10000000012C18D002E00EBF0FE50DBF09EBAF9237
:10001000A02E02D0AF90FFCF49E0C39A0BD0AA1C0C
:1000200010F4C39A01C0C39805D04A95C1F7C3988C
:1000300001D0F2CF0F931F931DE006EC0A95F1F764
:100040001A95D9F70AE40A95F1F7000000001F910C
:040050000F9108956F
:00000001FF

... but I don't know where the mismatch is because I can't make sense of the addressing in the file.  I think there are 16 bytes per line, but that would make (for the first line)

Address:   1000000001
Data       2C 18 D0 02 E0 0E BF 0F - E5 0D BF 09 EB AF 92 37

Then the next address would be 10001000A0.  I don't understand it.

I'm wallowing here, Folks.  Any help would be very welcome.

Last Edited: Sun. Mar 19, 2017 - 11:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The arguments I am using in tools/external tools are ...

-U lfuse:w:0xe6:m -U hfuse:w:0xd9:m

-e -F -v

-patmega328p

-carduino -PCOM5

-b19200

-D

-Uflash:w:"$(ProjectDir)Debug\$(ItemFileName).hex":i

-C"C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf"

Use "-cstk500v1" when talking to the "Arduino as ISP" sketch.   "-carduino" is for talking to the Arduino bootloader.

Is your end device at Atmega328, or am ATtiny85 (as you mentioned in your text)?  If you're going via the ISP code, you want the end device.

Don't use "-F" - any time it complains that you can "use -F to override", it means you've done something wrong.

While it's SUPPOSED to work anyway, the "Arduino as ISP" sketch works much better if you disable auto-reset on the Nano.  The easiest way to do this us to connect an ~10uF capacitor between reset and GND of the nano (AFTER you've loaded the ArduinoAsISP sketch.)

 

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

The Intel Hex format is well described in wikipedia: https://en.wikipedia.org/wiki/Intel_HEX

Actually,

:10000000012C18D002E00EBF0FE50DBF09EBAF9237

means:

10 - number of bytes (16)

0000 - start at address 0000

00 - content of this line is data

012C18D002E00EBF0FE50DBF09EBAF92 - 16 bytes of data

37 - checksum

 

In your case, the first byte should be 0x01 but is 0x00. For some reason the writing failed.

 

Wait. I just noticed, you said you are programming an attiny85? So, you need to put "-pattiny85" instead of "-patmega328p"

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

Many thanks to westfw and El Tangas. 

 

Let me answer your question first.  My hardware setup is as follows

Laptop PC---(USB)--->Arduino Nano---(hard wiring)--->ATtiny85

The Arduino is programmed with the ISP sketch.  The "hard wiring" has been checked by going back to the Arduino IDE and successfully sending an LED blink program to the AT85, which was then tested, and worked.

 

Following your instructions, the first thing I did was to remove the -F.      Studio-7 complains...

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

avrdude.exe: Device signature = 0x1e930b (probably t85)
avrdude.exe: Expected signature for ATmega328P is 1E 95 0F
             Double check chip, or use -F to override this check.

Then I changed the processor type to -cattiny85 as suggested by El Tangas - and that was seemingly what clinched it.  The transfer worked.

There's yet more good news - my program works too, and displays a register on the scope with a Start bit, 8 data bits and a stop bit.

 

Just one little clingon left - My External tools arguments were -Uflash:w:"$(ProjectDir)Debug\Reg2Scope.hex"         Note the file name at the end.

I changed the name back to   -Uflash:w:"$(ProjectDir)Debug\$(ItemFileName).hex"         but $(ItemFileName) doesn't seem to work.  The output, when I try to transfer the hex file, is ...

avrdude.exe: verifying ...
avrdude.exe: 1 bytes of hfuse verified
avrdude.exe: reading input file "C:\Users\Mik\Documents\Atmel Studio\7.0\Reg2Scope\Reg2Scope\Debug\main.hex"
avrdude.exe: can't open input file C:\Users\Mik\Documents\Atmel Studio\7.0\Reg2Scope\Reg2Scope\Debug\main.hex: No such file or directory
avrdude.exe: read from file 'C:\Users\Mik\Documents\Atmel Studio\7.0\Reg2Scope\Reg2Scope\Debug\main.hex' failed

I note that my filename (on disk) is   C:\Users\Mik\Documents\Atmel Studio\7.0\Reg2Scope\Reg2Scope\Debug\Reg2Scope.hex

but in Solution Explorer, I see the following files...

 

Dependencies

Labels

Output files   (expanded)

 - Reg2Scope.hex

 - Reg2Scope.lss

 - Reg2Scope.map

 - Reg2Scope.obj

main.asm      <========   Is this the "main" that is being used by $(ItemFileName)?

 

If I change my filename on disk to main.hex, the transfer works.

 

This isn't a big deal, as I know how to overcome it now, but do you see a simple solution to it?  It would be nice to have a generic argument that would work for any project, but if you don't see a simple solution, it's not worth spending time over.

 

Thanks again, Guys - I don't think I'd have got through this without you.

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

I use -U flash:w:$(TargetName).hex:i with Initial Directory:$(TargetDir)

 

If you use $(ItemFileName) it all depends on what particular focus your AS7 has when you use the Tools menu.

 

It also makes the Tool easier to configure.

 

David.

 

Edit.   I tend to use the Bootloader whenever possible.   The thread seems to be about using a Nano as dedicated programmer.   You can use ArduinoISP if you want (with 19200 baud) or just use some clone STK500 software (with 115200 baud).    The biggest advantage of clone STK500 is that AS7 will think you have a genuine Atmel programmer.

Last Edited: Mon. Mar 20, 2017 - 05:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sadly, David, that didn't work either.  It outputs ...

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

avrdude.exe: verifying ...
avrdude.exe: 1 bytes of hfuse verified
avrdude.exe: reading input file "C:\Users\Mik\Documents\Atmel Studio\7.0\Reg2Scope\Reg2Scope\Release\Debug\Reg2Scope.hex"
avrdude.exe: can't open input file C:\Users\Mik\Documents\Atmel Studio\7.0\Reg2Scope\Reg2Scope\Release\Debug\Reg2Scope.hex: No such file or directory
avrdude.exe: read from file 'C:\Users\Mik\Documents\Atmel Studio\7.0\Reg2Scope\Reg2Scope\Release\Debug\Reg2Scope.hex' failed

Before, it was using the Debug directory.  Now, it's looking in Release.     In fact, the only file in   Atmel Studio\7.0\Reg2Scope\Reg2Scope\Release      is  Reg2Scope.tmp  

Maybe that construct would work if I compiled it some other way, but at the moment, I run everything through the debugger.  If I didn't, it would never work!  :-(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Reg2Scope\Reg2Scope\Release\Debug\Reg2Scope.hex

I think it VERY unlikely that the path would have both "Debug" and "Release" in the name.

 

Either you are building debug and it's likely to be:

Reg2Scope\Reg2Scope\Debug\Reg2Scope.hex

or you are building release and it's likely to be:

Reg2Scope\Reg2Scope\Release\Reg2Scope.hex

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

I can confirm that the Tool programmed the Release version just fine.   Exactly like the Debug version.

 

I even built a project that is not the "Startup Project" of the opened Solution.    So it built that $(TargetName) and programmed that $(TargetName) just fine.

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

clawson - "I think it VERY unlikely that the path would have both "Debug" and "Release" in the name."

 

Yes, you're right.  I'm not energetic enough to have written that manually, so I must have copied/pasted it from somewhere, but I don't know how it happened.  It's not there now.

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

David, right now, I have "-Uflash:w:"$(TargetDir)Debug\$(TargetName).hex":i", and it's working, but is that "Debug" kosher? 

When I press F7 to build the project, it puts four files into my directory...

Reg2Scope\Reg2Scope\Release

... but even though I step through the program with the debugger, it no longer writes anything into   Reg2Scope\Reg2Scope\Debug.  It definitely did before, but I erased the files to see if it would recreate them.  I guess they would come back if I put the original argument string in, but it's working now, so I guess I'd rather get on with my project.  Being able to see the content of a register on the scope is not the end object!

Thanks for your help.

 

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

Did you not notice the trick?

with Initial Directory:$(TargetDir)

 

It even works with Codevision AS7 projects.  (which have slightly different folder structure)

 

I presume that you are using avrdude.   The older avrdude would have the .exe and .conf in the same /bin directory.

With that arrangement,   avrdude will find its .conf file automagically.

 

If you steal the avrdude from your Arduino installation,   the .conf is in an /etc directory.

So I put the base command into a .bat file which is much easier to use in your Tools menu.

 

David.

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

Umm...  Your original instruction said (copied/pasted) :  "I use -U flash:w:$(TargetName).hex:i with Initial Directory:$(TargetDir)"

Note that the "I use" is clearly not a part of the argument string, and its font shows that.  It's a comment from yourself.

"-U flash:w:$(TargetName).hex:i" is in a different font, indicating that it is a part of the string.

By that logic, "with Initial Directory" seems to be text from yourself - a comment.

":$(TargetDir)" is, again, part of the string

 

I'm starting to feel like the tourist who is looking for <name your public attraction>, and everybody he asks sends him in a different direction.  Sure - they all know where his destination is, but - well, I think you'll understand my point.

 

Is there a description somewhere of how that string is constructed, and what, its syntax is?  My whole string is

-U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -e -v -pattiny85 -cstk500v1 -PCOM5 -b19200 -D -Uflash:w:"$(TargetDir)Debug\$(TargetName).hex":i -C"C:\Program Files (x86)\Arduino\hardware\tool\avr\etc\avrdude.conf"

... but I'm only having trouble with the bit in red.  If I click the arrow to the right of the field, I see various possibilities - but without any attached explanations, and "Initial Directory" isn't there.

If you can point me to the instructions, I can probably construct the string myself.  Can you give the tourist a map?

 

Yes, I'm using avrdude, and the conf file is in \etc, but that doesn't seem to be presenting any problem.

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

In AS7 IDE:  Select Tools->External Tools...

 

You have four fields to configure (this is one of my Tools):

 

Title:                    UNO_com4

 

Command:           C:\Program Files\Arduino-1.6.12\hardware\tools\avr\bin\avrdude.exe

 

Arguments:         -c arduino -P com4 -p ATmega328P -U flash:w:$(TargetName).hex:i -C"C:\Program Files"\Arduino-1.6.12\hardware\tools\avr\etc\avrdude.conf

 

Initial Directory:  $(TargetDir)

 

You might find it convenient to copy avrdude.exe and avrdude.conf to a single directory on your PATH.

Or to a .BAT file on your PATH.   Life is much simpler if your Tools configuration is short and easy to read.    You only need to change the avrdude location in one place with a .BAT file.

 

Your COM# will be different.   Your avrdude folder might be different.   Mine is on a Win7-32 Laptop.

Of course,  the ideal place for the avrdude location would be an AS7 macro called $(DUDE).    I am not sure whether you can add global macros to AS7.

 

David.

Last Edited: Mon. Mar 20, 2017 - 10:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, David, Shortly before reading this, I got it going, apparently reliably.  I'm a bit puzzled about the scope output of my sketch - it goes to a "1" with a sharp edge, but falls to a "0" along what looks like a capacitor discharge that takes about 1mS - which, in the terms of this processor, is about a week.  However, if I can't solve it, it will be the subject of a different thread.  What you told me really helped with this one.  I think we can close it now.

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

For the new problem show both code and schematic.

 

Also what observation technique are you using? (scope, logic analyser? etc.)

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

armstack wrote:

I'm starting to feel like the tourist who is looking for <name your public attraction>, and everybody he asks sends him in a different direction.  Sure - they all know where his destination is, but - well, I think you'll understand my point.

 

Well, you know what they say... You learn from the journey, not from the destinationcheeky

 

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

Good people,  I eventually got my little project working, but it was more by a lot of iterations of trial and error than anything else, and I still don't really understand what I did. 

I was tempted to open a new thread to ask specifically for the formulation and syntax of the External Tools arguments string, but I have already experienced the push-back when a moderator feels that there is already a thread open, so I'll ask it here.

 

My original arguments string, as suggested by the Instructables web site  ( https://www.instructables.com/id... ) - hit Next twice to get to page 3.

I have inserted line feeds to make it more readable

 

-U lfuse:w:0xe6:m -U hfuse:w:0xd9:m

-e -F -v

-patmega328p

-carduino -PCOM5

-b19200

-D

-Uflash:w:"$(ProjectDir)Debug\$(ItemFileName).hex":i

-C"C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf"

 

After lots of instruction in this thread, it has changed to

-U lfuse:w:0xe2:m -U hfuse:w:0xdf:m

-e -v

-pattiny85

-cstk500v1

-PCOM5

-b19200

-D

-Uflash:w:"$(TargetDir)$(TargetName).hex":i

-C"C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf"

...... and it seems to be working.

 

Now I could ask "What do the following mean :  -U, -e, -F, -v, -D, -C, etc", and in the string "-U lfuse:w:0xe2:m -U hfuse:w:0xdf:m", what are the ":w:", ":m", ":i" - but as this is clearly such a useful string, able to set fuses, for example, it strikes me that it can probably do other things that I'm not aware of - possibly set pull-up resistors, for example.  I already asked (in my post #15 above) ...

"If you can point me to the instructions, I can probably construct the string myself.  Can you give the tourist a map?" - but I didn't get any offers - so now, I'm asking specifically where to find all the information that constructs the arguments line.  I have spent several hours reading the Studio manual, and searching in Studio for things like "-U", but I haven't found my answers yet. 

 

In the Studio manual, I found "Menus and Settings/External Tools/Pass Variables to External Tools" - but it gives minimal information with no explanation.

The manual speaks about the "memories" page -   http://www.atmel.com/webdoc/atme...

... which looks very useful, but it doesn't say how to access it - so after a lot of searching, I Googled "Atmel Studio Memories page", and I found "Debug→ Windows→Memory view - but the screen it shows makes me think it's not the dialogue I'm looking for - and besides, when I click Debug/Windows" there is no "Memory" entry in it.

 

Years ago, when dinosaurs roamed the earth and the Internet had not been invented, I was given a Data General Nova hotel system to maintain (with 15" diameter, 6-platter disks and core-plane memory).  Working from the books that came with the computer, without an assembler (so working binary in machine code), I wrote and completed an assembler for it in less time than it has taken me to make some superficial inroads to coding and using the online tools for the AVR core.  I'm finding it pretty frustrating.  While professionals probably get into the AVR environment through courses, and working in an environment where it's easy to ask colleagues, I'm finding that self-help material is in very short supply, and on-line documentation is obscure and difficult to use.

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

armstack wrote:
Now I could ask "What do the following mean :
  The problem is that tool is not Atmel Studio, it is AVRDUDE (as mentioned in the instructable you reference). A quick google of "avrdude documentation" gives this. The "memories" section you reference is for use with the Atmel tools (programmers and debuggers, not AVRDUDE), so yes there will be a disconnect. A lot of this disconnect is in coming into AS with the Arduino added on. I agree, it is not clearly demarcated.

 

Having brought myself up by the bootstraps on AVR (as well as other uCs), I must say the info is there, along with a lot of garbage.

 

Edit: clarification of tools above

David (aka frog_jr)

Last Edited: Tue. Mar 21, 2017 - 05:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

armstack wrote:
Now I could ask "What do the following mean : -U, -e, -F, -v, -D, -C, etc"
The user manual answers that...

 

http://www.nongnu.org/avrdude/us...

armstack wrote:
possibly set pull-up resistors, for example.
Err no  - you do that in your C code by writing to a PORT register while the bit in DDR is still 0 (input)

armstack wrote:
In the Studio manual, I found "Menus and Settings/External Tools/Pass Variables to External Tools"
But avrdude ahs nothing to do with Studio? It's an external program. All Studio knows is about invoking it and passing parameters. It's the thing that provides meta variables like $(TargetDir), $(ItemFileName) and so on. If you want to know about those go to the place where you set the external command and press the macros button and Visual Studio will show you all the ones it has available and (in the current context) what they willl currently be equal to.

 

Your problem seems to be that you were looking for a "one stop shop". If you want that kind of thing for an easy life then forget about using non-Atmel programmers and external commands like avrdude and just buy an Atmel ICE and it'll all be contained "inside" Studio and fully documented in their manual. But be ready to spend a hundred bucks!

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

clawson

frog_jr

Well, that de-mystifies that point.  I thought I was putting that string in as an instruction to AS-7, to tell it what to do to the target.  I get it now - it's a formatted string to be passed to avrdude, so the formatting is in avrdude's manual.  If that had occurred to me, I wouldn't have been asking about it on an Atmel forum.  Sorry for that!

Thanks for the links.  I'll study the AVRdude manual and see if I can put it all together.

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

Thanks for the explanation, and the sympathy.

"Having brought myself up by the bootstraps on AVR" - that's what I'm in the throes of too, but I keep running up against the fact that pulling on bootlaces is governed by Newton's laws.

 

 

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

armstack wrote:

clawson

frog_jr

Well, that de-mystifies that point.  I thought I was putting that string in as an instruction to AS-7, to tell it what to do to the target.  I get it now - it's a formatted string to be passed to avrdude, so the formatting is in avrdude's manual.  If that had occurred to me, I wouldn't have been asking about it on an Atmel forum.  Sorry for that!

Thanks for the links.  I'll study the AVRdude manual and see if I can put it all together.

 

It's ok, you can ask about all things AVR here, including avrdude.