shailav619 0 Posted April 19, 2017 Share Posted April 19, 2017 Hello, I am using msp430g2553 mcu and I interfaced that mcu with gsm sim900 successfully. Now I am facing some strange behavior in the code. When I write the loop as follows: void loop() { String buffer = readSIM900A(); String msgOn = buffer; String number1 = "8320389582"; //problem String number2 = "9106555707"; //problem String number3 = "9979933498"; //problem if (buffer.startsWith("\r\n+CMT: ")) { Serial.println(buffer); buffer.remove(0,12); buffer.remove(10); Serial.println(buffer); msgOn.remove(0,51); msgOn.remove(3); Serial.println(msgOn); if(((buffer==number1)||(buffer==number2)||(buffer==number3))&&((msgOn=="On")||(msgOn=="ON")||(msgOn=="on"))) { digitalWrite(led, HIGH); } } delay(100); } In the lines above commented with "problem": -> When I write String number1 = "8320389582"; //problem like this and when I use this for toggling led like this if(((buffer==number1)||(buffer==number2)||(buffer==number3))&&((msgOn=="On")||(msgOn=="ON")||(msgOn=="on"))) { digitalWrite(led, HIGH); } This doesnt work but instead when I use the code like if(((buffer=="+91963xxxx")||(buffer=="+91963XXXX")||(buffer=="+918753XXX"))&&((msgOn=="On")||(msgOn=="ON")||(msgOn=="on"))) { digitalWrite(led, HIGH); } This works and I can toggle the led. According to my understanding there is some compiler issue in this related to memory for local loop. Can anyone help me with this? I am attaching my code for reference. Thanks, Shailav prefinal.rar Quote Link to post Share on other sites
Rei Vilo 695 Posted April 19, 2017 Share Posted April 19, 2017 Posted thrice. Please read Netiquette for Newbies. Quote Link to post Share on other sites
bluehash 1,581 Posted April 20, 2017 Share Posted April 20, 2017 Thanks @Rei Vilo deleted the other posts. Quote Link to post Share on other sites
energia 485 Posted April 28, 2017 Share Posted April 28, 2017 Be very carful with the String library on small RAM devices like to G2553. The G2553 only has 1/2 a KB of RAM and you are most likely running out of RAM. I would avoid using the String library all together on the G2553. However you can try the following: Make number1 ,2 and 3 a global by declaring them outside the setup and loop and make them of type char. avoid the msgOn = buffer statement in the loop. If you know what the maximum string size is readSIM900A can ever return then declare buffer with String buffer[MAX_SIZE] as a global and then in the loop do buffer = readSIM900A(). This might just free up enough memory to make this work but you will most likely run into trouble again if you continue using the String library. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.