Can't program when PB0 is switched

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi experts

 

I have a closed switch onto PB0 with pull-up enabled and can't program the AVR during this state. 

If I open the switch I can program the AVR without any issue.

How would I go about configuring this pin for the avr to be programmable when the switch is closed?

int main(void)
{
    DDRB &= ~(1<<0);  // PB0 as input
    PORTB |= (1<<0);  // Pull-up enabled on PB0
}

Thanks

This topic has a solution.
Last Edited: Mon. Sep 16, 2019 - 04:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Presuming a couple of things that you neglected to mention:

 

1) Your switch shorts PB0 to ground

2) Your AVR uses the same pin as PB0 for programming

2a) You didn't mention WHICH AVR.  There's lots of them.

 

Then it is going to be very unhappy and you'll need to move your switch elsewhere.  There are other more complex ways of dealing with it too (e.g. put a resistor (5k or so) between the pin and the switch, and use an external pullup, while connecting the programmer directly to the pin).  &c.  We lurv schematics around here.  S.

 

Edited to correct my own errors in thinking it was a pushbutton, not a switch.  S.

Last Edited: Mon. Sep 16, 2019 - 03:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

1) Your switch shorts PB0 to ground

 A. Correct

2) Your AVR uses the same pin as PB0 for programming

 A. Correct (MOSI)

2a) You didn't mention WHICH AVR.  There's lots of them.

 A. Apologies. Tiny85

 

Wanted to avoid the voltage divider hence why I've omitted the external R on the pulled-up pin.

Schematic is being drafted as I type, that's why I didn't bother. Just a 2P switch hooked to PB0 and GND at the moment.

 

Let me know if you can think of anything, I'd really want to keep this switch there but can change it if absolutely necessary.

 

Last Edited: Mon. Sep 16, 2019 - 04:02 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

What you need is something like this:

 

Pin Isolation Schematic

Resistor values probably a bit low.  Up to 47k or so would be fine.  Turn OFF the AVR's own pullup.  S.

Last Edited: Mon. Sep 16, 2019 - 04:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This actually works perfectly, magic!

Sincerely appreciated. Promise to learn electronics in due time, let me get that switch working first ;)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

No problem.  Have fun!   S.