Bootloader erased after uploading sketch (atmega328p)

Hi all, I have an atmega328p 32 pins standalone, I am trying to burn a bootloader to run the avr on 1

MHz internal oscillator using Arduino as ISP.

After burning the bootloader, I monitored the bootloader content using Atmega_board_detector created by Gammon.
The Serial Monitor shows that the bootloader is used and has 512 bytes in size and the lock_bits=0xCF

Here’s the result :

Atmega chip detector.
Written by Nick Gammon.
Version 1.20
Compiled on Aug 7 2018 at 22:37:58 with Arduino IDE 10805.
Attempting to enter ICSP programming mode …
Entered programming mode OK.
Signature = 0x1E 0x95 0x0F
Processor = ATmega328P
Flash memory size = 32768 bytes.
LFuse = 0x62
HFuse = 0xDE
EFuse = 0xFF
Lock byte = 0xCF
Clock calibration = 0xA6
Bootloader in use: Yes
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 512 bytes starting at 7E00

Bootloader:

7E00: 0x11 0x24 0x94 0xB7 0x14 0xBE 0x89 0x2F 0x8D 0x70 0x11 0xF0 0x89 0x2F 0xDE 0xD0
7E10: 0x85 0xE0 0x80 0x93 0x81 0x00 0x82 0xE0 0x80 0x93 0xC0 0x00 0x88 0xE1 0x80 0x93
7E20: 0xC1 0x00 0x86 0xE0 0x80 0x93 0xC2 0x00 0x89 0xE1 0x80 0x93 0xC4 0x00 0x8E 0xE0
7E30: 0xB7 0xD0 0x25 0x9A 0x86 0xE0 0x23 0xEC 0x3F 0xEF 0x91 0xE0 0x30 0x93 0x85 0x00
7E40: 0x20 0x93 0x84 0x00 0x96 0xBB 0xB0 0x9B 0xFE 0xCF 0x1D 0x9A 0xA8 0x95 0x81 0x50
7E50: 0xA9 0xF7 0xEE 0x24 0xFF 0x24 0xB3 0xE0 0xAB 0x2E 0xBB 0x24 0xB3 0x94 0xA5 0xE0
7E60: 0xDA 0x2E 0xF1 0xE1 0xCF 0x2E 0x90 0xD0 0x81 0x34 0x71 0xF4 0x8D 0xD0 0x08 0x2F
7E70: 0x9D 0xD0 0x02 0x38 0x11 0xF4 0x82 0xE0 0x05 0xC0 0x01 0x38 0x11 0xF4 0x86 0xE0
7E80: 0x01 0xC0 0x83 0xE0 0x79 0xD0 0x75 0xC0 0x82 0x34 0x11 0xF4 0x84 0xE1 0x03 0xC0
7E90: 0x85 0x34 0x19 0xF4 0x85 0xE0 0x92 0xD0 0x6C 0xC0 0x85 0x35 0x79 0xF4 0x74 0xD0
7EA0: 0xE8 0x2E 0xFF 0x24 0x71 0xD0 0x08 0x2F 0x10 0xE0 0x10 0x2F 0x00 0x27 0x0E 0x29
7EB0: 0x1F 0x29 0x00 0x0F 0x11 0x1F 0x7A 0xD0 0x78 0x01 0x5B 0xC0 0x86 0x35 0x21 0xF4
7EC0: 0x84 0xE0 0x7C 0xD0 0x80 0xE0 0xDE 0xCF 0x84 0x36 0x09 0xF0 0x35 0xC0 0x5C 0xD0
7ED0: 0x5B 0xD0 0x18 0x2F 0x59 0xD0 0x08 0x2F 0xC0 0xE0 0xD1 0xE0 0x55 0xD0 0x89 0x93
7EE0: 0x1C 0x17 0xE1 0xF7 0x63 0xD0 0x05 0x34 0x09 0xF4 0xFF 0xCF 0xF7 0x01 0xA7 0xBE
7EF0: 0xE8 0x95 0x07 0xB6 0x00 0xFC 0xFD 0xCF 0xA7 0x01 0xA0 0xE0 0xB1 0xE0 0x2C 0x91
7F00: 0x30 0xE0 0x11 0x96 0x8C 0x91 0x11 0x97 0x90 0xE0 0x98 0x2F 0x88 0x27 0x82 0x2B
7F10: 0x93 0x2B 0x12 0x96 0xFA 0x01 0x0C 0x01 0xB7 0xBE 0xE8 0x95 0x11 0x24 0x4E 0x5F
7F20: 0x5F 0x4F 0x1A 0x17 0x61 0xF7 0xF7 0x01 0xD7 0xBE 0xE8 0x95 0x07 0xB6 0x00 0xFC
7F30: 0xFD 0xCF 0xC7 0xBE 0xE8 0x95 0x1D 0xC0 0x84 0x37 0x69 0xF4 0x25 0xD0 0x24 0xD0
7F40: 0x08 0x2F 0x22 0xD0 0x00 0x66 0xE7 0x01 0xFE 0x01 0x85 0x91 0xEF 0x01 0x14 0xD0
7F50: 0x01 0x50 0xD1 0xF7 0x0E 0xC0 0x85 0x37 0x39 0xF4 0x28 0xD0 0x8E 0xE1 0x0C 0xD0
7F60: 0x85 0xE9 0x0A 0xD0 0x8F 0xE0 0x8E 0xCF 0x81 0x35 0x11 0xF4 0x88 0xE0 0x18 0xD0
7F70: 0x1D 0xD0 0x80 0xE1 0x01 0xD0 0x77 0xCF 0x98 0x2F 0x80 0x91 0xC0 0x00 0x85 0xFF
7F80: 0xFC 0xCF 0x90 0x93 0xC6 0x00 0x08 0x95 0x80 0x91 0xC0 0x00 0x87 0xFF 0xFC 0xCF
7F90: 0x80 0x91 0xC0 0x00 0x84 0xFD 0x01 0xC0 0xA8 0x95 0x80 0x91 0xC6 0x00 0x08 0x95
7FA0: 0xE0 0xE6 0xF0 0xE0 0x98 0xE1 0x90 0x83 0x80 0x83 0x08 0x95 0xED 0xDF 0x80 0x32
7FB0: 0x19 0xF0 0x88 0xE0 0xF5 0xDF 0xFF 0xCF 0x84 0xE1 0xDE 0xCF 0x1F 0x93 0x18 0x2F
7FC0: 0xE3 0xDF 0x11 0x50 0xE9 0xF7 0xF2 0xDF 0x1F 0x91 0x08 0x95 0x28 0x2E 0x80 0xE0
7FD0: 0xE7 0xDF 0xEE 0x27 0xFF 0x27 0x09 0x94 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
7FE0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
7FF0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x02 0x06

