Author Topic: ATTiny(102) programming in cicurit  (Read 1249 times)

0 Members and 1 Guest are viewing this topic.

Offline bitmanTopic starter

  • Supporter
  • ****
  • Posts: 299
  • Country: us
  • Open Source Guy jabbing with Electronics
ATTiny(102) programming in cicurit
« on: April 19, 2020, 02:53:18 am »
For a while I've been using external programmers to program ATTiny chips. I'll like to try to move on to in-circuit programming, meaning be able to plug a ISP or USB into the board to program the unit while it sits in circuit.  But I'm not sure how to approach it.  How do you deal with existing load/connections on the SPI pins needed for programming?

So the challenge isn't making a circuit to program it - it's how can I switch off existing loads while "taking over" the few pins available to program it.
 

Offline djacobow

  • Super Contributor
  • ***
  • Posts: 1151
  • Country: us
  • takin' it apart since the 70's
Re: ATTiny(102) programming in cicurit
« Reply #1 on: April 19, 2020, 03:14:04 am »
There's no trick to it. Either don't use those pins for another purpose, or make sure the things connected are not driving when you want to program, and don't care about having their inputs toggled, or use logic or mux to switch between the tasks.

I've done all three approached. Personally, I prefer door number one: use a part with many pins and don't use the programming pins on your design for anything but programming.
 

Offline stafil

  • Regular Contributor
  • *
  • Posts: 205
  • Country: us
Re: ATTiny(102) programming in cicurit
« Reply #2 on: April 19, 2020, 03:15:46 am »
There's no trick to it. Either don't use those pins for another purpose, or make sure the things connected are not driving when you want to program, and don't care about having their inputs toggled, or use logic or mux to switch between the tasks.

I've done all three approached. Personally, I prefer door number one: use a part with many pins and don't use the programming pins on your design for anything but programming.

I think his problem is that ATTiny has so few pins, that he cannot afford to not use them for other purposes.
 

Offline djacobow

  • Super Contributor
  • ***
  • Posts: 1151
  • Country: us
  • takin' it apart since the 70's
Re: ATTiny(102) programming in cicurit
« Reply #3 on: April 19, 2020, 03:59:28 am »
There's no trick to it. Either don't use those pins for another purpose, or make sure the things connected are not driving when you want to program, and don't care about having their inputs toggled, or use logic or mux to switch between the tasks.

I've done all three approached. Personally, I prefer door number one: use a part with many pins and don't use the programming pins on your design for anything but programming.

I think his problem is that ATTiny has so few pins, that he cannot afford to not use them for other purposes.

Yes, that's why it's not a good idea to choose your microcontroller in advance of working out your IO requirements. If he can design is system to be tolerant of having random pins jiggled, and making sure that nothing else is driving the attiny's MOSI pin, and that the attiny's MISO pin is not fighting against something else, then he can just do it with no hardware. Otherwise you're looking at some glue, like some ttl logic or a pal or something to connect the "rest of system" or programmer. But once you're looking at some external logic, then the thrift of the attiny starts to look not so great. I guess you could also use jumpers or a carefully wired double-throw physical switch, but that defeats some of the elegance of in-system programming.
 

Offline bitmanTopic starter

  • Supporter
  • ****
  • Posts: 299
  • Country: us
  • Open Source Guy jabbing with Electronics
Re: ATTiny(102) programming in cicurit
« Reply #4 on: April 19, 2020, 04:40:02 am »
So I it sounds like I would need to design two ways of powering the circuit (which sorta is how it's done with ATTINY anwyay) and when powered from the programming connection, I bias a few transistors so they no longer allow connectivity to the rest of the circuit from the 3 pins needed (actually only two, since my circuit doesn't use RST for anything).
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 6781
  • Country: pl
Re: ATTiny(102) programming in cicurit
« Reply #5 on: April 19, 2020, 05:26:30 am »
You could use a manual switch or jumpers to choose between programing and operating mode.
Or use DIP package and socket it for easy external programming.

You don't need to power the MCU from the programmer. Even if its in-circuit VCC is different than the programmer's VCC, oftentimes some simple circuit can be cobbled together to connect them without issues.

ATtiny212/412 use only the reset pin for programming but has different programming interface and peripherals than the classic parts.
 

Offline JustMeHere

  • Frequent Contributor
  • **
  • Posts: 744
  • Country: us
Re: ATTiny(102) programming in cicurit
« Reply #6 on: April 19, 2020, 05:43:12 am »
 

Offline bitmanTopic starter

  • Supporter
  • ****
  • Posts: 299
  • Country: us
  • Open Source Guy jabbing with Electronics
Re: ATTiny(102) programming in cicurit
« Reply #7 on: April 19, 2020, 05:53:47 am »
I've never tried it, but the answer is on page 1 of the first document and page 4-5 of the second document.

http://ww1.microchip.com/downloads/en/AppNotes/doc8373.pdf
http://ww1.microchip.com/downloads/en/appnotes/atmel-0943-in-system-programming_applicationnote_avr910.pdf

