4.2.3 Atmel tinyAVR with USI Interface

Most of the tinyAVR microcontrollers do not have SPI module. Instead they have a universal serial interface which can be implemented as either SPI or TWI. This library contains drivers for the SPI implementation of the tinyAVR USI. Drive the SPI interface of the MSL with the AVR USI ports to control the LED driver using this library. Since USI is a three pin interface, use an additional I/O pin as SS by the software.

The following code section contains the definitions related to this target.

#elif defined(TINYAVR) && defined(SPI_USI)    
        #include "tiny_avr_spi_via_usi_driver.h"        

        /* USI port and pin definitions for ATTINY25*/    
        #define USI_OUT_REG   PORTB //!< USI port output register.    
        #define USI_IN_REG    PINB  //!< USI port input register.    
        #define USI_DIR_REG   DDRB  //!< USI port direction register.    
        #define USI_CLOCK_PIN PB2  //!< USI clock I/O pin.    
        #define USI_DATAIN_PIN     PB0    //!< USI data input pin.    
        #define USI_DATAOUT_PIN    PB1    //!< USI data output pin.    
        #define CSB_PIN            PB4    //!< Atmel LED driver CSB      
        #define TC0_PRESCALER_VALUE 1 //!< Must be 1, 8, 64, 256, 1024     
        #define TC0_COMPARE_VALUE  31 //!< Must be 0 to 255. Minimum 31
                                      //with prescaler CLK/1.
  • USI_OUT_REG defines the USI port used
  • USI_IN_REG defines the USI port input register
  • USI_DIR_REG defines the USI port direction register
  • USI_CLOCK_PIN defines the USCK pin (SCK)
  • USI_DATAIN_PIN defines the USI data in (MISO) pin
  • USI_DATA_OUT defines the USI data out (MOSI) pin
  • CSB_PIN is the software controlled I/O pin (SS). Since USI is a three pin interface, use this pin, which is software controlled, to drive the MSLxxxxCSB input.
  • TCO_PRESCALAR_VALUE and TCO_COMPARE_VALUE set the SCK bits-per-second of the interface according to the equation below

Use prescaler value of {1, 8, 64, 256, or 1024} and compare value 0 to 255. Use at least 31 when using prescaler value of 1. Hence maximum SCK bits-per-second is F_CPU/64.

b p s = F _ C P U P R E S C A L E R * ( C O M P A R E _ V A L U E + 1 ) * 2