MD5 sum of bootloader = 0x1A 0xE6 0x33 0x4C 0xEB 0x94 0xB2 0xEB 0x13 0xCB 0x1D 0x4C 0x13 0xE7 0xB7 0xA1
Bootloader MD5 sum not known.

First 256 bytes of program memory:

00: 0xFF 0xFF 0xFF 0xF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 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
D0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
E0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
F0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF

Programming mode off.

Now when trying to upload the Blink sketch, the first thing the blink sketch doesn’t work, the second thing I retry monitoring the result, after uploading the blink sketch, using Atmega_board_detector sketch.

adnano1234:
Now when trying to upload the Blink sketch

How did you do the upload?

Here's the result:

Atmega chip detector.
Written by Nick Gammon.
Version 1.20
Compiled on Aug 7 2018 at 22:42:36 with Arduino IDE 10805.
Attempting to enter ICSP programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x95 0x0F
Processor = ATmega328P
Flash memory size = 32768 bytes.
LFuse = 0x62
HFuse = 0xDE
EFuse = 0xFF
Lock byte = 0xFF
Clock calibration = 0xA6
Bootloader in use: Yes
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 512 bytes starting at 7E00

Bootloader:

7E00: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
7E10: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
7E20: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
7E30: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
7E40: 0xFF 0xFF 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 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
7FD0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
7FE0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
7FF0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF

