[SOLVED] Custom Atmega8u2/Atmega328PB uploading issues

I have built a pretty unnecessarily complex power supply (based on the eevblog uSupply design), just to practice using different ICs and technology and am having just one problem with the USB side of things. I'm not crazy experience with electronics or atmega chips.

By copying the circuitry of Arduino Uno (r1/r3) schematics, I am using an atmega8u2 to act as a usb-serial converter for an atmega328pb which manages everything else on the board (mainly managing SPI devices, LCD screen, etc). The only real difference between the Uno schematic(s) is the use of 3.3V to power to atmega chips. I understand there might be some issue using external 16Mhz and 3.3V but in my previous version where I programmed the 328pb via, it didn't seem to cause any issues for me.

The relevant schematics pages are here (imgur for full resolution):

a) atmega8u2 usb-serial
b) atmega328PB
c) Overall connections

Layout/picture is here:
a) Kicad PCB layout
b) PCB image

I have performed the following steps:

  1. Using Atmel flip, I have flashed the ArduinoCore-avr-master\firmwares\atmegaxxu2\arduino-usbserial\Arduino-usbserial-uno.hex firmware onto the atmega8u2. Whilst the atmega328pb reset is held low, by jumping the atmega8u2 TX/RX lines, I can confirm the atmega8u2 is functioning correctly via serial loopback.

  2. Using minicore board manager in the Arduino IDE, I was able to burn a bootloader onto the atmega328pb using arduino as ISP using the following settings:

arduino_settings

The log output seems to show that it was successful:

C:\Users\Lachlan\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino18/bin/avrdude -CC:\Users\Lachlan\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/avrdude.conf -v -patmega328pb -cstk500v1 -PCOM4 -b19200 -Uflash:w:C:\Users\Lachlan\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328pb/16000000L/optiboot_flash_atmega328pb_UART0_115200_16000000L_B5.hex:i -Ulock:w:0x0f:m 
Writing | ################################################## | 100% 0.01s
 
avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3f:
avrdude: load data lock data from input file 0x3f:
avrdude: input file 0x3f contains 1 bytes
avrdude: reading on-chip lock data:
 
Reading | ################################################## | 100% 0.01s
 
avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0b11110101"
avrdude: writing efuse (1 bytes):
 
Writing | ################################################## | 100% 0.01s
 
avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0b11110101:
avrdude: load data efuse data from input file 0b11110101:
avrdude: input file 0b11110101 contains 1 bytes
avrdude: reading on-chip efuse data:
 
Reading | ################################################## | 100% 0.01s
 
avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0b11010110"
avrdude: writing hfuse (1 bytes):
 
Writing | ################################################## | 100% 0.01s
 
avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0b11010110:
avrdude: load data hfuse data from input file 0b11010110:
avrdude: input file 0b11010110 contains 1 bytes
avrdude: reading on-chip hfuse data:
 
Reading | ################################################## | 100% 0.01s
 
avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0b11111111"
avrdude: writing lfuse (1 bytes):
 
Writing | ################################################## | 100% 0.01s
 
avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0b11111111:
avrdude: load data lfuse data from input file 0b11111111:
avrdude: input file 0b11111111 contains 1 bytes
avrdude: reading on-chip lfuse data:
 
Reading | ################################################## | 100% 0.01s
 
avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
 
avrdude done.  Thank you.
 
 
avrdude: Version 6.3-20201216
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch
 
         System wide configuration file is "C:\Users\Lachlan\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/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
           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
           efuse          0     0     0    0 no          1    0      0  4500  4500 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
 
Reading | ################################################## | 100% 0.02s
 
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\Lachlan\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328pb/16000000L/optiboot_flash_atmega328pb_UART0_115200_16000000L_B5.hex"
avrdude: writing flash (32768 bytes):
 
Writing | ################################################## | 100% -0.00s
 
avrdude: 32768 bytes of flash written
avrdude: verifying flash memory against C:\Users\Lachlan\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328pb/16000000L/optiboot_flash_atmega328pb_UART0_115200_16000000L_B5.hex:
avrdude: load data flash data from input file C:\Users\Lachlan\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328pb/16000000L/optiboot_flash_atmega328pb_UART0_115200_16000000L_B5.hex:
avrdude: input file C:\Users\Lachlan\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328pb/16000000L/optiboot_flash_atmega328pb_UART0_115200_16000000L_B5.hex contains 32768 bytes
avrdude: reading on-chip flash data:
 
Reading | ################################################## | 100% 0.00s
 
avrdude: verifying ...
avrdude: 32768 bytes of flash verified
avrdude: reading input file "0x0f"
avrdude: writing lock (1 bytes):
 
Writing | ################################################## | 100% 0.02s
 
avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x0f:
avrdude: load data lock data from input file 0x0f:
avrdude: input file 0x0f contains 1 bytes
avrdude: reading on-chip lock data:
 
Reading | ################################################## | 100% 0.01s
 
avrdude: verifying ...
avrdude: 1 bytes of lock verified
 
avrdude done.  Thank you.
  1. Removing the Arduino ISP, I connect the USB to the atmega8u2 and can see it in device manager as Arduino Uno and the Arduino IDE shows it as a COM port. When uploading blink to it either using a) Arduino Uno board or b) as an atmega328pb with settings shown in the screenshot, I get the following output:
"C:\\Users\\Lachlan\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\\Users\\Lachlan\\AppData\\Local\\Temp\\arduino_build_257937/Blink.ino.elf"
Sketch uses 1232 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\Lachlan\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino18/bin/avrdude -CC:\Users\Lachlan\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/avrdude.conf -v -patmega328pb -carduino -PCOM7 -b115200 -D -Uflash:w:C:\Users\Lachlan\AppData\Local\Temp\arduino_build_257937/Blink.ino.hex:i 
 
avrdude: Version 6.3-20201216
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch
 
         System wide configuration file is "C:\Users\Lachlan\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/avrdude.conf"
 
         Using Port                    : COM7
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xb0
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xb0
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xb0
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xb0
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xb0
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xb0
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xb0
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xb0
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xb0
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xb0
 
avrdude done.  Thank you.
 
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

I can't figure out why. As a side note, I can upload a blink sketch to the atmega328bp via it's ICSP with arduino as ISP, and everything functions as expected. In the worst case, I can always program my power supply but all the effort implementing USB-serial would be for none so I'd love to get this fixed.

So my questions are really:

  1. Does anything stand out as being wrong in these design and/or steps that I've performed already?
  2. Does the fact I am using a 328PB change the compatibility with the arudino IDE, since the uno only ever used the 328P.

Any help would really be appreciated. Thanks so much!

Lachlan

edit: the ugnd and gnd jumper is bridged, so is the reset jumper from the atmega8u2 to atmega328pb, so the auto reset feature should work :slight_smile:

I have solved solved this. The issue was that I did not correctly set the atmega8u2 lock bits and fuses, so the clock was running at 1MHz, while the atmega328pb was running at 16MHz. See here for more information.