0
\$\begingroup\$

I am going to start working with microcontrollers. I will need to programm it. To programm it, I want to use a USB to serial port shield.

There are several options. Should I use https://www.electronicscomp.com/cp2102-usb-to-ttl-serial-converter-module?search=usb%20to%20ttl this one?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Your ATmega 328P must have a boot loader programmed into it before you can use a USB to serial converter to program it. \$\endgroup\$
    – JRE
    Commented Sep 2, 2020 at 7:33
  • 1
    \$\begingroup\$ okay , i have that one \$\endgroup\$ Commented Sep 2, 2020 at 7:36

2 Answers 2

1
\$\begingroup\$

I think you might be mixing Arduino programming with plain AVR programming.

Arduino boards, which are based on ATMega328P (not the only one microcontroller (MCU) they use, but probably most popular) comes with a bootloader pre-programmed. This opens a method for self-programming MCU on the remaining flash memory with UART method. With this (i.e. via bootloader) you can use any USB-UART converter (like CP2102) to flash user program to it.

On the other hand plain ATMega328P MCU doesn't comes with a bootloader itself. And you can't flash it with just a USB-UART bridge. It has SPI interface (and some others, which are rare to be used) for programming. You have to use some AVR SPI programmer to flash it.

If you want to get started with AVR MCUs I strongly suggest you getting some kind of such AVR ISP programmer (or build one yourself) as some of the projects require flashing so-called fusebits to get some things done. And this can only be achieved with AVR programmer, you can't change fusebit from bootloader (via USB-UART). But be careful with those. You can easily "brick" (recoverable with additional hardware) your MCU by flashing wrong fusebits.

One example of such programmers which are quite common, cheap (both built & DIY) and opensource of such programmers are USBAsp. It's not the best one - it uses software USB stack, but it works. Still you may try finding others with better specs.

\$\endgroup\$
5
  • \$\begingroup\$ Arduino vs ATmega and bootloader vs ISP are orthogonal questions: The Arduino IDE supports both methods of loading a sketch, and the serial bootloader used on many Arduino boards predates the Arduino project. \$\endgroup\$ Commented Sep 2, 2020 at 12:02
  • 1
    \$\begingroup\$ As for the USBAsp beware it is a hack that doesn't really meet the USB spec and if you look at existing questions you will find many people have had issues with them. It's probably better to use something with a true USB interface - for example another "Arduino" into which an ISP "sketch" can be loaded on need. \$\endgroup\$ Commented Sep 2, 2020 at 12:08
  • \$\begingroup\$ @ChrisStratton, I agree about USBAsp. This was just an example of cheap opensource DIY project. I'll update answer to reflect there might be a better options. \$\endgroup\$
    – NStorm
    Commented Sep 3, 2020 at 6:21
  • \$\begingroup\$ AVRDUDE suppoert the serrbb interface therefore any usb-uart bridge with enough I/O can be used to program AVRs, (albeit slowly) \$\endgroup\$ Commented Sep 3, 2020 at 6:51
  • \$\begingroup\$ @Jasen Yes, but 1) It won't work out of box with CP2102. You have to add inverted signals to avrdude.conf. 2) It's slow to unusable state. With CP2102 bitbang people reports sometimes it takes more than an hour to flash optiboot only. \$\endgroup\$
    – NStorm
    Commented Sep 3, 2020 at 7:02
-1
\$\begingroup\$

you need 3 outputs and one input to program AVR, so that UART bridge having only 2 i/o pins isn't going to work.

One that has enough pins could work, for software use something based around the the "serbb" programmer profile in AVRDUDE.

Serial port bit-bang is very slow over USB so you're probably better served using a dedicated programmer like fischl.de "USBasp" or genuine STK500

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.