Uploading sketch on ATMEGA328PB

Hi,

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.

I would be very grateful if someone could help me

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.

avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x12
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x12

Please do this:

  • File > Preferences > Show verbose output during: > compilation (uncheck) > upload (check) > OK
  • Sketch > Upload
  • After the upload fails you'll see a button on the right side of the orange bar "Copy error messages". Click that button.
  • Paste the error messages in a reply here USING CODE TAGS (</> button on the toolbar).

I think I might be closer to the sollution.

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.

If I use the Arduino 1.6.206 configuration I get this msj

Arduino: 1.8.5 (Windows 10), Board: "ATmega328, Yes, 328PB, 2.7v, Disabled (default), 16 MHz external"

Sketch uses 1290 bytes (3%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino12/bin/avrdude -CC:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino12/etc/avrdude.conf -v -patmega328pb -cstk500v1 -PCOM4 -b19200 -Uflash:w:C:\Users\Pabol\AppData\Local\Temp\arduino_build_97283/Blink.ino.hex:i 

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino12/etc/avrdude.conf"

         Using Port                    : COM4
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328PB
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

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.

avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x12

avrdude done.  Thank you.

the selected serial port 
 does not exist or your board is not connected

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Also, when I use the 1.6.206 version I can't upload the bootloader.

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.

I did as you told me and I was able to burn the bootloader but when I try to upload an sketch I get this msj

Arduino: 1.8.5 (Windows 10), Board: "ATmega328, No, 328PB, 2.7v, Disabled (default), 16 MHz external"

Sketch uses 1290 bytes (3%) of program storage space. Maximum is 32768 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/bin/avrdude -CC:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf -v -patmega328pb -cstk500v1 -PCOM4 -b19200 -Uflash:w:C:\Users\Pabol\AppData\Local\Temp\arduino_build_97283/Blink.ino.hex:i 

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf"

avrdude: AVR Part "atmega328pb" not found.

Valid parts are:
  uc3a0512 = AT32UC3A0512       [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:14599]
  c128     = AT90CAN128         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools
...

\avrdude\6.3.0-arduino9/etc/avrdude.conf:8305]
  m168pb   = ATmega168PB        [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:8317]
  m169     = ATmega169          [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:5495]
  m16u2    = ATmega16U2         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:12675]
  m2560    = ATmega2560         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:10337]
  m2561    = ATmega2561         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:10531]
  m2564rfr2 = ATmega2564RFR2     [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:10749]
  m256rfr2 = ATmega256RFR2      [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:10598]
  m32      = ATmega32           [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:6102]
  m324p    = ATmega324P         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:4337]
  m324pa   = ATmega324PA        [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:4529]
  m325     = ATmega325          [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:13045]
  m3250    = ATmega3250         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:13426]
  m328     = ATmega328          [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:8518]
  m328p    = ATmega328P         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:8703]
  m329     = ATmega329          [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:5677]
  m3290    = ATmega3290         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:5876]
  m3290p   = ATmega3290P        [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:5890]
  m329p    = ATmega329P         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:5862]
  m32m1    = ATmega32M1         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:8715]
  m32u2    = ATmega32U2         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:12487]
  m32u4    = ATmega32U4         [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:11512]
...

  ucr2     = deprecated, use 'uc3a0512' [C:\Users\Pabol\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf:14615]

An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

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 unfortunatelly don't.

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.

Which of them would work better?

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:

I'm somewhat familiar with the first two but only found the last one during my search so I can't say whether that is any good.

The issue report for the avrdude 6.3.0-arduino12 w/ Arduino as ISP bug:

I did it!

in the wnd I was able to program my PCBs. I would like to thank you pert very much for your help and time.

The way I did it was the following.

I followed the way that it is described here

But there are some things to take care of that aren't described in the guide. The most important one is to modify the avrdude.conf file.

You have to insert the following after the "ATmega328P" section as it is described in the last coment here:

Code to add to avrdude

part parent "m328"
    id			= "m328pb";
    desc		= "ATmega328PB";
    signature		= 0x1e 0x95 0x16;

    ocdrev              = 1;
;

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.

Reference:

http://forum.arduino.cc/index.php?topic=541588.msg3693575#msg3693575

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.

(Ah. Reporting a bug with enough detail to fix it quickly, and having it actually BE fixed quickly! Very Satisfying!)