Problems uploading Bootloader to custom ATMEGA328PB board

Hope I used the right category

I have built a custom Uno that uses a ATMEGA328PB, however I can't seem to upload the bootloader to it. I have tried using the MINICORE core (following the instructions on GitHub), however I get this error:

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x000000 (retrying)
avrdude: device signature = 0x000000 (retrying)
avrdude: device signature = 0x000000
avrdude main() error: Yikes!  Invalid device signature.
avrdude main() error: expected signature for ATmega328PB is 1E 95 16
        Double check connections and try again, or use -F to override
        this check.

(I have no idea where to enter "-F" so I haven't done that, should I??

This is my schematic:

I am using an Arduino as ISP using the old wiring (properly declared in the ArduinoISP code.

Is the chip bricked, or can I repair it somehow? How can it be fixed?

I want to use it just like a ATMEGA328P (ie. normal Uno)

When I connect my FTDI device and select Get Board Info, I see this:
image
However I don't know wether that is the FTDI or my ATMEGA

Try this

Regards

This is a ATMEGA328PB, doesn't that make a big difference though?

Oops! I was wrong, sorry

Add: It seems that the solution (?) is the same but change ID to 1E 95 16

1 Like

I have a 16mhz resonator connected to my chip, can I burn the bootloader for internal crystal and then reburn for the external one later?

I think not but I'm not sure, sorry.

1 Like

I don't see why not. It's a change to one of the fuse bits. The minicore docs say that it will run at 8MHz (or lower) using the internal clock.

If the PB is the same as the P (excluding extra ports), then you may have problems if you have programmed the fuses for an external clock, and the external clock isn't running.

What crystal are you using? I don't see any capacitors - 22pF or so to GND - that are normally present. See the minimal setup schematic in the docs.

EDIT: Ah didn't read your posts properly - you are using a resonator.

I might be wrong here, but if you've programmed the chip (i.e. set the fuses) for an external clock, and the clock isn't running, then you can't reprogram the chip until you provide an external clock. There was a post somewhere on here about using an UNO to generate a 4MHz clock for a chip where that happened.

Maybe this will help if the clock is the issue:

So I'm guessing a resonator isn't a clock then?

First time I did this:
image
However it said it completed. Since then I can't use it.

I have three new chips, should I try one with internal clock even if there is a resonator attached to the XTAL pins?

Ok, with these settings and a new chip and the resonator removed:
image

I get these results:

avrdude: Version 7.1-arduino.1
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

         System wide configuration file is C:\Users\Daniel VN\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.2.2\avrdude.conf

         Using Port                    : COM13
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328PB
         Chip Erase delay              : 10500 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         Serial program mode           : yes
         Parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                           Block Poll               Page                       Polled
           Memory Type Alias    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    1      0  4500  4500 0x00 0x00
           hfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
           efuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
           lock                    0     0     0    0 no          1    1      0  4500  4500 0x00 0x00
           signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
           calibration             0     0     0    0 no          1    1      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: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9516 (probably m328pb)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file C:\Users\Daniel VN\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.2.2/bootloaders/empty/empty.hex for flash
         with 0 bytes in 0 sections within [0, -1]
         using 0 pages and 0 pad bytes
avrdude: writing 0 bytes flash ...

Writing | ################################################## | 100% 0.00s

avrdude: 0 bytes of flash written
avrdude: verifying flash memory against C:\Users\Daniel VN\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.2.2/bootloaders/empty/empty.hex

Reading | ################################################## | 100% 0.00savrdude: 0 bytes of flash verified
avrdude: reading input file 0xcf for lock
         with 1 byte in 1 section within [0, 0]
avrdude: writing 1 byte lock ...
avrdude: 1 byte of lock written
avrdude: verifying lock memory against 0xcf
avrdude: 1 byte of lock verified

avrdude done.  Thank you.

Success!!!!

Now how do I add the resonator back in?

Your resonator circuit provides a clock source. I would expect it to work fine as shown in your schematic but your results do indicate that the microcontroller is not being clocked from the external source. I recommend triple checking your resonator circuit. If you have a spare resonator, try swapping out the current one in case the original component was bad.

1 Like

It works beautifully on an Internal 8mHz, do I need the resonator?
My goal is to create a pro Mini with some added functions. 8mHz will be slower, but will it make a noticeable difference?

My main problem now is working out how to upload code to my board using FTDI

Which programmer do I select for FTDI???

Arduino as ISP does work to upload code, but I'd like the FTDI if possible

Other than the lower speed, the concern with using the internal RC oscillator is that it is less accurate. You can see the accuracy data in table 33.5.1 of the ATmega328PB datasheet:

You can compare that to the data that will be provided in the datasheet for the specific resonator you are using.

If the clock is significantly off it can affect timing sensitive code. For example, you might find there is some corruption of serial communication by your sketch code or uploads via the serial port fail.

But it is common to use the internal RC oscillator and I think most people don't encounter any problems.

The Tools > Programmer menu selection is only used when you are doing Tools > Burn Bootloader or "Upload Using Programmer". When you're doing a standard "Upload", the Tools > Programmer menu selection is completely ignored. So it makes no difference at all what you have selected from the Tools > Programmer menu.

You might see the term "programmer" mentioned in error messages from a failed upload (e.g., "programmer is not responding"), but these error messages are not referring to the same thing as the programmers listed in the Arduino IDE Tools > Programmer menu.

1 Like

When I try to use the FTDI to upload code, I get this error:

avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 1 of 10: not in sync: resp=0x00

What could cause that?

I'm basically trying to use the board like a pro Mini, can I somehow upload the pro Mini bootloader then continue as if it is a pro Mini?

I can see from the screenshot and avrdude output in your post #9 that you had the Tools > Bootloader menu set to "No bootloader". That is the appropriate setting for when you are going to be using an ISP programmer to upload your sketches, in which case a bootloader is not needed. But a bootloader is required for you to upload via the FTDI module. So you'll need to repeat the "Burn Bootloader" operation, but this time with the appropriate configuration of the Tools > Bootloader menu:

  1. Connect your ISP programmer to the ATmega328PB, as you did before.
  2. Select Tools > Bootloader > Yes (UART0) from the Arduino IDE menus.
  3. Select Tools > Burn Bootloader from the Arduino IDE menus.
  4. Wait for the "Burn Bootloader" operation to complete successfully.
  5. Disconnect the ISP programmer from the ATmega328PB.
  6. Connect the FTDI module to your computer.
  7. Select the port of the FTDI module from the Tools > Port menu in Arduino IDE.
  8. Select Sketch > Upload from the Arduino IDE menus.

The Pro Mini does come in an 8 MHz version, but this uses an external clock so you would need to solve the problem with the external resonator before you could use the Pro Mini board definition.

But you should also be aware that the Pro Mini board definition is significantly inferior to the one provided by MiniCore. The benefit of using MiniCore is it provides you with the state of the art Optiboot bootloader that only requires a 0.5 kB boot section in the flash memory of your ATmega328PB microcontroller. The Pro Mini board definition uses an antiquated "ATmegaBOOT" bootloader that requires a 2 kB boot section. This means you would have 1.5 kB less precious flash memory for your sketch program if you switched to using the Pro Mini board definition.

In addition, the "ATmegaBOOT" bootloader has a bug that causes it to go into an infinite loop after a watchdog timer reset. This means you can't use the watchdog timer to reset the microcontroller (e.g., as a safety measure to automatically recover the device from a hang) when you have that bootloader installed on the microcontroller. The Optiboot bootloader handles watchdog timer resets properly.

1 Like

I have worked out why the resonator didn't work. I had the footprint wrong so GND was connected to the input pin :woozy_face:

Thank you so much! Couldn't have done this without your help!!

You are welcome. I'm glad you were able to find the cause.

Regards,
Per

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.