Arduinio Mega buffer filling up

Issue: Two shields utilize the buffer, and its filling up.

I have a function to start an engine via CANbus

void sendstart() {
 
    unsigned char stmp[8] = {01, 0, 0, 0, 0, 0, 0, 0};
    CAN.sendMsgBuf(0x18ff8000, 1, 8, stmp);
    lcd.setCursor(1, 0);
    lcd.print("Starting Engine");
    Serial.println("Starting Engine");
 
}

If i call the function at the begining of the loop, it starts the engine, and prints everything.

However if i place it at the bottom of my loop() OR inside of a if else statement like the final code will need to be structured it doesn't execute the CAN.send portion, but i see my message in the serial monitor.

My 4G module has a function to read an sms, and store the contents in the buffer.

// Read incoming SMS
    status = _4G.readSMS(index);

    if (status == 0)
    {
      Serial.println(F("--- READ SMS ---"));
      Serial.print(F("SMS body: "));
      Serial.println((char *)_4G._buffer);
      Serial.print(F("Phone number: "));
      Serial.println(_4G._smsNumber);
      Serial.println(F("-------------------------------"));

I am unsure if the 4G code is playing a role, but either way it seems like my CAN.send message doesnt work unless placed near the beginning of my loop.

Is the buffer getting full? Is there a way to clear it?

Thanks

Is the buffer getting full?

What buffer?

You must have missed the part about posting ALL of your code.

PaulS:
What buffer?

You must have missed the part about posting ALL of your code.

I cant post the code as it falls out of the 9000 character limit

Here is the IF statement section where the CAN portion doesnt execute, as mentioned the serial print and other functions take place.

////////////sms actions////////////////////////




      if (strcmp(_4G._buffer, "Start") == 0)
      {
        sendstart();
        int phone_number = _4G._smsNumber;
        error = _4G.sendSMS(phone_number, "Engine Starting");

      }
      else if (strcmp(_4G._buffer, "Valve 1 close") == 0)
      {

        digitalWrite(relay1, HIGH);
        int phone_number = _4G._smsNumber;
        error = _4G.sendSMS(phone_number, "VALVE 1 CLOSING");

      }
      else if (strcmp(_4G._buffer, "Valve 2 open") == 0)
      {
        Serial.println("Opening");
        digitalWrite(relay2, LOW);
        int phone_number = _4G._smsNumber;
        error = _4G.sendSMS(phone_number, "VALVE 2 OPENING");

      }
      else if (strcmp(_4G._buffer, "Valve 2 close") == 0)
      {

        digitalWrite(relay2, HIGH);
        int phone_number = _4G._smsNumber;
        error = _4G.sendSMS(phone_number, "VALVE 2 CLOSING");

      }

      else if (strcmp(_4G._buffer, "Valve 3 open") == 0)
      {

        digitalWrite(relay3, LOW);
        int phone_number = _4G._smsNumber;
        error = _4G.sendSMS(phone_number, "VALVE 3 OPENING");


      }
      else if (strcmp(_4G._buffer, "Valve 3 close") == 0)
      {

        digitalWrite(relay3, HIGH);
        int phone_number = _4G._smsNumber;
        error = _4G.sendSMS(phone_number, "VALVE 3 CLOSING");


      }
      else if (strcmp(_4G._buffer, "Valve 4 open") == 0)
      {

        digitalWrite(relay4, LOW);
        int phone_number = _4G._smsNumber;
        error = _4G.sendSMS(phone_number, "VALVE 4 OPENING");

      }
      else if (strcmp(_4G._buffer, "Valve 4 close") == 0)

      {

        digitalWrite(relay4, HIGH);
        int phone_number = _4G._smsNumber;
        error = _4G.sendSMS(phone_number, "VALVE 4 CLOSING");

      }

      else if (strcmp(_4G._buffer, "") == 0)

      {


        int phone_number = _4G._smsNumber;
        error = _4G.sendSMS(phone_number, valve1state);

      }
      else
      {
     
   int phone_number = _4G._smsNumber;
         error = _4G.sendSMS(phone_number, "UNKNOWN COMMAND");
      }

I cant post the code as it falls out of the 9000 character limit

What that means is that you have not read the stickies at the top of the forum. They explain how to (easily) get around that limit.

Please see attached code.

Section ///////////sms actions////////
show where the function is called. The serial.println lines execute but not the CAN portion.
Thanks again.

Canbus.txt (2.16 KB)

Please see attached code.

More snippets. Post ALL of your code!

My apologies, i didnt re-Copy after pasting.

Canbus.txt (11.1 KB)