Custom Nano board wont let me upload sketch. Have to reflash bootloader.

So I built my own Arduino PCB based on the Nano.
It has a few extra components on for 7 segment displays, wireless header and a few buttons.

Issue I am having is that I run the board for a few days and then when I try to upload a new sketch, it won't let me.

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x33
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access is denied.

I have to reflash the bootloader to get it to work.

Any ideas on what could be causing this?

Is the "run the board for a few days" part required to reproduce the problem, or does the same failure occur if you try to upload twice immediately after burning the bootloader?

pert:
Is the “run the board for a few days” part required to reproduce the problem, or does the same failure occur if you try to upload twice immediately after burning the bootloader?

Just tested uploading right after the first upload and it fails.

Sketch uses 14696 bytes (47%) of program storage space. Maximum is 30720 bytes.
Global variables use 1041 bytes (50%) of dynamic memory, leaving 1007 bytes for local variables. Maximum is 2048 bytes.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM5 -b57600 -D -Uflash:w:C:\Users\Jack\AppData\Local\Temp\arduino_build_895768/distance_meterMay.ino.hex:i 

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                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: ser_drain(): read error: The I/O operation has been aborted because of either a thread exit or an application request.


avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_drain(): read error: Access is denied.


avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_drain(): read error: Access is denied.


avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access is denied.


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x3b
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access is denied.


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x3b
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access is denied.


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x3b
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access is denied.


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x3b
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access is denied.


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x3b
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access is denied.


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x3b
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access is denied.


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x3b
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access is denied.


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x3b
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access is denied.


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x3b
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access is denied.


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x3b
avrdude: ser_drain(): read error: Access is denied.



avrdude done.  Thank you.

the selected serial port 
 does not exist or your board is not connected
processing.app.SerialException: Error opening serial port 'COM5'.
	at processing.app.Serial.<init>(Serial.java:147)
	at processing.app.Serial.<init>(Serial.java:82)
	at processing.app.SerialMonitor$2.<init>(SerialMonitor.java:131)
	at processing.app.SerialMonitor.open(SerialMonitor.java:131)
	at processing.app.AbstractMonitor.resume(AbstractMonitor.java:134)
	at processing.app.Editor.resumeOrCloseSerialMonitor(Editor.java:2135)
	at processing.app.Editor.access$1300(Editor.java:117)
	at processing.app.Editor$UploadHandler.run(Editor.java:2109)
	at java.lang.Thread.run(Thread.java:748)
Caused by: jssc.SerialPortException: Port name - COM5; Method name - openPort(); Exception type - Port not found.
	at jssc.SerialPort.openPort(SerialPort.java:167)
	at processing.app.Serial.<init>(Serial.java:136)
	... 8 more
Error opening serial port 'COM5'.

are you enabling the lock bits ? could you post your sketch

m_k_akash:
are you enabling the lock bits ? could you post your sketch

Not that I know of. This all used to work fine and I could re-upload the sketch before.
Can't post the sketch I am afraid.

why are you afraid to post the sketch no one will hang you right ? :slight_smile: :slight_smile:

m_k_akash:
why are you afraid to post the sketch no one will hang you right ? :slight_smile: :slight_smile:

It is rather large and has proprietary code in.

then could you explain in detail what does the code do ?

m_k_akash:
then could you explain in detail what does the code do ?

Measures distance with a sonar sensor and displays it on some 7 segment displays.

Just found an Arduino Nano and I can upload the sketch again and again.
So looks to be an issue with my PCB or bootloader on the boards.

I am using the old 328p bootloader as the new one does not work with my code.

could you try with the uno's bootloader ?

Usually the "can only upload once" symptom is caused by a missing auto-reset circuit. In order to upload, the bootloader must be activated. This is done by resetting the microcontroller at just the right time during the upload process. The Arduino Nano and the other Arduino boards with a dedicated USB to serial adapter chip have a special circuit that allows the IDE to automatically reset the board. If your board is missing this circuit (DTR or RTS pin of the USB to serial chip connected to the ATmega328P's reset pin) then the IDE won't be able to reset the board.

The reason the auto reset isn't required on the first upload after burning the bootloader is because the bootloader continues to run constantly after doing that.

You can test this by manually resetting the board. When you don't have that auto-reset, and are resetting manually, you need to get the timing right. If you press the reset button too early, the bootloader will have already timed out by the time the upload starts. The tricky thing is that when you press the "Upload" button in the Arduino IDE, it first compiles your sketch before starting the actual upload. So you need to wait until after the compilation finishes before pressing the reset button. The way to get the timing right is to watch the black console window at the bottom of the Arduino IDE window. As soon as you see something like this:

Sketch uses 444 bytes (1%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

press and release the reset button. The upload should now finish successfully.

pert:
Usually the "can only upload once" symptom is caused by a missing auto-reset circuit. In order to upload, the bootloader must be activated. This is done by resetting the microcontroller at just the right time during the upload process. The Arduino Nano and the other Arduino boards with a dedicated USB to serial adapter chip have a special circuit that allows the IDE to automatically reset the board. If your board is missing this circuit (DTR or RTS pin of the USB to serial chip connected to the ATmega328P's reset pin) then the IDE won't be able to reset the board.

The reason the auto reset isn't required on the first upload after burning the bootloader is because the bootloader continues to run constantly after doing that.

You can test this by manually resetting the board. When you don't have that auto-reset, and are resetting manually, you need to get the timing right. If you press the reset button too early, the bootloader will have already timed out by the time the upload starts. The tricky thing is that when you press the "Upload" button in the Arduino IDE, it first compiles your sketch before starting the actual upload. So you need to wait until after the compilation finishes before pressing the reset button. The way to get the timing right is to watch the black console window at the bottom of the Arduino IDE window. As soon as you see something like this:

Sketch uses 444 bytes (1%) of program storage space. Maximum is 30720 bytes.

Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.



press and release the reset button. The upload should now finish successfully.

I have a reset pin from the FTDI USB to Serial IC.

I'll check the capacitor and resistor values as well as continuity now.

pert:
DTR or RTS pin of the USB to serial chip connected to the ATmega328P's reset pin

I see from your schematic that you already know, but just to correct myself, I left off a very important part in this part of my last reply: via a 0.1 uF capacitor.

Ahahahah

The +5v from the resistor to the +5v rail is not connected. Looks like PCB error.

Yea this is why I hate Circuit Maker.
Try to connect it and it removes part of the +5v trace. Fking stupid software.

Surprised it got past DRC.