Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino in uncontrolled infinity loop

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
Joined
Apr 24, 2010
Messages
899
Helped
24
Reputation
48
Reaction score
26
Trophy points
1,318
Location
Dhaka, Bangladesh, Bangladesh
Activity points
8,253
I've found this problem before, but just did not work with that code. But having the issue again with the same library file.

Adafruit_FONA.h library is pretty popular in Phone, GSM, etc. projects with Arduino. Used in different projects. But one problem is totally uncontrolled.

Once the caller ID detection function is used, the Arduino goes into some kind of uncontrolled loop after a few moments especially if other functions are used with the caller ID detection function.

The function works fine if it is used alone. I mean, no other task needs to do. Please check the video to find the Arduino behavior.



Once the Arduino falls into this situation, No reset works, no loop works. only power restarts bring it back to work.

Why does this happen and how can be solved?
--- Updated ---

Note that, this is a simple test project.

Code:
#include "Adafruit_FONA.h"
#define FONA_RST           5
#define FONA_RI_INTERRUPT  0

#include <EEPROM.h>

#include <SoftwareSerial.h>
#define FONA_RX 4
#define FONA_TX 3
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);


const int button1 = 12, button2 = 11, swtch = 9;

void setup() 
{
   
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(swtch, INPUT_PULLUP);
  
  Serial.begin(115200);
  Serial.println(F("Init..."));
  fonaSerial->begin(4800);
  if (! fona.begin(*fonaSerial))
  {
    Serial.println(F("GSM NOT FOUND"));
    while (1);
  }
  Serial.println(F("FONA is OK"));

  // Enable incoming call notification.
  if (fona.callerIdNotification(true, FONA_RI_INTERRUPT))
  {
    Serial.println(F("C_id n. en"));
    EEPROM.write(7,1);
  }

}

void loop() 
{
  char phone[32] = {0};
  // Check for an incoming call.  Will return true if a call is incoming.
  if (fona.incomingCallNumber(phone))
  {
    Serial.println(F("RING!"));
    Serial.print(F("Phone Number: "));
    Serial.println(phone);
     
    if (digitalRead(button1) == LOW)
    {
      for (int k = 0; k < 12; k++)
      {
        EEPROM.update(101 + k, phone[k + 3]); delay(60);
        Serial.print(phone[k + 3]); 
      }
      char phn[12] = {0};
      Serial.println(F("Saved Phn number: "));
      for (int i = 0; i < 12; i++)
      {
        phn[i] = EEPROM.read(101 + i);
      }
      Serial.println(phn);

      //reject the call
      if (! fona.hangUp()) {
        Serial.println(F("Failed")); 
      } else {
        Serial.println(F("OK!"));
      }

      delay(1000); 
      String text = "1st number: " + String(phn);
      int length_text = text.length() + 1;
      char sms_text[length_text];
      text.toCharArray(sms_text, length_text);

      if (!fona.sendSMS(phn, sms_text))
      {
        Serial.println(F("Failed")); 
      } else {
        Serial.println(F("Sent!")); 
      }
      EEPROM.update(1,1);       
    }

    if (digitalRead(button2) == LOW)
    {
      for (int k = 0; k < 12; k++)
      {
        EEPROM.update(201 + k, phone[k + 3]); delay(60);
        Serial.print(phone[k + 3]); 
      }
      char phn[12] = {0};
      Serial.println(F("Saved Phn number: "));
      for (int i = 0; i < 12; i++)
      {
        phn[i] = EEPROM.read(201 + i);
      }
      Serial.println(phn);

      //reject the call
      if (! fona.hangUp()) {
        Serial.println(F("Failed")); 
      } else {
        Serial.println(F("OK!"));
      }

      delay(1000);
      String text = "2nd number: " + String(phn);
      int length_text = text.length() + 1;
      char sms_text[length_text];
      text.toCharArray(sms_text, length_text);

      if (!fona.sendSMS(phn, sms_text))
      {
        Serial.println(F("Failed")); 
      } else {
        Serial.println(F("Sent!")); 
      }
      EEPROM.update(2,1);
    }
  }//fona end

}



//
--- Updated ---

ino File
 

Attachments

  • sketch_nov12a.rar
    972 bytes · Views: 86
Last edited:

Hi,

you should check the terminal output.

Maybe add some more Serial.print() to locate the problem.

Klaus
 

Hi,

you should check the terminal output.

Maybe add some more Serial.print() to locate the problem.

Klaus
There is a response in the serial terminal [inside the FONA library] when the Interrupt 0 is called. Sometimes it gives lots of response then starts falling into this uncontrolled loop or sometimes it falls just after 2/3 interrupts. If this interrupt is not used, then it works normally.
 

Executing time consuming code, e.g. unbuffered serial output in interrupt routines isn't recommended because it can easily cause deadlock situations. I won't expect it in quality libraries.
 

Executing time consuming code, e.g. unbuffered serial output in interrupt routines isn't recommended because it can easily cause deadlock situations. I won't expect it in quality libraries.
It generates some warning "ISO C++ forbids converting a string constant to 'char*'" . The library is pretty large. I'm trying to write my own library for that. But How can we stop this deadlock situation? What is the remedy if it fall into once anyhow? Because no reset works that time. Only power restart works.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top