MD5 sum of bootloader = 0xDE 0x03 0xFE 0x65 0xA6 0x76 0x5C 0xAA 0x8C 0x91 0x34 0x3A 0xCC 0x62 0xCF 0xFC
No bootloader (all 0xFF)

First 256 bytes of program memory:

00: 0x0C 0x94 0x5C 0x00 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00
10: 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00
20: 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00
30: 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00
40: 0x0C 0x94 0x15 0x01 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00
50: 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00
60: 0x0C 0x94 0x6E 0x00 0x0C 0x94 0x6E 0x00 0x00 0x00 0x00 0x00 0x24 0x00 0x27 0x00
70: 0x2A 0x00 0x00 0x00 0x00 0x00 0x25 0x00 0x28 0x00 0x2B 0x00 0x04 0x04 0x04 0x04
80: 0x04 0x04 0x04 0x04 0x02 0x02 0x02 0x02 0x02 0x02 0x03 0x03 0x03 0x03 0x03 0x03
90: 0x01 0x02 0x04 0x08 0x10 0x20 0x40 0x80 0x01 0x02 0x04 0x08 0x10 0x20 0x01 0x02
A0: 0x04 0x08 0x10 0x20 0x00 0x00 0x00 0x08 0x00 0x02 0x01 0x00 0x00 0x03 0x04 0x07
B0: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x11 0x24 0x1F 0xBE 0xCF 0xEF 0xD8 0xE0
C0: 0xDE 0xBF 0xCD 0xBF 0x21 0xE0 0xA0 0xE0 0xB1 0xE0 0x01 0xC0 0x1D 0x92 0xA9 0x30
D0: 0xB2 0x07 0xE1 0xF7 0x0E 0x94 0x5F 0x01 0x0C 0x94 0xC9 0x01 0x0C 0x94 0x00 0x00
E0: 0xE1 0xEB 0xF0 0xE0 0x24 0x91 0xED 0xE9 0xF0 0xE0 0x94 0x91 0xE9 0xE8 0xF0 0xE0
F0: 0xE4 0x91 0xEE 0x23 0x09 0xF4 0x3B 0xC0 0x22 0x23 0x39 0xF1 0x23 0x30 0x91 0xF0

Programming mode off.

What's Wrong?
I notice that Lock_bits change its value to 0xFF, Why?
Please helps.

pert:
How did you do the upload?

SPI using Arduino as ISP

here's the verbose output of burning bootloader:

