timer1 interrupt + reading DHT11 sensor

Hello,
as a newbie into arduino programming I already stumbled into a problem.

I'm trying to use timer1 interrupts (set to 3s atm) and each interrupt read data from the temperature/humidity DHT11 sensor [u]Arduino Playground - HomePage.
I used that exact library and it works normally, if the reading occurs in the main loop (outside the interrupt function), but as soon as I move the code in interrupt part, it hangs and stops sending any data via serial (not even the Serial.print("interrupt "); down in the code).

I wonder if I'm missing anything here?

#include <avr/io.h>
#include <avr/interrupt.h>

// DHT11 library
#include <dht11.h>

dht11 DHT11;

#define DHT11PIN 3

volatile int humidity;
volatile int temperature;



ISR(TIMER1_COMPA_vect)
{
    Serial.print("interrupt ");
    unsigned long a = millis();
    Serial.print(a/1000);
    Serial.print(".");
    Serial.println(a%1000);
    //delay(500);
    
    int chk = DHT11.read(DHT11PIN);

    Serial.print("Read sensor: ");
    switch (chk)
    {
      case DHTLIB_OK: 
  		Serial.println("OK"); 
  		break;
      case DHTLIB_ERROR_CHECKSUM: 
  		Serial.println("Checksum error"); 
  		break;
      case DHTLIB_ERROR_TIMEOUT: 
  		Serial.println("Time out error"); 
  		break;
      default: 
  		Serial.println("Unknown error"); 
  		break;
    }
  
    Serial.print("Humidity (%): ");
    Serial.println((float)DHT11.humidity, 2);
  
    Serial.print("Temperature (oC): ");
    Serial.println((float)DHT11.temperature, 2);
}


void setup()
{
    Serial.begin(115200);
    
    // ##################### TIMER #####################
    // initialize Timer1
    cli();          // disable global interrupts
    TCCR1A = 0;     // set entire TCCR1A register to 0
    TCCR1B = 0;     // same for TCCR1B
 
    // set compare match register to desired timer count:
    //OCR1A = 43874;
    OCR1A = 46875;
    // turn on CTC mode:
    TCCR1B |= (1 << WGM12);
    // Set CS10 and CS12 bits for 1024 prescaler:
    TCCR1B |= (1 << CS10);
    TCCR1B |= (1 << CS12);
    // enable timer compare interrupt:
    TIMSK1 |= (1 << OCIE1A);
    sei();          // enable global interrupts
    
    
}

void loop()
{

}

Sensor is normally linked to pin3 with a 5k pull-up resistor.

Tnx for the help

~Matt

You can't use functions that rely on interrupts in an ISR, because interrupts are disabled during an ISR.

Serial.print() among other things needs interrupts to function. You are doing far too much in the ISR.

For reading temperature every 3 seconds, you hardly need interrupts.

This means all interrupts are disabled? ... as far as I know Serial.print() works within it, tested that (if I comment the whole sensor-reading part).

This means all interrupts are disabled?

During your ISR, yes.

All you should be doing is setting a flag. Check that flag in loop(). When set, take a reading and clear the flag.

I'll do that, tnx