Atmega328P - SCK pin I am using Atmega328p with arduino bootloader in a project. There happens to be an LED connected on SCK pin. During Start (or restarts), the LED appears to flicker a couple of times (3 times to be exact). I don't want this to happen. I can change the connections but I would prefer a software solution because hardware change means a PCB modification.

I probed the SCK pin and I got some expected waveforms. There were two different cases:

1) When I powered the arduino using USB to serial programmer i.e. Tx Rx connected to a PC:



2) When I powered the arduino with an external power source (the case with my project):



This is what I think:

1) As mentioned in this thread, the bootloader has a piece of code which makes it act that way.
The bootloader code has a pin definition file which declares SCK pin as a LED and blinks it a couple of times to indicate that it has entered the bootloader. I found the code here:

#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duemilanove */ 
#define LED_DDR     DDRB
#define LED_PORT    PORTB
#define LED_PIN     PINB
#define LED         PINB5


Other relevant piece of code is here.

In this case, changing the LED definition to PINB4 and burning the bootloader and program again should take care of the issue. However this didn't work out for me. This is what I did exactly:

a) Opened the file D:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\optiboot\pin_defs.h

b) Modified the PINB5 to PINB4 on line 6.

c) Saved the file, burnt the bootloader and then program.

d) Powered up the chip and tested whether I am getting those 3 pulses. I got those 3 pulses.

(Even though it didn't work, I am still going to try it a few more times just in case I might have made an error.) :(

2) This brings me to second thought that since atmega328 accepts code through SPI by default, it checks for incoming data by clocking the SCK pins 3 times during startup. In this case, a software fix won't do anything.

What do you guys suggest? Should I go for the PCB modification or is there still some hope left?

Ignacio pointed out that I can disable bootloader to get rid of the issue. I want to program the chip using arduino IDE (preferably via UART) but I can consider SPI as well in case everything else fails.

Note: I am not sure whether this post is more suited for EE or Arduino. In case you guys(mods) think I'd get better suggestions there, feel free to move my post to Arduino.
There is nothing in the default megaAVR initialization that causes SCK to behave in this manner; it is all caused by the bootloader.

Fortunately all you have to do to solve this is disable the bootloader. Unprogramming the BOOTRST fuse (ext:0) will cause execution to start at address 0 instead of the beginning of the bootloader on reset.