Using Port : COM15
Using Programmer : stk500v1
Overriding Baud Rate : 19200
AVR Part : ATmega328P
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
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 : 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 = 0x1e950f (probably m328p)
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\Youssef\Desktop\Arduino\hardware\arduino\avr/bootloaders/myoptiboot/optiboot_atmega328_01M_004800_D13.hex"
avrdude: writing flash (32768 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 32768 bytes of flash written
avrdude: verifying flash memory against C:\Users\Youssef\Desktop\Arduino\hardware\arduino\avr/bootloaders/myoptiboot/optiboot_atmega328_01M_004800_D13.hex:
avrdude: load data flash data from input file C:\Users\Youssef\Desktop\Arduino\hardware\arduino\avr/bootloaders/myoptiboot/optiboot_atmega328_01M_004800_D13.hex:
avrdude: input file C:\Users\Youssef\Desktop\Arduino\hardware\arduino\avr/bootloaders/myoptiboot/optiboot_atmega328_01M_004800_D13.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.03s

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.

adnano1234:
SPI using Arduino as ISP

It's expected for that to erase the bootloader so what you're experiencing is completely normal. The whole point of the bootloader is to allow you to upload over serial. If you're using the ISP programmer to upload then a bootloader is not needed.

Ok, Thank you very much.
But why Blink sketch doesn't work?

adnano1234:
Ok, Thank you very much.
But why Blink sketch doesn't work?

All sketches don't work

It's difficult to say since I don't have much information to work with. A common mistake is that the physical pin number doesn't match the Arduino pin number used with the standard Arduino API functions like digitalWrite(), etc. You need to make sure the LED is connected to the correct pin. Using the standard pin mapping for ATmega328P, Arduino pin 13 is mapped to PB5:

Yes, I check all wiring, same problem.

How can I erase The flash completely and start the program memory from the beginning of the memory,(erase the partition of bootloader shown in Arduino_board_detector screen output)?

Sorry

I found the problem, it was the reset Pin!
I detach the reset pin of target avr from chip select(pin 10) of programmer and attach it to 5v.
But I faced a problem with timing, I set the fuse settings to run the AVR on 1 MHz, but the delay function spent now 16 seconds!
Is this normal?

adnano1234:
I found the problem, it was the reset Pin!

Glad to hear!

adnano1234:
But I faced a problem with timing, I set the fuse settings to run the AVR on 1 MHz, but the delay function spent now 16 seconds!
Is this normal?

It is normal when you're using a 16 MHz board definition on a chip running at 1 MHz. You need to use a 1 MHz board definition. I recommend using MiniCore:

  • Install MiniCore
  • Tools > Board > ATmega328
  • Tools > Clock > 1 MHz Internal

Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Gowthm\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10805 -build-path C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079 -warnings=none -build-cache C:\Users\Gowthm\AppData\Local\Temp\arduino_cache_385920 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose H:\full\electronic\sfx\arduino-1.8.3- sfx\Arduino-1.8.5\examples\01.Basics\Blink\Blink.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Gowthm\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10805 -build-path C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079 -warnings=none -build-cache C:\Users\Gowthm\AppData\Local\Temp\arduino_cache_385920 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose H:\full\electronic\sfx\arduino-1.8.3- sfx\Arduino-1.8.5\examples\01.Basics\Blink\Blink.ino
Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079\sketch\Blink.ino.cpp" -o "nul"
Generating function prototypes...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079\sketch\Blink.ino.cpp" -o "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079\sketch\Blink.ino.cpp" -o "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079\sketch\Blink.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core
Linking everything together...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079/Blink.ino.elf" "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079\sketch\Blink.ino.cpp.o" "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079/..\arduino_cache_385920\core\core_arduino_avr_uno_0c812875ac70eb4a9b385d8fb077f54c.a" "-LC:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079" -lm
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079/Blink.ino.elf" "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079/Blink.ino.eep"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-objcopy" -O ihex -R .eeprom "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079/Blink.ino.elf" "C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079/Blink.ino.hex"
Sketch uses 928 bytes (2%) 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:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM10 -b115200 -D -Uflash:w:C:\Users\Gowthm\AppData\Local\Temp\arduino_build_56079/Blink.ino.hex:i

An error occurred while uploading the sketch
avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
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 : COM10
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: ser_open(): can't set com-state for "\.\COM10"

avrdude done. Thank you.

pert:
Glad to hear!
It is normal when you're using a 16 MHz board definition on a chip running at 1 MHz. You need to use a 1 MHz board definition. I recommend using MiniCore:
GitHub - MCUdude/MiniCore: Arduino hardware package for ATmega8, ATmega48, ATmega88, ATmega168, AT

  • Install MiniCore
  • Tools > Board > ATmega328
  • Tools > Clock > 1 MHz Internal

A big thanks to you Pert, really your ideas were very helpful!

Actually, I faced a strange thing, the avr I worked with, a LoRa module will be connected to it ( via SPI), and my PCB consists of the avr and the LoRa module. When the LoRa is detached from the PCB, I can change the fuse setting and upload a sketch normally to Avr, but when soldering the LoRa to the PCB I can't do anything with Avr, the Arduino IDE output gives:

avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.

P.S: the Avr runs on the internal oscillator.