Jump to content
43oh

Memory problem with msp430g2553


Recommended Posts

Hi! I tried to connect GPRS Shield from Arduino to msp430g2553 with SoftwareSerial library. But I faced with the problem. When the size of sketch exceeds 5590 bytes, global variables do not work. I just add one variable (global string) and the program stops executed correctly.

Here is the code:

/*
  When new serial data arrives, this sketch adds it to a String.
  When a '!' character is received, the loop prints the string "Hello world!"
*/

#include <SoftwareSerial.h>
SoftwareSerial mySerial(P2_0, P1_5);

String inputString = "";           // a string to hold incoming data
boolean stringComplete = false;    // whether the string is complete

String string1 = "Hello ";
String string2 = "Just string";
String string3 = "Another string";
//String string4 = "Another string";  // If we uncomment this line, code will not work  

void setup()
{
  Serial.begin(9600);
  mySerial.begin(19200);
}

void loop()
{
  if (stringComplete)  //if the incoming character is a '!'
  {  
  inputString = "";
  stringComplete = false;
  Serial.print(string1);
  Serial.println("world!");
  }
}

/*
  SerialEvent occurs whenever a new data comes in the
  hardware serial RX. This routine is run between each
  time loop() runs, so using delay inside loop can delay
  response. Multiple bytes of data may be available.
*/
void serialEvent() 
{
  while (Serial.available()) 
  {
    char inChar = (char)Serial.read(); 
    inputString += inChar;
    if (inChar == '!') { stringComplete = true; } 
  }
}

Somebody knows where is my problem?

SoftwareSerialEnergia.ino

Link to post
Share on other sites

Strings are variables, which are stored in RAM. Since your chip has only a hand full of RAM (512 bytes? or half or that, not sure) you should use it with care.

If you'd consider changing your Strings to const Strings, then the data will be kept only in flash (where it already is, the RAM needs to be set up with something).

Note that you should only do this for strings that will never change, so not for inputString:

String inputString = "";           // a string to hold incoming data
boolean stringComplete = false;    // whether the string is complete

const String string1 = "Hello ";
const String string2 = "Just string";
const String string3 = "Another string";
const String string4 = "Another string";
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...