Sending command over serial >64 bytes - fails at 70 bytes

In a simple test between serial devices (as illustrated here) you can write more that 70 bytes.

#include <SoftwareSerial.h>

int SSTXPin = 5;
int SSRXPin = 6;

SoftwareSerial aSerial1(SSRXPin, SSTXPin); //xxxxxx

char TxBuff = “012345678911234567892123456789312345678941234567895123456789612345678971234567898012345678911234567892123456789312345678941234567895123456789612345678971234567898”;
int i;

void setup()
{
// put your setup code here, to run once:
Serial.begin(19200);
aSerial1.begin(19200);
Serial.println(TxBuff);

for (i = 0; i < strlen(TxBuff); i++)
Serial.write(TxBuff*);*

  • Serial.println("");*
  • Serial.print("Message length = ");*
  • Serial.println(strlen(TxBuff));*
  • Serial.print("write crashed out the for loop at ");*
  • Serial.println(i, DEC);*
    for (i = 0; i < strlen(TxBuff); i++)
    _ aSerial1.write(TxBuff*);_
    _
    }_
    void loop()
    _
    {_
    _
    // put your main code here, to run repeatedly:_
    _
    }*_
    All good.
    However in a real program (a bit more complex) the TX fails at 70 bytes. Both serial, to the serial monitor, and to a second device via SoftwareSerial - Why? The fail even breaks the for loop sending the data. Even if you split the send at the 64th or less bit the loop sending the balance of the message fails at the 70th byte.

Please read this

However in a real program

Which we can't see.

If you use the 2nd or 3rd example in Serial Input Basics you can receive as much data as you have memory for. In the examples the array size is set to 32 bytes - but you can easily change that.

...R

Thank you, but as I said it is the write that fails and crashes out the send loop.

Still can't see any code.

SimonPEdwards:
Thank you, but as I said it is the write that fails and crashes out the send loop.

Maybe this

  for (i = 0; i < strlen(TxBuff); i++)
    Serial.write(TxBuff);

should be

  for (i = 0; i < strlen(TxBuff); i++)
    Serial.write(TxBuff[i]);

…R

Robin2:
Maybe this

  for (i = 0; i < strlen(TxBuff); i++)

Serial.write(TxBuff);



should be


for (i = 0; i < strlen(TxBuff); i++)
    Serial.write(TxBuff[i]);




...R

It is, hence the italics

Yes. As is it'll send the entire string in this case 77 times.
I'm guessing what I posted was in the clipboard from a previous cut and paste.
I'll post a better example soon.