Problem uploading code to ATMega168

Hello all,

I ordered 20 Arduino Nanos with the ATMega168 chip (Link). I want to solder them on my PCB but noticed a strange behavior. When I am first soldering the nano (there is non code uploaded yet) on my PCB and than uploading my code, I receive the following error message:

avrdude: stk500_recv(): programmer is not responding
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

When I first upload the code on the Nano and than soldering it to my PCB it works. I can upload new code afterwards. With my previous Nanos with a ATMega318 I did not have any issues. I can not imagine that my circuit of the PCB is the problem, because I can upload code to the Nanos when I first upload code and than soldering it to the PCB.
Does someone have an idea what is going on here?

Thank you,
Alex

Edit:
Here is the more detailed uploading log:

avrdude: Version 6.3-20190619
         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                    : COM17
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega168
         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        512    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     16384  128    128  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 : Arduino
         Description     : Arduino
avrdude: stk500_recv(): programmer is not responding
         Hardware Version: 2
         Firmware Version: 1.4611299
avrdude: stk500_recv(): programmer is not responding
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : 3.686 MHz
         SCK period      : 0.1 us

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

And this is the log with the Nano where I first uploaded the code and than soldered to the PCB:

avrdude: Version 6.3-20190619
         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                    : COM17
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega168
         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        512    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     16384  128    128  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 : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.16
         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.01s

avrdude: Device signature = 0x1e9406 (probably m168)
avrdude: reading input file "C:\Users\***\AppData\Local\Temp\arduino_build_165041/SolenoidManagerv4.ino.hex"
avrdude: writing flash (6134 bytes):

Writing | ################################################## | 100% 4.11s

avrdude: 6134 bytes of flash written
avrdude: verifying flash memory against C:\Users\***\AppData\Local\Temp\arduino_build_165041/SolenoidManagerv4.ino.hex:
avrdude: load data flash data from input file C:\Users\***\AppData\Local\Temp\arduino_build_165041/SolenoidManagerv4.ino.hex:
avrdude: input file C:\Users\***\AppData\Local\Temp\arduino_build_165041/SolenoidManagerv4.ino.hex contains 6134 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 3.70s

avrdude: verifying ...
avrdude: 6134 bytes of flash verified

avrdude done.  Thank you.

Are there anything in your PCB connecting to the pins 10-13 and RST of the soldered Nano?
Please show the schematic of the PCB

Here is the schematic. There is no pin 13, but Pin 10-11 is connected to a LED and RST pin is empty.

how do you upload a program in nano - via a ICSP programmer or through a USB or 0/1 pins?

I am using a USB Cable and connect it to my computer.

So you need disconnect HC05 module during upload.

Or, more precisely, you need disconnect anything from pins 0 and 1 of Nano, including the voltage divider R1 and R2

Because of the diode between Vin and VCC of the HC05 module, the HC05 is turned off when I am uploading. So the RX and TX Pins of the Arduino sould be empty. Otherwise I could not uploade code on the case first uploade code, than soldering, than upload code again?

I should add: There is no power on VCC and GND when I uploading code.

Why do you need the second upload if you uploaded it first?

You can argue. But I advise you to check - solder the arduino to the PCB, disconnect everything from pins 0 and 1 and try to flash

I have nothing more to add.
Good luck

I have to change the code because I am still working on it.
I guess the better question is: Why do I not first upload the code and then solder it, because this works. However, I am scared if the Arduino crashes and loses its code, I could have the same problem again.

I can not explain why that would work with a 328P and not with a 168 (without P). There are some electrical differences between the two processors that might result in the observed behaviour.

If the HC05 is not powered, it might be powered through the TX pin of the 168. Maybe the cause?

Those are just ideas. To fully investigate, you will have to sacrifice one of your PCBs and e.g. remove R1 or the HC05.

Thanks for your advice. I removed the HC05 of the PCB and could upload the code to the ardiuno. When I resolder the HC-05 I cannot upload a code again. But his time I am getting another error code than before:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x28

I tried it again with an adruino with an ATMega328P and it worked again. I think maybe you are right and the TX pin is getting powered? However the HC05 led is off the whole time.
But what confused me most is that the first ATMega168 is still working, altough I am using identical components. Very confusing...
But I guess I have to order more ATMega328P.

No, the Arduino TX pin supplies the power to the HC05 so it's still (kind of) powered. As a result, it interferes with the upload.

As said, kind of powered, possibly not enough to let the LED work.

So I was right and for normal upload it is necessary to remove hc05.

And you were arguing...

I used two more Nanos ATMega328P and now one of them also does not work. 3 of 4 are working. I am really confused, every compnent is identical and I think I soldered them correctly.

Someone has an idea?
The problem is that I do not want to remove the HC05 everytime I change the code.

Edit:
I measured the voltage on the HC05 during uploading and received different results. When I am measuring more than 20mV than the uploading is not working. On some boards I am beasuring up to 50mV. Is this because of the tolerance of the ATMega?

Still can't believe that used pins 0 and 1 interfere with the upload?
The fact is that uploading with connected pins becomes unstable. It may or may not happen - which is what you observe on the example of your boards. Even boards from the same batch are not exactly the same - which leads to different behaviour. And those boards that are currently working may stop at the next upload. And those that are not loaded - can start loading.

If you want stable work, disconnect HC05. In order not to remove the module - you can, for example, make switches on the board

1 Like

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