[SOLVED] SCK pulses on when power is applied ATMEGA328P

Looking for advice:

The target board is a custom PCB with an ATMEGA328P. It has the Arduino boot loader installed and a version of the capacitor detect sketch. I am using PB5 pin 17 SCK as the output. The sketch works fine. But the output is activated when board is powered on. This is interpreted in my application as a false capacitance detect event with undesirable consequences. I think the output is being asserted by the boot loader starting up not the sketch code.

Does anyone know if it is the boot loader pulsing SCK on power up and is there a way to stop it doing that?

Otherwise I guess I could try another port pin but would have to hack up my PWB.

[SOLUTION] Since boot loader uses SCK to flash a LED so I used another pin. But it is set as input by boot loader till sketch starts. This caused the pin to be seen as a high so adding a 10K pull down ensures pin stays low till sketch starts and asserts as output. (I did not want to mess with boot loader.)

PB5/SCK on physical pin 17 indicates you are using TQFP package. Standard bootloader does flash the SCK pin a few times. You can change the bootloader to use a different pin, or not at all.

Not sure what's required to do that, am sure one of the software knowledgable folks can advise how.

All pins also go to Input state during reset, until your sketch takes over. Will you have problems with floating pins being sensed as inappropriate Highs or Lows?

CrossRoads: Not sure what's required to do that, am sure one of the software knowledgable folks can advise how.

I was able to rebuild the bootloader by adding the AVR toolset to the PATH and running the batch file that's included with the source code. In total, it took about 30 minutes to build and install a 1M baud bootloader. Turning off the blink-during-bootload should be about the same effort.

CrossRoads: All pins also go to Input state during reset, until your sketch takes over. Will you have problems with floating pins being sensed as inappropriate Highs or Lows?

Thanks I confirmed SCK is pulsed by boot loader so used pin 9 instead. (PD5). This time output (after buffer) was asserted even longer. I tried a few changes to the sketch to initialze at start but did not help. I think you are right about the pin floating. The pin is connected directly to an74HC05 cmos open drain buffer input. I will add a weak pull down (10K). That should hold it in known state till sketch takes over. Will post result.

Do you need the bootloader, or can you upload your code via ISP instead? Leaving it out would certainly be easier than hacking the PCB or the bootloader source.

Pins will still float until the part comes out of reset and the sketch kicks in.

I think I misunderstood, since the OP didn't specify what's connected to what. I thought the problem was that pin 13 is set HIGH during init, possibly charging a capacitor under test (? not sure what the "capacitor detect sketch" does), since it's connected to pin 13.

My thinking here was that floating pins might read high (and you won't be reading your own pins during reset anyway), but they won't be capable of driving a load high. Now I see there's another IC involved, which I guess is reading a floating pin, causing spurious input. I dunno, it's all vague. I give up.