I'm not sure I see that. I see stand-alone pins and how they should be connected. Not how you switch a pin from "runtime" to "programming" mode. With just 6 data pins (5 if you discount the "weak data pin" of RST) reducing that to 3 pins just to keep the programmer, doesn't leave room for even a CS for SPI programming to multiple devices.

In case I missed the obvious please correct me. Those documents very much shows how my current programmers are setup. For off-circuit programming.
 

Offline bitmanTopic starter

  • Supporter
  • ****
  • Posts: 299
  • Country: us
  • Open Source Guy jabbing with Electronics
Re: ATTiny(102) programming in cicurit
« Reply #8 on: April 19, 2020, 06:00:11 am »
You could use a manual switch or jumpers to choose between programing and operating mode.

I have plenty of dip switches, however I would need to lock all or nothing, not a combination of it. I looked for switches that would allow for two state (center pin, and two selectors) that would have 3x3 pins, and found very few and those that exist are HUGE and absolutely not in the price-range I'm willing to go to. I'm pretty sure I'll forget to set the dip-switches  - so something that automatically switches over will be needed or my brain-farts will screw it up eventually :D 

Quote
Or use DIP package and socket it for easy external programming.

That's pretty much what I do today. And I may just stick to it.

Quote
You don't need to power the MCU from the programmer. Even if its in-circuit VCC is different than the programmer's VCC, oftentimes some simple circuit can be cobbled together to connect them without issues.

Sorry, I don't understand this. Depending on the fuses set on the ATTINY I may need 12V on the RST pin. 12 volts will KILL everything else in that circuit.

Quote
ATtiny212/412 use only the reset pin for programming but has different programming interface and peripherals than the classic parts.

Correct - although you could put a small switch in to manually trigger the reset - for now I just keep it high. That means it's connected to the 3.3/5v (not sure which one it will be right now) would be hit by 12V if it got connected. I'm pretty sure that would end badly.
 

Offline JustMeHere

  • Frequent Contributor
  • **
  • Posts: 744
  • Country: us
Re: ATTiny(102) programming in cicurit
« Reply #9 on: April 19, 2020, 06:13:01 am »
I've never tried it, but the answer is on page 1 of the first document and page 4-5 of the second document.

http://ww1.microchip.com/downloads/en/AppNotes/doc8373.pdf
http://ww1.microchip.com/downloads/en/appnotes/atmel-0943-in-system-programming_applicationnote_avr910.pdf

I'm not sure I see that. I see stand-alone pins and how they should be connected. Not how you switch a pin from "runtime" to "programming" mode. With just 6 data pins (5 if you discount the "weak data pin" of RST) reducing that to 3 pins just to keep the programmer, doesn't leave room for even a CS for SPI programming to multiple devices.

In case I missed the obvious please correct me. Those documents very much shows how my current programmers are setup. For off-circuit programming.

Notice how they put resistors on the programming lines so that the programmer can override any other signal on the line.  Paragraph 2 section 2.2 of the AV910 document talks about this.

The thing I have done is to make sure all of my CS pins are held in their inactive position.  Since the AVR pins go high-z while in boot mode, biasing the CS pins on the peripherals makes sure they don't do anything until the AVR program is running and has control of the CS pins.
« Last Edit: April 19, 2020, 07:16:27 am by JustMeHere »
 

Offline bitmanTopic starter

  • Supporter
  • ****
  • Posts: 299
  • Country: us
  • Open Source Guy jabbing with Electronics
Re: ATTiny(102) programming in cicurit
« Reply #10 on: April 19, 2020, 06:41:30 am »
Notice how they put resistors on the programming lines so that the programmer can override any other signal on the line.  Paragraph 2 section 2.2 of the AV910 document talks about this.

Thanks!  But I see the following which would require me to implement similar "disconnect" ciccuitry:
Quote
The target system should never attempt to drive the three SPIlines while Reset is active.
Until I finally bread-board it I won't know if the input side would assert itself while programming and that would impact the SPI.
That said, I'm a bit puzzled that simple resistors will prevent signals from being interfeared with?  Well, I guess that's why I'm posting in "beginners".
 

Offline JustMeHere

  • Frequent Contributor
  • **
  • Posts: 744
  • Country: us
Re: ATTiny(102) programming in cicurit
« Reply #11 on: April 19, 2020, 07:22:39 am »
I edited my other reply.  The way I make sure none of the other things on the SPI don't do anything during programming is to use pull ups/pull downs to keep their CS in the idle state.  (This is why I've never checked to see how the resistor arrangement in the app notes work.)   
 

Offline JustMeHere

  • Frequent Contributor
  • **
  • Posts: 744
  • Country: us
Re: ATTiny(102) programming in cicurit
« Reply #12 on: April 19, 2020, 07:36:20 am »
That said, I'm a bit puzzled that simple resistors will prevent signals from being interfeared with?  Well, I guess that's why I'm posting in "beginners".

I think the idea is that the programmer will override any signal coming through a resistor. 

Ex:  Programmer has signal X high.  Mr. Talk out of Turn chip has signal X low.  Since there is a resistor between Programmer and Mr Talker, the state the Programmer puts the signal in will be the signal the device being programmed will see.    Honestly, this is kind of the way the reset buttons work on the Arduino. 
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf