Tiny UPDI-HV Programmer
24th January 2023
This is a simple High-Voltage UPDI programmer, for programming 0-series, 1-series, and 2-series ATtiny chips to allow you to configure the UPDI pin as a extra general I/O pin:
Flashing an LED on the UPDI pin of an ATtiny402,
by using the Tiny UPDI-HV Programmer to program it as an I/O pin.
For simplicity it is designed to work with an existing USB to Serial board, and an external 12V source.
Introduction
The ATtiny 0-series, 1-series, and 2-series chips allow you to get an extra I/O pin by reprogramming the UPDI pin as a general I/O pin. However, the downside is that you can't subsequently use a regular UPDI programmer to reprogram the chip. Microchip provide a reset mechanism, which involves applying a short pulse to the UPDI pin before programming it. Although the method is called 'High-Voltage Activation', the pulse is actually only 12V, slightly higher than the normal 3.3V or 5V voltage level.
This programmer extends a standard SerialUPDI programmer with extra circuitry to automatically apply the 12V HV pulse, and program an ATtiny chip even when the UPDI pin has been reprogrammed to another function.
History
I designed this programmer after I 'bricked' some microcontrollers by accidentally reprogramming the UPDI pins. Before designing it I studied some other HV UPDI programmers, including LeoNerd's AVR UPDI Programmer with 12V [1], and Dlloydev's Updi-Key [2]. The Microchip Developer Help was also useful [3].
How it works
The Tiny UPDI-HV Programmer is designed to work with an existing USB to Serial board configured as a SerialUPDI programmer.
It uses the DTR or RTS signal on the board, which is generated at the start of the UPDI signal, to trigger an analogue bidirectional switch. This briefly connects a 12V pulse to the UPDI line before connecting it back to the UPDI output from the USB to Serial board.
Other HV UPDI programmers often use a built-in boost converter or DC/DC converter to generate the 12V supply from the 3.3V/5V supply, but for simplicity this Tiny UPDI-HV Programmer uses an external 12V supply, such as from a 12V battery [4] or a lab supply.
Note: Before using HV programming you should remove any external circuitry from the UPDI pin that may interfere with the HV programming, or be damaged by the high-voltage pulse.
Reprogramming the UPDI pin function
You can use a standard UPDI programmer with the Arduino IDE Burn Bootloader function to configure the UPDI pin to another function. However, once you have changed the UPDI pin function, you need an HV programmer such as this Tiny UPDI-HV Programmer to program it, or reset it back to its UPDI function.
The three choices are:
- UPDI - This is the default
- GPIO - The pin can be used for standard input or output.
- RESET - The pin acts as a Reset pin.
For example, on the ATtiny202, ATtiny204, ATtiny406, or ATtiny807 the UPDI pin can be used as an extra digital input/output PA0, or as an extra analogue input AIN0. The same is true for the 1-series and 2-series parts. Note that if you use PA0 as an output, it has a lower drive capability than the other outputs.
Using the Tiny UPDI-HV Programmer as a standard UPDI programmer
If you don't need the HV feature in a particular application simply connect the +12V input to the 5V or 3.3V positive supply line. The programmer will then function as a standard UPDI programmer.
Compatible USB to Serial adapters
The circuit should work with any USB to Serial adapter, as long as it provides an RTS or DTR signal. I've tested it with the following:
Board | Power | Logic | RTS or DTR | Link |
Sparkfun FTDI Basic 5V * | 5V | 5V | DTR | FTDI Basic Breakout 5V |
Sparkfun FTDI Basic 3.3V * | 3.3V | 3.3V | DTR | FTDI Basic Breakout 3.3V |
Adafruit FTDI Serial-USB Cable 3V | 3.3V | 3.3V | RTS | FTDI Serial TTL-232 USB Type C Cable |
DFRobot USB to TTL Converter | 5V | 3.3V | RTS | USB to TTL Converter (CP210) |
SparkFun Serial Basic Breakout CH340C * | 3.3V | 3.3V | DTR | Serial Basic Breakout CH340C |
* You can convert the power/logic voltage of these by changing a solder link on the back.
I hope to add to this list as I hear about other USB to Serial boards that work too.
Note: USB to Serial adapters with only the four pins Rx, Tx, GND, and +5V are not suitable.
Are 3.3V logic levels compatible with 5V circuits?
Some of the USB to Serial converters for sale feature a 5V power output, but 3.3V logic levels. An example is the DFRobot USB to TTL Converter in the above table, or Adafruit's FTDI Serial TTL-232 USB Cable [5]. The idea is that you can use them to program 3.3V circuits by ignoring the 5V output, and powering the circuit from its own 3.3V supply.
Many guides to electronics repeat the statement that "3.3V logic levels are fine with 5V circuits". But is that really true?
If you look at the datasheets of the old ATtiny and ATmega devices, such as the ATtiny85 and ATmega328P, the specifications of the I/O pins state:
- Input high-voltage minimum (at 5V): 0.6VCC = 3.0V.
- Input low-voltage maximum (at 5V): 0.3VCC = 1.5V
In this case, because the minimum voltage for a '1' is 3.0V, 3.3V logic levels should be OK with a device powered from 5V.
However if you look at the same data for the new 0-series, 1-series, and 2-series chips such as the ATtiny402, the equivalent figures are:
- Input high-voltage minimum (at 5V): 0.7VDD = 3.5V.
- Input low-voltage maximum (at 5V): 0.3VDD = 1.5V
So the minimum voltage for a '1' is now 3.5V, and 3.3V logic levels may not be OK with a device powered from 5V. You might be lucky most of the time, but I don't recommend relying on this in a production circuit.
The circuit
Here's the circuit of the Tiny UPDI-HV Programmer:
Circuit of the Tiny UPDI-HV Programmer, based on a Maxim MAX4544 analogue switch.
The circuit is based on the Maxim MAX4544, an SPDT bidirectional analogue switch [6] that can run from a V+ supply of up to 12V, and it can switch signals up to V+. An alternative part is the Renesas ISL43210 [7] which is pin compatible and has a similar specification, but I haven't tried it.
The 10kΩ resistor and 10nF capacitor convert the level change on the DTR pin to a low pulse of about 100µs, as determined by the RC time constant (10e3 x 10e-9). This is within the range of 10ns to 4ms specified on the ATtiny datasheets.
The 470Ω resistor and Schottky diode implement the UPDI programmer recommended by Spence Konde: see SerialUPDI. Most Schottky diodes should be suitable.
I built the circuit on a mini breadboard [8]. The MAX4544 is in an SOT23-6 package so I mounted it on an Adafruit breakout board [9] to make it breadboard compatible:
The Tiny UPDI-HV Programmer built on a mini-breadboard.
Here's a diagram showing the layout on the mini breadboard, with the connections to the target and HV supply:
The connections to the Tiny UPDI-HV Programmer on a mini-breadboard.
There's space on the breadboard to the right of the Tiny UPDI-HV Programmer to fit an ATtiny202/402/212/412 on a breakout board while you're programming it, as shown in the photograph at the start of the article.
Example
Here's a worked example of using the Tiny UPDI-HV Programmer to program the UPDI pin on an ATtiny chip as an output, use it to blink an LED, and then program it back to a UPDI pin. In the following example I assume it's an ATtiny402, but any other 0-series, 1-series, or 2-series ATtiny chip should work.
Prepare megaTinyCore
The standard choice for programming the new ATtiny chips from the Arduino IDE is megaTinyCore [10] by Spence Konde; without his work none of this would be possible.
In the current version of megaTinyCore the menu options to reprogram the UPDI pin are commented out in the boards.txt file, to prevent users without an HV programmer from accidentally rendering their ATtiny chips unprogrammable. So the first step is to restore these menu options as follows:
- Locate the boards.txt file. It should have a pathname similar to:
/Users/david/Library/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.4/boards.txt
- Make a backup of the file.
- Open the original file in a text editor and locate the section headed UPDI/RESET PIN CONFIGURATION.
- Delete the '#' to uncomment each of the four lines in this section starting with:
#atxy7.menu.resetpin
- In the next section headed UPDI/RESET PIN CONFIGURATION uncomment the four lines starting with:
#atxy6.menu.resetpin
- In the next section headed UPDI/RESET PIN CONFIGURATION uncomment the six lines starting with:
#atxy4.menu.resetpin
- Finally, in the next section headed UPDI/RESET PIN CONFIGURATION uncomment the six lines starting with:
#atxy2.menu.resetpin
- Save the file.
Program the UPDI pin as a general I/O pin
Set up megaTinyCore [11] as follows:
- Choose the ATtiny412/402/212/202 option under the megaTinyCore heading on the Board menu.
- Check that the subsequent options on the Tools menu are set as follows (ignore any other options):
Chip: "ATtiny402" (or as appropriate)
UPDI/Reset Pin Function (burn bootloader req'd): "GPIO (DANGER ...)"
- Select the Port corresponding to the USB to Serial Board.
- Set Programmer: to SerialUPDI - 230400 baud.
- Choose Burn Bootloader.
In this case the command doesn't actually burn a bootloader, but configures the fuses (non-volatile memory locations) in the ATtiny chip to change the function of the UPDI pin.
Use the UPDI pin to flash an LED
The next step is to upload the following Blink program to the ATtiny:
void setup() { pinMode(PIN_A0, OUTPUT); } void loop() { digitalWrite(PIN_A0, LOW); delay(1000); digitalWrite(PIN_A0, HIGH); delay(1000); }
- Connect the +12V supply to the Tiny UPDI-HV Programmer.
- Choose Upload to upload the program to the ATtiny.
If the upload worked you should see:
Pinging device...
followed by:
Verify successful.
- Connect an LED and 1kΩ resistor between the UPDI pin (PA0) and GND.
- Reset the ATtiny402 by disconnecting the +5V supply and reconnecting it.
The LED should flash.
Program the UPDI pin back to its UPDI function
If you wanted to restore the UPDI pin back to its programming function you could do this as follows:
- Disconnect the LED, as it will interfere with the programming of the UPDI pin.
- Change the UPDI/Reset Pin Function menu option to "UPDI (no reset pin)".
- Connect the +12V supply to the Tiny UPDI-HV Programmer.
- Choose Burn Bootloader.
The ATtiny402 can now be programmed with normal UPDI, without the +12V signal.
What about the AVR DD-series?
The AVR DD-series chips also allow you to reprogram the UPDI pin, and they use a similar HV pulse to the Reset pin to restore the default UPDI function. I had hoped that this programmer would also work with AVR DD-series devices, but so far I haven't managed to get it to work. If I solve the problem I'll feature it in a future article.
Update
30th January 2023: Added a note that PA0 has a lower drive capability than the other outputs.
- ^ AVR UPDI Programmer with 12V on Tindie.
- ^ Updi-Key on GitHub.
- ^ UPDI High-Voltage Activation Information on Microchip Developed Help.
- ^ Energizer A27 Alkaline Battery 12V on Amazon.
- ^ FTDI Serial TTL-232 USB Cable on Adafruit.
- ^ MAX4541-MAX4544 datasheet on analog.com.
- ^ ISL43210 datasheet on Mouser.
- ^ Mini breadboard white on Sparkfun.
- ^ SMT Breakout PCB Set For SOT-23, SOT-89, SOT-223 and TO252 on Adafruit.
- ^ megaTinyCore on GitHub.
- ^ megaTinyCore on GitHub.
blog comments powered by Disqus