InterruptTIMER1 + SoftwareSerial.h not compatible?


I’m trying to send one sms a SMS 60 in 60 seconds with the value of temperature.
But doesn’t work.

I Use interrupt’s and the timer1 to increment de int “s”, who represent the seconds.

The code is:

//by Raul Vidal
//April 2015

#include <SoftwareSerial.h>
SoftwareSerial sim808(10, 11); // RX, TX

//storage variables
int s = 0;
int m = 0;
int h = 0;
int temp = 16;

void setup(){
  sim808.begin(9600); //GSM Module
  Serial.begin(9600); //Serial Monitor  
  cli();//stop interrupts
    //set timer1 interrupt at 1Hz
    TCCR1A = 0;// set entire TCCR1A register to 0
    TCCR1B = 0;// same for TCCR1B
    TCNT1  = 0;//initialize counter value to 0
    // set compare match register for 1hz increments
    OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
    // turn on CTC mode
    TCCR1B |= (1 << WGM12);
    // Set CS12 and CS10 bits for 1024 prescaler
    TCCR1B |= (1 << CS12) | (1 << CS10);  
    // enable timer compare interrupt
    TIMSK1 |= (1 << OCIE1A);
  sei();//allow interrupts
}//end setup

ISR(TIMER1_COMPA_vect){//timer1 interrupt 1Hz toggles pin 13 (LED)
//generates pulse wave of frequency 1Hz/2 = 0.5kHz (takes two cycles for full wave- toggle high then toggle low)
  Serial.print(" Seconds");
  if (s==60){
    Serial.print("Temperature is:");
    print808(); //function to send the sms
  }//close interrupt
void print808(){
  Serial.println("Sending SMS with temperature");
  sim808.print("AT+CMGF=1\r"); // Set the shield to SMS mode
  sim808.print("The temperature is: ");
  sim808.print(" C");
  sim808.print("\r"); //the content of the message
  sim808.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
  Serial.println("SME Sent.");
  }//close print808()

void loop(){
  }//close loop

In software monitor i can see all correct, but the module GSM (SIM808) don’t send SMS…

If i put the the function print808(), on void loop(), the function work, and send an sms, but it’s not activate by the interrupt (timer 1)…

Can any one help me?

You don't have to use a hardware timer for that. Timer 0 is already running. You only need to use it with micros() or millis().

You need to pay attention to what you can, and can NOT do, in an ISR. Sending Serial data is not possible. Sending SMSs is not possible. Using delay() is not possible.

Is there some part of "An interrupt handler MUST be fast" that you think doesn't apply to use?

Quit using a timer to make something happen on a regular schedule. Look at the blink without delay() example, and use that technique instead of a timer interrupt.

Thank you for your help (both).

I look for the "blink without delay() example", and for now solve my problem.

But make a little error to send a SMS every minute, but for now solve the problem. I will continue to search/look for other solucions.

Thank You :D