Go Down

Topic: Uploading sketch to ATMega328p AU using internal clock (Read 437 times) previous topic - next topic

Kamool

Hello,

I'm working on project where I use ATMega328P on my custom designed board without external clock. On board there is also CH340E chip to communicate through serial.

How I bootload ATMega:
1. Get fresh Nano module,
2. Bootload it with 8MHz Bootloader.
3. Desolder it from board,
4. Solder it on my custom board.
5. Upload sketches etc.


Now there is a problem with AU chips when I try to upload sketch to my custom board. I cannot upload sketch. Everytime immediately after reseting chip (I have to do that manualy when "Overriding Baud Rate          : 57600" appears) I get error:
Code: [Select]
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:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x8c
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x84
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x94

avrdude done.  Thank you.


That's one kind of error, second one is:
Code: [Select]

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:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: stk500_getsync(): can't communicate with device: resp=0xfc

avrdude done.  Thank you.




And it only happen with ATMega328P AU chips.

I'm also using ATMega328P U-TH chips, and they work flawlessly.

So what could be the case?

Link to my drive folder where You can see photos of chips:
https://drive.google.com/open?id=1-QrwJpueFsfOk8UKEYoMo2E-sI3Rvooi


I've tried swaping CH340E modules, no luck. When I solder U-TH chip on board where previously was AU it works, so that's not a problem with board.

When I solder AU chip bard on Nano module and remove crystal I also get errors with Nano USB programming.

When I bootload AU chip back with stock 16MHz bootloader it works with no problem (but only on that bootloader)

My boards.txt file for 8MHz:

Code: [Select]

##############################################################

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05

atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard


atmega328bb.bootloader.tool=arduino:avrdude
atmega328bb.upload.tool=arduino:avrdude


pert

The internal oscillator is not as accurate as an external resonator or crystal. In addition, the baud rate error at 8MHz for the 57600 baud rate Arduino chose for the bootloader of that "breadboard" hardware package is 3.7%. If the internal oscillator of your chips is off in a direction that further increases the already significant baud rate error, this could cause the upload error you encountered. It's possible that the ATmega328P-U chips happen to have more favorable characteristics to their oscillators than the ATmega328P-AU. If you got each at the same time, it would make sense for each batch to have similar characteristics.

At 38400 baud and 8 MHz, the baudrate error is only 0.2%. For this reason, MiniCore uses that baud rate for its bootloader for ATmega328P @ 8 MHz. Here's how you can use MiniCore:

MiniCore uses the far superior Optiboot bootloader instead of the outdated and bloated "ATmegaBOOT" bootloader Arduino decided to use with their "Breadboard" hardware package. The switch to the optiboot bootloader will free up 1.5 kB of precious program memory on your ATmega328P and also will not subject you to the "ATmegaBOOT" bootloader's bug that causes your board to go into an endless reset loop after a watchdog reset. So it's a win all the way around!

Kamool

Tested that right now, still getting error:

Code: [Select]
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\xkam5\Documents\Arduino\hardware\MiniCore-master\avr/avrdude.conf"

         Using Port                    : COM3
         Using Programmer              : arduino
         Overriding Baud Rate          : 38400
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x4c
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x84
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x4c
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x84
avrdude: stk500_getsync(): can't communicate with device: resp=0x90

avrdude done.  Thank you.


 I've allready tried changing baud rate in boards.txt to even 9600 and nothing.
What is more - serial communication works, I can upload sketch with programmer, and ATMega both receives and sends data, so communication is established. But uploading sketch with programmer is not what I want, because I'd like to be able to change sketch after I potting in resing.


@EDIT

Right now I've tested MiniCore with ATMega328P U-TH which previously wasn't working - it was restarting during writing to flash memory and U-PH which had the same problem. Now it works, but there is still problem with AU chips...

@EDIT2

I've now bootloader all my chips with MiniCore, and now 2 U-TH + 1 U-PH can be programmed through USB, 3 different U-TH cannot, 3 AU also cannot... That's wierd...

pert

Well, I'm glad it's at least been partially helpful.

One thing to note is that when you do a Sketch > Upload Using Programmer, it erases the bootloader. You need to do a Tools > Burn Bootloader again after doing that to replace the bootloader before you can do an upload via your CH340.

Kamool

That work with 2 chips, on the rest I must stick to breadboard version, but on AU chips i must upload using programmer, and I won't be able to change programm i the future.

Guess I have to make such a good sketch that it won't need any updates in future.

dmjlambert

You could just always upload new sketches using programmer.   Put ICSP programming pins on the board.  

Kamool

That's not good way for me, I don't want headers / pins sticking from box. There are only USB and wires comming out of box.

pert

How often are you going to need to program the thing?

Go Up