I had a working custom PCB with a atmega328P but by mistake I bought and got soldered atmega328pb and now I can't flash the code I developed for atmega328p.
I already flashed the bootloader using optiLoader.ino but now I can't upload any sketches.
I really don't need the added functions that the "PB" version offers, I just want to upload my old code in this new microcontroller.
Btw, I'm using (trying to use) an arduino UNO as ISP to upload the code.
There are several 3rd party hardware packages you can install to add support for ATmega328PB to the Arduino IDE. The one that comes first to mind is MiniCore:
Note there is an additional installation step for the PB chips:
If you end up wanting to use one of the other ATmega328PB hardware packages I should be able to dig up links for them.
Hi, I tryed to upload my sketch using the MiniCore package and still don't.
Every time I try the arduino LEDs of Tx and Rx flash like 10 times and then I get the following mistake:
avrdude: stk500_initialize(): n_extparms 6 mayor 1 minor 18
avrdude: stk500_initialize(): n_extparms = 6
avrdude: sending extparam for arduino multi isp
avrdude: stk500_set_extended_parms(): can't get into sync
avrdude: stk500_initialize(): failed
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
I was able tu burn the Bootloader using the MiniCore package, but I still can't upload sketch.
To burn the bootloader I changed to Arduino boards version 1.6.21 and it worked, but every time I try to upload an sketch I get this compile error
In file included from C:\Users\--\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.0\cores\MCUdude_corefiles/wiring_extras.h:14:0,
from C:\Users\--\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.0\cores\MCUdude_corefiles/Arduino.h:290,
from sketch\Blink.ino.cpp:1:
c:\users\pabol\appdata\local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.3-arduino2\avr\include\avr\sleep.h:224:6: error: #error "No SLEEP mode defined for this device."
#error "No SLEEP mode defined for this device."
^
exit status 1
Error compiling for board ATmega328.
You can't use Arduino AVR Boards 1.6.21, that's why you got that error. You must follow the PB-specific instructions I linked earlier to install Arduino AVR Boards 1.6.206.
I can reproduce the problem. It seems there is a bug with the way the AVRDUDE uploader tool included with Arduino AVR Boards 1.6.206 and 1.6.205 works with the Arduino as ISP programmer.
Try this:
Tools > Board > Boards Manager
Wait for downloads to finish
Click on "Arduino AVR Boards"
Select 1.6.200 from the dropdown menu
Click "Install"
Wait for the installation to finish
Click "Close"
Now try the upload again.
It's unfortunate to need to use the outdated version but maybe it will work out. The problem does not occur for me with this version and it should also support the PB chips.
I'll report this issue to the Arduino developers and update here with news.
It looks like the version of AVRDUDE used by Arduino AVR Boards 1.6.200 does not have a definition for ATmega328PB. Likely that version only has the updated version of AVR-GCC but only 1.6.205 and 1.6.206 have the avrdude that supports ATmega328PB (but also is incompatible with Arduino as ISP).
Do you have a USB-TTL serial adapter chip (e.g. FT232, CH340, PL2303, CP2102) on the board or a separate one you can connect to the board?
I just have a couple arduino UNO boards that I was using as my programmers, but if you think that using one of those chips I can flash my boards I can buy one.
Once you have the bootloader burned to the microcontroller you can upload to it via serial, just like you do with the Uno, so even though the new version of avrdude (6.3.0-arduino12) doesn't work with Arduino as ISP it should still work for serial uploads (at least it does for me with the ATmega328P). A USB-TTL serial adapter board is a useful tool to have and you can buy them on eBay/Aliexpress for <$1 USD w/ free shipping from China. The FT232 based adapters you will find four around $1 are counterfeit. They work fine for me but there are some possible problems using the official Windows driver with them (there is an unofficial driver you can use instead) so if you want a cheap one it's probably best to buy the CH340 based ones, which work fine too and don't have any strange anti-counterfeit measures. If you buy one make sure to get the one with the "FTDI header" pinout: DTR, RX, TX, Vcc, CTS, GND. It's fine if the DTR and CTS pins are swapped. That is the most common pinout, such as the one used on the Arduino Pro Mini so you can plug the adapter right into most boards, rather than needing a mess of jumper wires to adapt from some non-standard pinout.
But buying something to work around the problem means waiting and I'm sure you want to get this working now. There are some things you could do to try to get MiniCore to work for you but they get a bit more advanced so maybe the best path forward is to try one of the other hardware packages that add ATmega328PB support to the Arduino IDE:
Glad you got it working! The modification to avrdude.conf was one of the "bit more advanced" processes I mentioned for getting MiniCore working with Arduino AVR Boards 1.6.200. I was hoping the other packages would offer more of a "turn-key" solution but really that's not so difficult an extra step. Enjoy your ATmega328PB!
Update on the Arduino as ISP bug discovered in this thread:
Forum member westfw did some investigation into this issue and it turns out the problem was caused by a new feature added in to avrdude 6.3.0-arduino12, which requires an updated version of the ArduinoISP sketch but does not correctly check the version number reported by the programmer for backwards compatibility. You can solve the problem by:
File > Examples > 11.ArduinoISP > ArduinoISP
Change line 149 from:
#define SWMIN 18
to
#define SWMIN 17
Upload the modified ArduinoISP to the Arduino board you are using as your Arduino as ISP programmer and it will now work with Arduino AVR Board 1.6.206.
The Arduino as ISP bug has now been fixed in Arduino AVR Boards 1.6.207/avrdude 6.3.0-arduino14. So the workaround I described in my previous reply is no longer necessary. You can use the unmodified ArduinoISP sketch in your Arduino as ISP programmer.