New Part Day: ATtiny102 And 104

Atmel put out some new, small microcontroller chips early this year, and we’re just now starting to think about how we’d use them. The ATtiny102 and ATtiny104 (datasheet) sell for about a buck (US) and come in manageable SOIC packages with eight and fourteen pins respectively. It’s a strange chip though, with capabilities that fit somewhere between the grain-of-rice-sized ATtiny10 and the hacker-staple ATtiny25-45-85 series.

The ATtiny104 has a bunch of pins for not much money. It’s got a real hardware USART, which none of the other low-end AVRs do, and it’s capable of SPI in master mode. It has only one counter, but it’s a 16-bit counter, and it’s got the full AVR 10-bit ADC instead of the ATtiny10’s limited 8-bit ADC. The biggest limitation, that it shares with the ATtiny10, is that it has only 1 KB of program flash memory and 32 bytes (!) of RAM. You’re probably going to want to program this beast in assembler.

Read on for more reviews, and check out [kodera2t]’s video review at the end.

Reviews

attiny_comparisonThe first review comes courtesy of [Dan Watson] on his blog. He bought one of the Atmel Xplained 104 Nano evaluation boards back in March and put it through its paces. We don’t know how he got one for under $5 back then, but the kit seems available for under $10 from the usual suspects.

The Xplained kit is funny. It’s got a relatively powerful ATmega32u4 serving as an in-system programmer and USB-serial connector for the Tiny part. That’s funny because the programmer costs twice as much as the device under test.

[Dan] also presents a nice comparison chart of the small AVR parts. (Click to embiggen.)

[kodera2t] has been pushing the ATtiny series of chips to the max for a few months now, so we were stoked to see his review of the ATtiny102. Given the chip designation (T102-ES), he managed to get himself some engineering samples, which is extra cool-points, but shouldn’t discourage you because the parts are in stores now.

attiny102_104_pinoutsInstead of working with an evaluation board, [kodera2t] did everything from scratch. Maybe that’s why he emphasizes the new pinouts of the ATtiny102 parts. In particular, the GND pin is where the VCC pin is located on other ATtiny chips(!). It pays to read the datasheets. Although we’re grumpy and hate change, the new pinout is much more rational, with the VCC and GND pins together at the top of the chip, right where you want to add a decoupling capacitor anyway.

There’s one other minor gotcha if you’re used to working with the ATtiny parts. Because the ATtiny104 has fourteen pins, the GPIOs are split into two eight-bit banks: PORTA and PORTB. The ATtiny102 seems to be a chopped-down version of the 104, which means that even though it only has six GPIO pins, they’re still spread out across the two banks — three pins in each. If you’re accustomed to writing whole bytes at a time to GPIO output, this’ll force you to change your coding habits.

Uses

brief-review-of-attiny102-2j4y0pxxnq0mkv-shot0005_thumbnailWe find ourselves scratching our heads and asking what this chip is good for. The USART in a small and cheap package is a great feature. Something like the ATtiny14, with eleven or twelve free GPIO pins, fits a nice niche for very small projects. But we can’t quite get our heads around the 32 bytes of RAM. Whatever applications there are for the USART will have to reckon with a short receive buffer, for instance, and do its processing on the fly. C startup code alone costs a few hundred bytes, and with such limited RAM, we are guessing that coding assembler is the only reasonable option.

Of course, the hacker market was probably not even on Atmel’s radar when designing and marketing this chip. It must be good for some industrial use that we can’t quite figure out. What needs USART but doesn’t need much program or RAM? What uses can you think up for such a niche device?

