Cannot upload code when D9 or D10 connected to hardware debounced button

Hello Everyone,

I am having a problem that I can't seem to solve on my own:
I have an Atmega328p with Arduino bootloader on a pcb that has been working flawlessly for a long time now. I use the Arduino IDE 1.8.9 with a cheap FTDI serial adapter to upload code to the Atmega through the RX/TX pins. Works flawlessly every single time.

UNLESS I connect a hardware debounced button to either digital pins 9 or 10 (atmega pins 15 / 16). Then, I just get three flashes from the RX led on the serial adapter, the upload fails, and that's it. When I disconnect the button with an otherwise unchanged setup. everything works fine.

When I connect the same circuit to digital pins 11, 12, or 13 (atmega pins 17 / 18 /19) I can upload code without issues.

The button schematic looks like this:

The rest of the layout looks as follows:

All pins are broken out to keyed JST connectors. Depending on where I connect the button circuit, the upload works / works not.

The digital pins in question are configured as INPUT_PULLUP, but that shouldn't affect the upload process...

tl;dr

Can't upload code to Atmega328p when digital pins 9 or 10 are connected to button.

What am I overlooking?

Show us the actual wiring.

Show us the complete schematic.

It's a manufactured PCB, the wiring is 100% as defined by the schematic.
Everything works perfectly fine, except for the flashing issue i described in my initial post.

D9 and D10 (pins 15 and 16 on a DIP atmega328p) should be harmless here. However, if the pin 1 marker on the chip package is not so clear then you could misread pins 1 and 2 as pins 15 and 16, that is viewing the chip as rotated through 180 degrees. These pins are reset and RX respectively and connecting a capacitor between these pins and ground would probably show the symptoms you have described

Thanks for the answer, but that isn't the case here. Is really comes down to whether the button is connected to 9 / 10 or not. everything else is the same.

I expected them to be harmless as well, and the fact that the button circuit has no effect when connected to other pins baffles me.

The Atmega is soldered to the board (with pin1 in the right spot), so no room for error there :slight_smile:

And when you read the buttons connected to these pins with digitalRead() they behave normally?

I don't know if it is the cause of your problem but you should have a 0u1 ceramic decoupling capacitor on the power pins and ground of the ATmega 328p. The capacitor should connected as physically close to the pins as possible.

Looks like you're right on the money here. I just tested the DIs with the code below and found that Pin 9 is dead.

// use milliseconds as mock sysTick
unsigned long t0 = 0;

void setup() {
  // start serial comms
  Serial.begin(115200);

  // configure pins
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  
  // get current sysTick
  t0 = millis();
}

void loop() {
  // every 100 ms
  if (millis() - t0 >= 100){
    
    // get current sysTick
    t0 = millis();
    
    Serial.print("D9: ");
    Serial.print(!digitalRead(9));
    Serial.print(", D10: ");
    Serial.print(!digitalRead(10));
    Serial.print(", D11: ");
    Serial.print(!digitalRead(11));
    Serial.print(", D12: ");
    Serial.print(!digitalRead(12));
    Serial.print(", D13: ");
    Serial.println(!digitalRead(13));
    }
}

Oddly enough, that dead D9 pin seems to prevent proper flashing as soon as anyting is connected to it.

I can work around that.
(I was soo sure that the pin is OK. On second thought, I could have had that idea myself...)

Thanks!

Thanks for the input. I have a 100nF decoupling cap just next to the uC. However, I keep them in a corner of the schematic sheet, so they don't 'get in my way', that's why they're not in the screenshot I posted.

Thanks anyway!

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