ATTiny(102) programming in cicurit - Page 1
Forum section: electronics / beginners

author: bitman
author_rank: Unknown
timestamp: April 19, 2020, 02:53:18 am
content: 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.

author: djacobow
author_rank: Super Contributor
timestamp: April 19, 2020, 03:14:04 am
content: 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.

author: stafil
author_rank: Regular Contributor
timestamp: April 19, 2020, 03:15:46 am
content: Quote from: djacobow on April 19, 2020, 03:14:04 amI think his problem is that ATTiny has so few pins, that he cannot afford to not use them for other purposes.

author: djacobow
author_rank: Super Contributor
timestamp: April 19, 2020, 03:59:28 am
content: Quote from: stafil on April 19, 2020, 03:15:46 amYes, 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.

author: bitman
author_rank: Unknown
timestamp: April 19, 2020, 04:40:02 am
content: 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).

author: magic
author_rank: Super Contributor
timestamp: April 19, 2020, 05:26:30 am
content: 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.

author: JustMeHere
author_rank: Frequent Contributor
timestamp: April 19, 2020, 05:43:12 am
content: 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.pdfhttp://ww1.microchip.com/downloads/en/appnotes/atmel-0943-in-system-programming_applicationnote_avr910.pdf

author: bitman
author_rank: Unknown
timestamp: April 19, 2020, 05:53:47 am
content: Quote from: JustMeHere on April 19, 2020, 05:43:12 amI'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.

author: bitman
author_rank: Unknown
timestamp: April 19, 2020, 06:00:11 am
content: Quote from: magic on April 19, 2020, 05:26:30 amI 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 eventuallyQuoteThat's pretty much what I do today. And I may just stick to it.QuoteSorry, 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.QuoteCorrect - 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.

author: JustMeHere
author_rank: Frequent Contributor
timestamp: April 19, 2020, 06:13:01 am
content: Quote from: bitman on April 19, 2020, 05:53:47 amNotice 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.

author: bitman
author_rank: Unknown
timestamp: April 19, 2020, 06:41:30 am
content: Quote from: JustMeHere on April 19, 2020, 06:13:01 amThanks! But I see the following which would require me to implement similar "disconnect" ciccuitry:QuoteUntil 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".

author: JustMeHere
author_rank: Frequent Contributor
timestamp: April 19, 2020, 07:22:39 am
content: 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.)

author: JustMeHere
author_rank: Frequent Contributor
timestamp: April 19, 2020, 07:36:20 am
content: Quote from: bitman on April 19, 2020, 06:41:30 amI 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.