# ATmega328p and USB conection to PC

I posted the same question on StackOverflow and I was redirected here.

For my project I need to be able to program the eeprom of an Atmega 328p via an USB to PC. I tried to incorporate an USBasp programmer in my circuit but I was unsuccessful. The PC does not recognise the programmer so I am unable to install the drivers.

So my question is:
Does anybody know how can I update the Atmega 328p eeprom via USB. Is there any basic communication I could use?

I know there are boot loaders, but my programming skills are not adequate to make my own and I can not find an appropriate one.

My code for the Atmega 328 is written in Atmel studio 6. Thank you for the help.

EDIT: I already have a programator for atmel's chip, but I need some sort of programming option directly on USB. That is why I incorporated an USBASP on my board design. I would like to be able to open a simple program on a PC, set some parameters and than upload to the eeprom of my 328. All that without an additional programator (a simple plug and play device for any other user).

• so how are you currently programming the '328p? – Techydude May 5 '15 at 11:38
• I think you should try harder to get the USBasp to work. – Dzarda May 5 '15 at 12:16
• Edited my answer and you should give avrdude a try. – Maxthon Chan May 5 '15 at 12:20
• I use a avrisp mk II to program the 328p. – user3713940 May 5 '15 at 12:20
• USBasp worked fine for me with this software. – Bence Kaulics May 5 '15 at 12:28

I purchased a programmer made by Atmel AVRISP mkII and used Atmel Studio - you should be able to program all of the Atmel's 8 bit chips. I do not think you can do real time debugging with it. But programming is a finger snap.

Assuming you have a 6-pin ICSP header on your board for programming the '328p, then a device-programmer like USBasp, Atmel's AVRISP mkII, AVRtinyISP, etc, coupled with the AVR programming util 'avrdude' (& you'll need to dive deep into how to use it) will get you what you want.

It is possible to improvise a close enough approximation of a USB interface for the ATmega328p using two GPIO pins and external components. However, "close enough" does not necessarily mean "in spec" and so much as you had trouble with the USBasp which is an implementation of the same idea, you may in rare cases be unable to get this to work with a particular host PC. Proper component selection, proper clocking, correct and geometrically clean wiring, etc are all necessary - although this method uses the lowest speed form of USB, it is still high-rate signalling that does not appreciate signal corruption.

And yes, you will need software. Likely you can create this by a combination of LUFA examples, bootloader examples, eeprom examples but expect to do some work and learn some things here - it is not the role of the stack exchange sites to write your firmware for you, or to identify a site where a read-to-go implementation has been published.

You will probably have an easier time creating a robust design if you use a microcontroller with a USB interface instead, such as the ATMega32u4 already mentioned.

• Unfortunately this time the chip will be a 328. Thank you for the ATMega32u4 suggestion. – user3713940 May 6 '15 at 5:44

If you are willing to add chips to your project you can add some kind of USB UART chip, like FTDI's FT232, Prolific's PL2303 or WCH's CH340 to your design. This will give you serial access to the ATmega328P and your code is then able to update its EEPROM contents. Or maybe just refactor your project into an Arduino shield and use the well-tested Arduino hardware platform (and since you are using Atmel Studio, you can safely disregard the Arduino IDE)

Or you can use a USB-enabled AVR like ATmega32U4. This may or may not require you to roll your own drivers though.

Speaking of programming it, avrdude can read Atmel Studio's output hex or bin file, and allow you to use a very wide range of programmers, from AVRISP mkII to Arduino as ISP to bit banging using a Bus Pirate to raw Linux SPI access using spidev. Just give it a try.

Speaking of EEPROM, it is accessible using special registers in your AVR.

• He currently has no way of programming the chip, the FTDI will be no good; it can't be used to program a blank chip. – Dzarda May 5 '15 at 12:14
• @Dzarda Edited. – Maxthon Chan May 5 '15 at 12:19
• I am able to program my chip. I would like that other people would be able to change the parameters of my 328 without any programator. – user3713940 May 5 '15 at 12:27
• I would like my device to be like an plug an play which you control by a small interface on your PC. Therefore I am searching a replacement for the USB ASP (not functioning on my board- I am still trying to make it work) for easy accessing my 328 without any (or at least as little as possible) additional gear. – user3713940 May 5 '15 at 13:31
• All three chips I suggested, CH340, FT232 and PL2303 are plug and play USB to UART adapters and is simple to use. Just bridge it between the microcontroller's UART and the computer's USB and it will appear to your computer as a serial port. The communication over the serial, however, is all your own code. Design a protocol that make sense, and that is all it. – Maxthon Chan May 5 '15 at 13:34