ATTiny85 - no external crystal?

I'm considering the ATTiny85 to do a simple small project. I looked around at the diagrams, and am a little confused. Doing a google search, I found a few diagrams of them show using the controller without an external crystal oscillator, and some of WITH a 16mhz or 12mhz crystal.

I dove into the datasheet, and if I am reading this right - I guess there is an internal low frequency oscillator that can be selected.

Did I read this correctly? I can use external crystal if I need something to be timing dependent or precise, and just use internal oscillator if I want to begin amateur use test purposes?

From what I understand, there is an 8 MHz RC oscillator which is preset from the factory for a 1 MHz clock. I've used the internal oscillator a couple of times with no issues. For HMI type applications, even 1 MHz with 10% fluctuation is not going to be noticeable.

The trouble I see with an external oscillator is that you lose two IO pins. Considering there are only five to begin with, that's a lot (unless your particular project only needs one or two, of course). I don't know how precise you want it but you can also calibrate the internal oscillator if you want a bit of a slightly improved "middle ground".

saximus:
From what I understand, there is an 8 MHz RC oscillator which is preset from the factory for a 1 MHz clock. I've used the internal oscillator a couple of times with no issues. For HMI type applications, even 1 MHz with 10% fluctuation is not going to be noticeable.

The trouble I see with an external oscillator is that you lose two IO pins. Considering there are only five to begin with, that's a lot (unless your particular project only needs one or two, of course). I don't know how precise you want it but you can also calibrate the internal oscillator if you want a bit of a slightly improved "middle ground".

I was trying to avoid as much extra circuitry as possible and obviously the 2 pins are too expensive to sacrifice. I need 2 lines for a serial or UART, spi I2C. That leaves 3 whole pins to do something with. It looks like I have to daisy chain SPI or I2C devices to get a practical use.

The ATtiny85, like just about every other 8-bit AVR microcontroller, has an internal 8mhz RC oscillator (and a lower frequency WDT oscillator). By default they come configured to use the internal 8mhz RC oscillator divided by 8 (CKDIV8). They also have a very unusual feature - an on-chip PLL that can generate a 64mhz clock for the high speed timer, and which can also provide a 16mhz clock for the processor.

So, they can be set to use the internal oscillator at 1 or 8mhz, the internal PLL (which is in turn clocked off the oscillator) at 16mhz, or an external crystal or clock source.

Be aware that the internal oscillator is only very approximately 8mhz - +/-10% is the spec. You can tune it, but you have to do that on a per-chip basis, and there's no non-volatile way to store your tuned OSCCAL value other than saving it to flash/eeprom, which greatly complicates matters.

UART serial requires timing to within +/-2% or so - so whether it works or not without tuning is a matter of luck, and will vary between chips.

Note also - there is no hardware UART on the 85 - any serial implementation is a software implementation, and hence it's both half-duplex (can't send and receive at the same time, both come out as gibberish if you try) and blocking (unlike real hardware serial which sends and receives in the background, software serial implementations require the processor's undivided attention while sending or receiving).

These issues don't apply to I2C or SPI (Though note that you need a different SPI/I2C library, since it has a USI rather than a full I2C or SPI peripheral)

1 Like

I am using ATtiny85 quite often, mostly without external crystal.

As mentioned in DrAzzy's very competent explanation you can tune the internal oscillator. By tuning you can get a reasonable accuracy of about 1% for a given voltage and temperature. So the frequency may be good enough for UART if (and only if) voltage and temperature stay constant.

I recommend this core for ATtiny85: https://github.com/SpenceKonde/ATTinyCore

If you just want to program the ATtiny85 to do simple processes, you don't need an external crystal. It can do many things without the crystal - apart from essential timing tasks. I wrote a blog post that flashes the ATtiny85 with the Arduino bootloader and flashes an LED. With the Arduino bootloader, you can do analog reading and writing and many other tasks an Arduino can! It's quite powerful for such a small IC.

Here's the link to the blog post:

ATtiny85 Arduino Board: How to Flash the Arduino Bootloader and Run A Simple Sketch

And here's the wiring diagram to upload the Arduino bootloader using an Uno board:

In fact Digispark shows it is even able to do quite timing demanding task - bit banging USB communication - if you have a reference to calibrate the internal oscillator from time to time.
@DrAzzy: The Datasheet says USI may be used as half duplex UART. But I have never tried it so I don't know how much burden it takes from the CPU.