To much data error in serial communication??

Hello togehter,

I have a weird problem. I have a programm, sending some data within an endless loop with some other operations. Nothing extraordinay.

The problem is, if I send to much signs, the whole programm crashs.

Here’s the problematic excerpt of the original sourcecode, while everything works fine:

Serial.print(“Zeit_Cref: “);
Serial.print(show_ref2.16-18.66);
Serial.println(" pF");
Serial.print("Zeit_Cdet: ");
Serial.print(show_det
2.16-18.66);
Serial.println(” pF”);
Serial.print((diff-offset)*2.16);
Serial.println(" pF");
Serial.println(" ");

but when I add just one string like:

Serial.print(“Zeit_Cref: “);
Serial.print(show_ref2.16-18.66);
Serial.println(" pF");
Serial.print("Zeit_Cdet: ");
Serial.print(show_det
2.16-18.66);
Serial.println(” pF”);
Serial.print((diff-offset)*2.16);
Serial.println(" pF");
Serial.println(“Additional_text”);
Serial.println(" ");

… the program crashs
It’s really just because of this additional line, I changed nothing else

Is there a limit for signs to send? Som problems with the buffer or what?

Thanks a lot for your help!!

Greetings

Ralle595

– sry for bad english… I’m german

Usual advice: post all your code, post code in code tags, and use the F macro to put strings in program memory

As AWOL points out, when adding more code causes random crashes, running out of memory is almost always the problem.

Serial.print("Zeit_Cdet: ");
should be
Serial.print(F("Zeit_Cdet: "));

This keeps the string "Zeit_Cdet: " out of SRAM (which is what you don’t have a lot of).

Thank you for your help. I'm sry for the formal mistakes, I have just registerd here some hours ago...

I tried using the F() macro, but It didn't change anything... :(

Serial.print(F("Zeit_Cref: "));    
 Serial.print(show_ref*2.16-18.66);
 Serial.println(F(" pF"));
 Serial.print(F("Zeit_Cdet: "));
 Serial.print(show_det*2.16-18.66);
 Serial.println(F(" pF"));
 Serial.print((diff-offset)*2.16);
 Serial.println(F(" pF"));
 Serial.println(F(" "));

I read the F() macro is already integrated since arduino 1.0 IDE . I use the 1.5 version.

Found this on the Arduino.cc page:

[b]Using Flash Memory for string storage[/b]

Version 1.0 of the Arduino IDE introduced the F() syntax for storing strings in flash memory rather than RAM. e.g.

Serial.println(F("This string will be stored in flash memory"));

so could there be another reason? I use an Arduino Nano with an ATmega 328.

Ralle595: so could there be another reason?

Maybe, but by not posting all of your code, who knows?

Ralle595: I tried using the F() macro

The code you posted doesn't use it at all, so we have no way of knowing whether the changes you made were what was intended.

Have you ever measured the amount of free memory when the sketch is running? There is a code fragment in the playground which will do that for you.

Your code layout is horrible and makes it hard to read. Please use the Arduino Tools / Auto Format command to correct the indentation - preferably, before you do that put each { and } on separate lines.

Yes, your're right, in this code I did not use the F() macro. It was the original version. But it's not that difficult to implement the F() macro as i posted before.

How can I measure the amount of memory while the sketch is running?

Btw: I fixed the problem :) It's because the global interrups were disabled... Did not expect, that internal interrupts are necessary that often. Now everything is running fine :)

Sry for my code layout, but i think horrible is a little bit exaggerated^^ the large amount of comments are there because it's for my prof.

Nevertheless, many thanks for your support!