Author Topic: can't upload sketch after flashing bootloader - Atmega328PB  (Read 2419 times)

0 Members and 1 Guest are viewing this topic.

Offline AndyNZTopic starter

  • Contributor
  • Posts: 16
  • Country: nz
Hi all,
after resolving the issues I had uploading a boot loader to an ATMega328PB (https://www.eevblog.com/forum/microcontrollers/problem-flashing-bootloader-to-atmega328pb/), I am now struggling to upload a blink sketch (or any sketch) to it. When I try uploading using a FT232R clone  from Aliexpress https://www.aliexpress.com/item/32843185453.html?_randl_currency=AUD&_randl_shipto=AU&src=google&src=google&albch=rmkt&acnt=576-373-4425&albcp=16560254345&albag=&slnk=&trgt=&plac=&crea=&netw=x&device=c&mtctp=&albbt=Google_7_rmkt&gclid=Cj0KCQjw-JyUBhCuARIsANUqQ_JGzFj-JiPLZtzcvFcDcqsn2aeTDf4tLwtusCzj_n0QDsU_Ub2v5_8aArabEALw_wcB&aff_fcid=8221bc3a71534bbb8f13cc2800416d00-1653099495457-07072-UneMJZVf&aff_fsk=UneMJZVf&aff_platform=aaf&sk=UneMJZVf&aff_trace_key=8221bc3a71534bbb8f13cc2800416d00-1653099495457-07072-UneMJZVf&terminal_id=6ca1f3c260424bf7b4ded7bedc3de2aa&afSmartRedirect=y,
I get an out of synch message, when I try using the Uno R3 I get an "device signature error" as per message below.

I've connected pin 10 of the Uno to the chip reset pin on the target board via 100n cap and 10k resistor to VCC, and I'm getting a few us pulse on the scope, so that seems to work OK.

The error output seems to indicate a 28 kHz oscillator frequency, while I'm using a 16MHz resonator on the target board, so something looks wrong here already.

Any ideas are much appreciated.
Thanks,
Andreas


----------------------------------
Arduino: 1.8.15 (Windows 10), Board: "ATmega328, Yes (UART0), EEPROM retained, 328PB, BOD 4.3V, LTO disabled, External 16 MHz"

Sketch uses 1256 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\1520004\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino18/bin/avrdude -CC:\Users\1520004\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/avrdude.conf -v -patmega328pb -carduino -PCOM8 -b115200 -D -Uflash:w:C:\Users\1520004\AppData\Local\Temp\arduino_build_81012/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\1520004\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/avrdude.conf"



         Using Port                    : COM8

         Using Programmer              : arduino

         Overriding Baud Rate          : 115200

         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 : Arduino

         Description     : Arduino

         Hardware Version: 3

         Firmware Version: 4.4

         Vtarget         : 0.3 V

         Varef           : 0.3 V

         Oscillator      : 28.800 kHz

         SCK period      : 3.3 us



An error occurred while uploading the sketch

avrdude: AVR device initialized and ready to accept instructions



Reading | ################################################## | 100% 0.00s



avrdude: Device signature = 0x1e950f (probably m328p)

avrdude: Expected signature for ATmega328PB is 1E 95 16

         Double check chip, or use -F to override this check.



avrdude done.  Thank you.



https://downloads.arduino.cc/libraries/library_index.json.sig file signature verification failed. File ignored.



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


Offline Psi

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: nz
Re: can't upload sketch after flashing bootloader - Atmega328PB
« Reply #2 on: May 21, 2022, 04:11:48 am »
You appear to be instructing avrdude to flash a Atmega328PB but avrdude is detecting that your chip is actually an Atmega328P   (no "B" on end, which is slightly different chip)

Are you sure your chip is Atmega328PB and not Atmega328P.

Even if the chip does say Atmega328PB on it, If you got it from a non legit source like aliexpress/ebay it maybe recycled and re-stamped with the wrong part number on it.

Try changing your IDE/code/avrdude command to be for a Atmega328P chip


https://www.pololu.com/file/0J1464/Atmel-42559-Differences-between-ATmega328P-and-ATmega328PB_ApplicationNote_AT15007.pdf

Quote
ATmega328PB is not a drop-in replacement for ATmega328 variants, but a
new device. However, the functions are backward compatible with the
existing ATmega328 functions. Existing code for these devices will work in
the new devices without changing existing configuration or enabling new
functions. The code that is available for your existing ATmega328 variants
will continue to work on the new ATmega328PB device.
« Last Edit: May 21, 2022, 04:17:02 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3020
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: can't upload sketch after flashing bootloader - Atmega328PB
« Reply #3 on: May 21, 2022, 05:24:20 am »
You appear to be instructing avrdude to flash a Atmega328PB but avrdude is detecting that your chip is actually an Atmega328P   (no "B" on end, which is slightly different chip)


Hazard a guess that avrdude is talking to his Uno, not the DUT.
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3020
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: can't upload sketch after flashing bootloader - Atmega328PB
« Reply #4 on: May 21, 2022, 05:28:55 am »
It is unclear exactly what you have connected where or what you are trying to achieve.

Once you have flashed the bootloader your target no longer needs to be connected to your programmer (Uno in your case), indeed remove the programmer from the equation entirely.

Your USB-UART chip (FTDI in your case, I prefer CP2012) should be connected thusly...

  * RX -> TX
  * TX -> RX
  * DTR -> 100nF Cap (Series) -> RESET
  * Vcc and Gnd as appropriate

Again, remove your programmer so you don't confuse the situation.

Once connected in the Arduino IDE Tools > Port choose the port your USB-Uart is on.

Then hit Upload, to Upload your sketch, not Upload Using Programmer you are no longer using a Programmer, just regular old upload.

~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline AndyNZTopic starter

  • Contributor
  • Posts: 16
  • Country: nz
Re: can't upload sketch after flashing bootloader - Atmega328PB
« Reply #5 on: May 21, 2022, 06:48:57 am »
Thanks for all replies.

@JDubU: I used the following settings when flashing the boot loader:
Board: MiniCore / Atmega328
Clock: external 16MHz
BOD: 2.7V and also tried 4.3V
EEPROM: retained
Compiler LTO disabled
Variant 328PB
Bootloader yes (UART0)
Programmer Arduino as ISP (MiniCore)

I wasn't sure if the resonator I selected is OK, but if I can upload the bootloader successfully it shows that it works, correct?

@Psi: Yes, I'm sure it's a 328PB, as I ordered it from the JLCPCB assembly service. And I managed to upload the boot loader successfully with the PB settings. But just in case I also tried to flash the 328P boot loader, which was not successful.

@sleemanj: Yes, I think you're right, that chip ID would match the Uno R3 I think. Which brings me back to square one: when I tried with the FT232R FTDI first, I got the "out of synch" message, so I gather it can't talk to the 328PB. I hooked it up initially without programmer and just with the FTDI board exactly like you suggested. Also I initially omitted the peripherals at the DTR pin (100n cap and 10k resistor to VCC), as that was what I was used to from the Arduino Pro Mini, but looking at the signal it was just pulling the DTR pin to ground when trying to upload, so I included the peripherals which gave a few us pulse, I think that's correct?
I'm unsure as to what board I select in the IDE, I tried the same settings that I used to flash the boot loader, i.e. the MiniCore Atmega328, variant 328PB and UART0, but since this didn't work I tried other options like Arduino AVR boards > Uno, Pro Mini and Nano, all of which gave the same out of synch error.

I've got two prototype boards, both gave the same result, so I think a faulty chip is unlikely. I think I'm making a newbie mistake somewhere, but where?

Again thanks for your input, it is much appreciated.
Cheers,
Andreas

 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3020
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: can't upload sketch after flashing bootloader - Atmega328PB
« Reply #6 on: May 21, 2022, 07:25:40 am »
You should not change the selection of board from between burning bootloader and uploading normally.

If you burnt bootloader for minicore 328PB then you should upload as minicore 328PB too.

Suggest you start again from square one, connect up programmer, burn bootloader, disconnect programmer, connect FTDI, upload sketch.

~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12807
Re: can't upload sketch after flashing bootloader - Atmega328PB
« Reply #7 on: May 21, 2022, 08:16:29 am »
The first thing to do, before revisiting the bootloader, is to check the target can run an Arduino sketch loaded using a programmer.  The customary 'Is it alive?' sketch to use is Examples>01.Basics>Blink, which flashes a LED, at 0.5Hz with 50% duty cycle.  If your board definition doesn't have LED_BUILTIN, change the three places it occurs in the sketch to a pin number for a pin you have connected to a LED (+ usual series resistor).  Compile, and Upload Using Programmer - if the LED doesn't blink and there were no errors during the upload, you've got a hardware problem.  If it blinks, time 30 flashes and if its *NOT* one minute, you've got an oscillator frequency problem.

Once Blink has run successfully, you need to exercise the AVR UART (Arduino serial interface) to check its working properly with your USB <=> UART adapter.  The easiest way to do that is to program the target with Examples>04.Communication>SerialEvent, which accepts text you type in a terminal program character by character then echos the whole line back to you when you press Enter (or more accurately when your terminal program sends a newline, ASCII(10) after you press enter).  It does that at 9600 baud, so configure your terminal accordingly.  If it doesn't work, check for connection problems and scope the AVR RX and TX pins to see what's going on.  Also try disconnecting the target and connecting RX to TX on your USB UART, to check that's OK, which should echo each character as soon as you send it. 

N.B. the Arduino built-in terminal buffers what you type and only sends it when you click the button.  Select 'Newline' at the bottom, next to the baud rate, for it to work with this sketch.

As the bootloader typically uses baud rates up to 115 Kbaud, change the baud rate in line 26 to:
Code: [Select]
Serial.begin(115200);and reprogram the target with the edited sketch, change your terminal program baud rate to 115200 and check it still works.

Assuming the above were all successful, carry on with Sleemanj's suggestions above (Reply#6).
« Last Edit: May 21, 2022, 10:14:21 am by Ian.M »
 

Offline AndyNZTopic starter

  • Contributor
  • Posts: 16
  • Country: nz
Re: can't upload sketch after flashing bootloader - Atmega328PB
« Reply #8 on: May 21, 2022, 09:10:52 am »
Quote
You should not change the selection of board from between burning bootloader and uploading normally.

That was what I've tried first, only when this was not successful I tried the other things in desperation.
I've also tried a new FTDI board, same result.

@Ian.M: I've just tried the blink sketch using the programmer (Uno R3) connected to the ISP header, nothing on the UART header. I left the settings same as when flashing the bootloader, not sure if I need to change "bootloader UART0" to "no bootloader". I get a device signature error, as it's recognizing the Uno R3:

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: Expected signature for ATmega328PB is 1E 95 16
         Double check chip, or use -F to override this check.

Not sure if that's what you suggested I try. So far I haven't been able to successfully upload any sketch, so the problems seem to be communication or settings related.
 

Offline AndyNZTopic starter

  • Contributor
  • Posts: 16
  • Country: nz
Re: can't upload sketch after flashing bootloader - Atmega328PB
« Reply #9 on: May 21, 2022, 09:48:47 am »
Result! I managed to upload a sketch by burning the bootloader using the internal 8MHz clock, then using the FTDI to upload the sketch.

So I guess the 328PB doesn't like the resonator I chose, I remember reading something about the requirements for the external oscillator, which I didn't understand so I went with a part that has been used for 328P before.

I've read about the internal clock being less accurate than an external resonator or crystal, but my application is not really time critical, so I'll try with the internal and see how I go.

 

Offline Kapple

  • Newbie
  • Posts: 1
  • Country: in
Re: can't upload sketch after flashing bootloader - Atmega328PB
« Reply #10 on: March 05, 2024, 09:49:18 pm »
Hey Andy!
I hope your circuit is running absolutely fine.
I have also run into the same problem. I have used an atmega328pb microcontroller and was able to bootload it while using an external 16 MHz oscillator.
On my board, I have a USB receptable and a FTDI232RL chip for serial programming. But I am unable to upload programmes with it. Can you please help me out?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf