Notes on the ATTiny 841

03 Jan 2014


Boat (27) 
Not the Boat (12) 


Recent articles

25 Apr 2017

Ubuntu 16.10 LXC host on ZFS Root, with EFI and Time Machine

Still completely unrelated to boats, but I needed somewhere to put this. Here is a blow-by-blow guide to installing a minimal Ubuntu 16.10 to a ZFS root, booted from EFI, which as used as a LXC host to act as an Apple "Time Machine" destination.
mike 25 Apr 2017 at 17:20
14 Mar 2017

How to connect any serial device to the internet

A completely generic script that will proxy serial devices over HTTP, turning USB-things into internet-things.
mike 14 Mar 2017 at 23:00

Working with the ATTiny841

Atmel released some new ATTinys in November 2013, essentially a refresh of the ATTiny 24/44/84. The new chips have quite a bit different, the highlights of which are (for me)

  • Proper I2C rather than the godawful USI framework. The I2C is I2C slave only, and uses the TWI_slave_vect interrupt which is on the ATTiny 828, rather than the TWI_vect interrupt which is on many of their other parts and which can serve as master or slave.
  • The fuse bits are different - careful!
  • The ADC differential channels are more flexible (the pins no longer have to be adjacent), and gain can be set to x1, x20 or x100 (the ATTiny84 only had x1 and x20
  • The power consumption during sleep can be reduced
  • Two full USARTs!
  • Dedicated SPI hardware, again not using the USI from the ATTiny84
  • Another 16 bit timer
  • Internal 4.096 reference voltage as well as the 1.1 reference from the ATtiny84. However it's still ±10% which makes it not very useful for me
  • The pullups on the input pins are not done with the DDR register, but with a new PUE register. It's possible to have then enabled even in output mode, which is a bit odd, but ties into another feature which is that when switching pins from input to output it's possible to set "make before break". In other words it's possible to switch the pin directly from input-pullup to output-low in one clock cycle without the pin floating. Handy for I2C, and it might explain why I could never get it to work properly with the older hardware...
  • Two of the output pins can optionally be set to "high power", which means they can sink more current when set to low output. Pins are still limited to 40mA per pin, like the older chips, so I think this is primarily useful if you're running the chips at low voltage, eg 1.8V

Hurdle 1: The pin names in the spec doesn't match the AVR includes

This wasn't a hurdle exactly, but took me a few minutes to figure out the error wasn't mine. Some of the registers described in the specification are spelled differently to the code in avr/iotn841.h - for instance, it's DDRB0 rather than DDB0. If your code isn't compiling, check that include for the definitive #define.

Hurdle 2: ArduinoISP and avrdude can't program

Note: it's; 2016 and I am still seeing lots of interest in this section. The avrdude.conf file listed here is way out of date. The latest version of avrdude should work with no changes.

Those are the good bits. The bad bits are that I can't program it with my existing ISP rig, which is based on the ArduinoISP and avrdude. I attempted to do so with the mods to /etc/avrdude.conf listed here (and available for download here - append this to /etc/avrdude.conf). But no luck: the firmware would appear to write, but verification would always fail. Atmel recommend their own AVRISPmkii and Atmel Studio 6.1 for programming, so I ordered one.

Hurdle 3: Atmel Studio needs to upgrade the firmware on my AVRISp and that doesn't work either!

Reluctantly I fired up a Windows VM and installed Atmel Studio 6.1, along with the update for the GCC and studio available for download here. Starting Studio shows my AVRIspmkii detected, but the firmware (1.11) is too old and needs updating to 1.17.

This fails. And the procedure described by Atmel to recover fails too - the device will no longer communicate with Atmel Studio 6.1 at all. This is not uncommon apparently and I can still flash older versions of the firmware with Atmel Studio 4 and 5, just not 6. However I need the new firmware supplied with Atmel Studio 6 for the Attiny841! What to do?

Here was my solution.

  1. Copy the firmware files from C:\Program Files\Atmel\Atmel Studio 6.1\tools\AVRISPmkII to C:\Program Files\Atmel\AVR Studio 5.0\tools\AVRISPmkII
  2. Short the reset pins as described here to reset the device
  3. Upgrade the firmware using Atmel Studio 5.0. It will use the firmware you copied from Studio 6.1 in the first step

Finally I have firmware 1.17 on the device. More to follow.

PostScript - Feb 2013

Not much more to say other than these chips are a welcome improvement over the Attiny84. The I2C is working flawlessly, the USART makes debugging a lot easier, and programming with avrdude and the AVRISPmkII is quick and works - I splashed out on a Tag Connect cable and with that connector on my boards, I can now flash about 10 a minute.