Problem in interfacing between Attiny85 and DS3231 RTC

I am making a “time trigger relay” project with Attiny85 and DS3231. The project works very well on UNO but after shifting the project to ATTINY85, it is displaying errors. I tried uploading Attiny85 - DS3231 example sketches on Attiny85 and the same result “error”.

Simple programs like Blink, Fade are working very well on Attiny85.

#include <DS3231.h>

int Relay = 1;
#define SDA 0
#define SCL 2
DS3231  rtc(SDA, SCL);
Time t;

const int OnHour = 06;
const int OnMin = 00;
const int OffHour = 07;
const int OffMin = 30;

const int OnHour2 = 18;
const int OnMin2 = 00;
const int OffHour2 = 19;
const int OffMin2 = 00;

void setup() {
//  Serial.begin(115200);     uncomment in case of UNO
  pinMode(Relay, OUTPUT);
  digitalWrite(Relay, LOW);

void loop() {
  t = rtc.getTime();
//  Serial.print(t.hour);
//  Serial.print(" hour(s), ");
//  Serial.print(t.min);
//  Serial.print(" minute(s)");
//  Serial.println(" ");
//  delay (1000);
  if(t.hour == OnHour && t.min == OnMin){
//    Serial.println("LIGHT ON");
    else if(t.hour == OffHour && t.min == OffMin){
//      Serial.println("LIGHT OFF");

  if(t.hour == OnHour2 && t.min == OnMin2){
//    Serial.println("LIGHT ON");
    else if(t.hour == OffHour2 && t.min == OffMin2){
//      Serial.println("LIGHT OFF");


Warning: Board breadboard:avr:atmega328bb doesn’t define a ‘build.board’ preference. Auto-set to: AVR_ATMEGA328BB
In file included from C:\Users\Sunmeet\Desktop\Practice2\libraries\DS3231\DS3231.cpp:26:0:

C:\Users\Sunmeet\Desktop\Practice2\libraries\DS3231\hardware/avr/HW_AVR.h: In member function ‘void DS3231::begin()’:

C:\Users\Sunmeet\Desktop\Practice2\libraries\DS3231\hardware/avr/HW_AVR.h:3:19: error: ’

In file included from c:\program files\arduino-1.8.5\hardware\tools\avr\avr\include\avr\io.h:99:0,

from c:\program files\arduino-1.8.5\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

from C:\Program Files\arduino-1.8.5\hardware\arduino\avr\cores\arduino/Arduino.h:28,

from C:\Users\Sunmeet\Desktop\Practice2\libraries\DS3231\DS3231.h:26,

from C:\Users\Sunmeet\Desktop\Practice2\libraries\DS3231\DS3231.cpp:22:

C:\Users\Sunmeet\Desktop\Practice2\libraries\DS3231\hardware/avr/HW_AVR.h:31:14: error: ‘TWEN’ was not declared in this scope



C:\Users\Sunmeet\Desktop\Practice2\libraries\DS3231\hardware/avr/HW_AVR.h:31:26: error: ‘TWEA’ was not declared in this scope



C:\Users\Sunmeet\Desktop\Practice2\libraries\DS3231\hardware/avr/HW_AVR.h:31:38: error: ‘TWINT’ was not declared in this scope



C:\Users\Sunmeet\Desktop\Practice2\libraries\DS3231\hardware/avr/HW_AVR.h:31:51: error: ‘TWSTA’ was not declared in this scope



exit status 1
Error compiling for board ATtiny25/45/85.

So that’s a compile error.

Probably the registers called in your code do not exist on the ATtiny85. So you have to either rewrite the existing code (which appears to be in a DS3231 library) to not use those registers, find a different library for the DS3231, or write your own.

It is probably because there is no TWCR defined for ATtiny. I've never worked with ATtiny, however after brief look into the datasheet, ATtiny uses USICR register etc. for TWI communication. It differs from ATmega.
Look for TWI library for ATtiny like this one:

ATtiny85 can do I2C just fine, with the appropriate I2C library (as built in into ATtinyCore). Indeed it doesn't have hardware I2C built in.

The problem of the OP appears to be within the DS3231 library though, looking at the paths in the compiler it seems that some AVR core files (hardware specific) are copied into the library and that's what's causing the problems.

Thanks Guys!! you are right this library is not for Attiny85.
I need to find another one.