1

An ATmega microcontroller can be flashed by a C compiler and a USB dedicated device (ISP).

I tried to flash the program into the microcontroller by saving the machine code to a MicroSD card that I then attached to the microcontroller. I figure we can use the USB SPI reader to test the program without dedicated device like USBtiny.

But I suspect that the compiler is just producing the hex file and then the USB will translate it to machine code.

Was I thinking wrong?

If the compiler loads the machine code through the USB programmer to microcontroller so don't we just need a MicroSD USB to program it?

dda
  • 1,595
  • 1
  • 12
  • 17
Lan...
  • 111
  • 1
  • 3

2 Answers2

1

Your initial assumption "An ATmega microcontroller can be flashed by a C compiler and a USB dedicated device (ISP)." is wrong.

The C compiler converts the source code into assembly language. It is then passed to an assembler which converts it to object code. The linker then creates an ELF file from it all. That is then converted into a HEX file using objdump.

That HEX file is then loaded by another program, avrdude, which knows how to control the USB-connected programming device. That device then issues special instructions to the chip through the ISP port to copy the data loaded from the HEX file into the memory of the chip in the right way.

It's quite a complex procedure and you require some active component in the mix to do the job. Just connecting an SD card and hoping it will work is, I am sorry to say, a laughable concept. You require something that a) understands how to read data from an SD card and can interpret it, and b) knows how to program an ATMega through ISP.

It is possible to create something that does that, using another chip, such as another ATMega, and writing the software to do it. If you feel adventurous, of course. You would basically have created a stand-alone programmer, which has advantages when you want to do field upgrades, but is pointless when you are sat at your desk developing software.

Majenko
  • 105,851
  • 5
  • 82
  • 139
0

The compiler doesn't do that, a separate program does that. For most ATMegas and most people, the program that does this is called avrdude. It interfaces with your ISP and transfers the code when you give it appropriate settings. See here:

http://www.ladyada.net/learn/avr/avrdude.html

So you get the hex from your compiler, and send that through avrdude to the chip using your ISP. At no point is the MicroSD necessary. FWIW, the ATMega must have its code loaded into its flash memory. It cannot run code from the Micro SD.