ATtiny841 registers help!

Hello everybody,

I bought one Attiny841 and i want to use it as an SPI master, but i am having some difficulties. It seems like there is no library ready to use hardware SPI on the 841, is that right? The one most people recommend for ATtiny's is the TinySPI lib, but it seems to have no support for the 841.

If that's true, then i need to program hardware SPI by myself, but i'm getting a little confused while reading the datasheet about the registers i'll need to setup.

Can somebody please explain to me what are the registers i need to configure to activate hardware SPI on the alternate ports of the IC? How do i set baudrate? is there a document where things are better explained than at the datasheet?

Thanks in advance

Assuming you’re using my ATTinyCore (board manager link in sig)…

Just include <SPI.h> and use it normally. It should just work - if it doesn’t, that’s a bug in the ATTinyCore.

The ATTinyCore board package i maintain includes a version of SPI.h that fully supports SPI on all of the ATTiny chips it supports, choosing the right implementation (hardware SPI for the 841, USI for most of the others) depending on the chip in use. Same with Wire.h

Make sure you are using 1.2.3 - there was a bug in 1.2.2 that may have impacted this functionality.

I am indeed using ATTinyCore, so i just need to program the atttiny like a normal arduino?

For the most part, yes.

Is there any chance that tinySPI will be ported over for the 841? I’m not super familiar with how the whole SPI thing works but it seems that there must be some differences that prevent some programs that were written for tinySPI from working properly with the regular SPI library.

Absolutely not, why on earth would you want that?

TinySPI is only for devices that have a USI (a less capable combined i2c/spi interface). The 841 has full SPI capability, the same exact functionality as on the ATmega parts.

In fact, recent versions of ATTinyCore have a special version of SPI.h which will use standard SPI library for parts that support it, and the tinySPI library (with tweaks so it "looks" like SPI, allowing it to work with libraries that include SPI.h (so you dont have to modify the libraries to use tinySPI)) on parts with just a USI. Wire.h works the same way too on ATTinyCore.

So those tinySPI and tinyWire libraries are obsolete and deprecated on ATTinyCore, as are the libraries hacked up to use them instead of the normal libraries in order to support old cores for the attiny parts that dont have my universal spi and wire libraries.

Thanks for the reply DrAzzy. Like I said, I don't know much about SPI. Guess it's time to do a bit of learning.