89 thoughts on “New Part Day: ATtiny102 And 104

    1. More specifically, the assembler is the program that assembles assembly language into machine code. However, it is less commonly known as assembler language as well, though it grates on the nerves of those who actuallt program in assembly language. We know that you know what he meant, so pedantry is not essential to understanding here.

    2. Oh, on another reading, you were questioning “beast”, not “assembler”. I see… Actually, severely limited resources can be more beastly and less civilized than larger devices. Gnats bite.

      1. You can try your luck on ebay. Ebay does sell a lot of good tech *things* mostly from China but chips are often fake. Even the chips in the left article picture look fake because of the color of the print but I suspect that that is because the color temperature when the pic as taken is low like 2700 – 3600 degrees Kelvin.

        A lot of CPU’s and micro-controllers from ebay are chips that have had the tops ground off and reprinted with a part number of a better spec or faster chip. I don’t know if normal color vision people can see it but the color of the reprint is a white with a lower color temperature so it looks ever so slightly yellow’ish under a high color temperature white light. I use a 5700 degree Kelvin white light for inspection of parts.

        The other give away is that the pins are often splayed further apart than normal. I have even had chips arrive with grinding oil still on them lol. One other give away is the depth of the orientation hole. It’s shallower from the grinding off of the original label.

        It’s not a big issue for more experienced buyers as you can spot the fakes.

  1. 32 bytes of RAM? Is this 1982 again?

    Even the lowest end STM32 part (STM32F030F4) blows this thing out of the water: 16kB flash, 4kB RAM, 4 timers, 9 12-bit ADC, SPI, UART, I2C, interrupt on every single IO, and in TSSOP20 package as well. And cheaper too.

    Why even bother.

      1. We’ll need some backup data on that. Last time I’ve checked, my design used a lot less power when I estimated power usage with an STM32F0 because that one woke up, had more computational power/MHz and a lower W/MHz, then went back to stop mode and used effectively less power than coin cell self-discharge. so, at the worst, it’d be a “emotional” tie, because both chips, when not doing something, are extremely power-saving. As soon as I needed to wake up the Attiny for regular maintenance, I couldn’t use its ultra-low power modes, and the SMT32F0 actually had a lower average power consumption.

        1. DMA helps quite a bit in power management as the CPU clock doesn’t need to be fast or waste cycles polling or servicing peripheral IRQ. The flexible clocking let you shift clock speeds on the fly, shut off unused parts or runs lower clock speed for peripherals.
          If you ever need to bit-bang on a chip because it doesn’t have the peripherals you need, all that power saving claims goes out the window.

        2. Please provide more details, I am curious about the scenario.
          My datasheet checks shows the tiny drawing 1.2mA@4MHz and the STM32F030F4 using 4.4mA@8MHz, needing about 2x the current per operation. In sleep the tiny has max 10uA@125C with running timer AND interrupts which would burn up to 32uA on the STM32.

          1. Cycle count for a 8-bit chip is going to be a lot higher if you need it to operate outside of 8-bit math or need to shift bits or multiply. So “2x the current per operation” isn’t comparing the same thing.

          2. Also most 8-bit microcontrollers, especially in Attiny or PIC10F/12F families have no hardware multiply capability. ARM Cortex-M0 has. So when you need to multiply any two numbers, STM32F030F4 will do that in one clock cycle. On the other hand if you are going to do some simple logic with no complex calculations, 8-bit micro will be as good as 32-bit one. It all depends on the usage…

          3. Then there are ATmegas, which do have a hardware multiplier and are as efficient as Cortex-M0 regarding MIPS/MHz. Even when doing 32-bit math. Likely more efficient when doing 8-bit math, but I didn’t check this.

            Also, AVRs are better integrated into gcc with the -mmcu parameter, have the much faster (compared to MBED) avr-libc and can run at 5 volts and provice 20 mA on a GPIO pin, allowing e.g. to directly drive LEDs. There are still a couple of good reasons to use AVRs.

          4. There are 2 multiplier implementations for M0: single cycle vs 32 cycles. The STM32F0 datasheet doesn’t explicitly say about sngle cycle so chances are that it is 32 cycle. (Some other chips say it on page one under features.)

            Not to sure about Atmega handling 32-bit as efficient as M0. Just having to burn 8 registers for operands sounds painful. If you have to shuffle operands for a 32-bit math library call, that’s going cost a lot of cycles vs a M0. Then add in the extra cycles of saving registers for the caller, it is just not going to be pretty.

            If you have to go up the AVR family just to compete with M0, then there are a lot more competitive ARM chips at those price range.

          5. The ATmega _is_ as fast per clock as an M0. That’s no theory, but running code. 3D printer Teacup firmware needs 304 clocks per motor step on ATmega vs. 296 clocks on M0 with 1-cycle multiplier.

            Not sure how to explain this. I take the AVR has a lot more registers, 32 (8-bit) vs. just 8 (32-bit) on the M0. That’s an advantage for any non-32-bit section of the code (e.g. storing addresses). Data shuffling isn’t any faster on the M0. To load 32 bit = 4 bytes both chips need the same clock count. Also, neither needs a library call, both have a hardware multiplier. Count in that 32-cycle multiplier of some M0’s and you might end up faster on the ATmega.

            That said, a Cortex-M3 or Cortex-M4 is indeed a lot faster, it gets away with 184 clocks. Due to more registers, I guess. And all Cortex’ can run at higher clock rates, of course.

      2. With that type of thinking, we can’t have any new microcontrollers or new functionality. Thankfully that the market shows that 32-bit at close to 8-bit price range with more speed, more powerful peripherals are getting market shares.

    1. Well this AVR series is almost as old as PIC’s but they still have some avantages or people wouldn’t keep buying them.

      STM32 goes up to 32kB or 128kB SRAM from memory so you would be wasting development time by using it in a microwave control panel.

    2. If you are only interested in the peripherals & RAM offered by the bigger chips (STM32) then this chip is not for you. As Greenaum says, low power is probably the biggest driver, perhaps the only driver. CR2032 for ten years type stuff. I don’t think your STM32 is going to do that.

      Not too sure about back-compatibility though, would you not just keep buying/producing/cloning the chip you are trying to replace?

      Besides, TSSOPs are for babies – go die… as in die bonding…

  2. 2X3mm package w/ two PWM and USART? Serial control for a pair of servos?
    With 5 channel ADC? A serial 5 channel ADC for remote applications?

    I know, this isn’t likely the best device for either of these applications, but you asked what it is good for. If I was familiar with the architecture, and needed features like these, I might go for it due to ease of implementation, even if, objectively, the application might have a better fit. It isn’t about the best, it is about what gets the job done economically in an a timely manner.

      1. I just looked at my code just now and eliminated an extra byte so I’m down to 9 global bytes… also I’m using the Arduino libraries which use 4 bytes doing nothing but looping…

        Are you just using avr-size to get the sram usage?

        1. I’m using whatever AtmelStudio uses under the hood to report SRAM usage. I’m not sure what that is. If I look at the Output Files under Solution Explorer, I can right-click on one of the generated files, like the .elf or .hex, and invoke “Properties,” and it will show me the RAM size. Also I can look at the generated assembly language and see where it uses registers as opposed to SRAM locations.

  3. 32 bytes isn’t so bad. PIC 8-bit baseline chips have as low as 16 bytes of RAM.

    Without USB it seems a bit odd, though. I could see this being used in, say, an optical mouse or something… could even do PS/2 comms using the USART… but who would buy a PS/2 mouse these days?

      1. Well if your going to code in Assembly then it makes little difference. What application would have ALL the GPIO’s dedicated to the same function, you would expect there to be at least two external function and in that way it is easier to code for in Assembly – less read/AND bit mask/OR bit set/write activity.

    1. Uh, USB with 1k of flash and 32B of RAM? Ain’t happening.

      These are chips pretty much designed for applications where one would otherwise use a bit of discrete logic or something like 555 timer. The timer is cheaper, but less flexible and needs more components around it. So something like a PWM light dimmer or a pushbutton controlled on/off circuit would be a typical application of something like this.

      On the other hand, there are cheaper micros for such applications. Atmel sucks on prices again, as always.

    2. Something that small might be used as some simple control logic for small appliances. [Dave Jones] from EEVBlog once had shown insides of electric toothbrush that used 4-bit micro that had, IIRC, 16 words of RAM…

        1. It was surprisingly sophisticated. There was a lot of motor control and it would shut down if the current draw was too high (eg, you jammed it against your teeth). Also there was inductive charge control IIRC

          1. Not quite grokking what you are asking, but yes I also thought it weird that they started the registers from R16, there is no R0..15 on a reduced core TinyAVR. Atmel claims (Tiny 4/5/9/10 Datasheet Page 17) that this is “for reasons of compatability”.

          2. Instructions that load or manipulate a constant directly into a register only work on R31-R16. LDI for instance does not work on registers <R16. The register asymmetry is annoying a hell sometimes.

            Probably what they meant by compatible.

      1. I guess, part of the problem is availability for hobbyists. I live in Russia and it’s really hard to find any ATSAMs in retail. And if you do, the price is not reasonable. Chinese shops on eBay/Aliexpress also rarely sell these chips.

      2. I guess, part of the problem is availability for hobbyists. I live in Russia and it’s really hard to find any ATSAMs in retail. And if you do, the price is not reasonable. Chinese shops on eBay/Aliexpress also rarely sell these chips.

  4. It’s odd, once you have a design adding RAM should not be hard, so I guess it just had too little space in the square of silicon to add more than a few bytes.
    I wonder if someone decapped one so we can check.
    But even if so, could they not have added a micron extra on the side for some more RAM?

    1. I thought I read somewhere that the new owners of Atmel are moving to a higher nano-meter process for these chips so perhaps they want to fit it all on the same sized die.

  5. All these comments go for the obvious limits, but I’d like to know WHY do they make this? Why the limits? What is the purpose really? They only mention it’s good for low power, but i can’t imagine that’s the whole story.

  6. “none of the other low-end AVRs [have a HW UART]”: attinyx313 has HW uart; attinyx41 and attiny1634 have TWO hardware uarts (and 2k/4k/8k/16k of flash.) I guess with the recent price increases, they’re all in the $2 range instead of $1, though. (I got MY 1634s for less than $1. To play with (doesn’t mean much if you’re planning a product.)

  7. I had those parts for a couple of months now and started to work on a serial bootloader:

    https://cpldcpu.wordpress.com/2016/05/21/gluon-developing-a-bootloader-for-the-attiny104/

    It’s far from complete, though.

    I was a bit put back by the lukewarm reception of these devices, as also evident in the comments above. Unfortunately it is true – there are plenty of other options in the same form factor that are cheaper, more convenient, more powerful and potentially less energy consuming.

    I would like to have an ATtiny10 with self-programming abilities, though.

      1. This for the info, very nice. You started from scratch with assembler, which was probably more efficient than cutting a C-based bootloader down :)

        I found the application note.

        Does Atmel spaces seriously require me to sign up to download open source projects? That place seems to be tumble-weed territory. Probably Atmel should just use Github, like the other companies?

        1. Can you link to any articles on cpldcpu that are about cpu done in cpld? I am curious and the search doesn’t work for these tags because they’re apart of the page titles so it returns *everything*.

  8. I have been programming this device (the 104 version) and I’m surprised by what I can do with 32 bytes of SRAM, in C, using Atmel Studio (which uses gcc). When configured for this chip, the compiler generates no regular C runtime code at all. It will freely put locals in registers.

    I can read an encoder and use it to encode a 16-bit value, using only 3 bytes of SRAM, and in the same program bit-bang SPI to a serial EEPROM chip using only a few more bytes. With the GPIOs I can drive a couple of LEDs and give them some flashing and timeout behavior using another couple of bytes. So for the cost of maybe half that SRAM I can implement an encoder driving an ADC with LEDs that flash to indicate that the user has hit the top or bottom of the available voltage range.

    I’ve also got one of them doing simple control of an iTLA (laser source) over serial.

    It’s never going to run a web server or parse JSON, or even run an RTOS, but this is perfect for some limited development tasks. And because they are so cheap and simple, it has brought back some old-school hacking fun to my development work. Not everything needs an ARM core and a megabyte of EEPROM…

Leave a Reply to tekkieneetCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.