Pages: [1]   Go Down
Author Topic: Memory problems with Serial.print  (Read 816 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi..

Iam using arduino UNO with WiFLY shild.

Using Arduino 0022 and it tells me I got 32K byte maximum Flash mem.

From what I understand Boot loader takes 2K Flash

Soo my Sketch should then have around 30K of free memory?!

My sketch use 16K Flash


SRAM show 85    (using ATS_GetFreeMemory(); )

And my program behaves strange and restarts and crash
But if I remove all Serial.println("balbalb");  (debug lines)

I endup with having 600 of free SRAM and no crashes or strange restarts and everything works fine.

Soo my questions why dose Serial.println take up SRAM? when it should only take Flash ram (sketch ram)


Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 638
Posts: 50300
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Serial.println() does not take up space in SRAM. The literal strings you are printing do. Where else do you expect them to be stored?
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 74
Posts: 7256
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe a little bit reading will help:

http://liudr.wordpress.com/2011/02/04/how-to-optimize-your-arduino-memory-usage/
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

>>Serial.println() does not take up space in SRAM. The literal strings you are printing do. Where else do you expect them to be stored?

I expected static text to be in flash. Would be awsome to be able to put static data in flash not needing to waste sram.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 638
Posts: 50300
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Would be awsome to be able to put static data in flash not needing to waste sram.
That's what PROGMEM is for.
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
expected static text to be in flash. Would be awsome to be able to put static data in flash not needing to waste sram.

In Arduino 1.0 this will be even simpler than "manual" PROGMEM stuff you can do now.  In 1.0, you'll just do Serial.println(f("I'm in flash now"));.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That sounds great.

PROGMEM for me is to store long term data, not junk text for simple debugging.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have 7.5Kbyte of static data I would like to dump into flash memory and then be able to search and extract data. (PROGMEM just 512? soo it's too small)

Is that possible ?
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

PROGMEM for me is to store long term data, not junk text for simple debugging.
I think you misunderstand PROGMEM.  Perhaps without realizing it, you have said "To me, text should be in RAM, not in Flash."

Which wouldn't make much sense would it?  You have 2K of RAM and 32K of Flash.  Why wouldn't you put all the "junk" in the space that is relatively large?


There are only three places to store any kind of data on an ATmega:  Flash (aka "PROGMEM"), RAM, and EEPROM.

EEPROM is for storing non-volatile data.  

RAM is for your program to work.

Flash / PROGMEM is Program Memory.  It is where instructions are stored for execution.  Wouldn't it make more sense to store constants associated with those instructions in the same place?  Simple debugging messages are instructions with char array constants.

Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
(PROGMEM just 512? soo it's too small)

On ATmega328:

Flash / PROGMEM:  32k
SRAM: 2k
EEPROM: 1k

The EEPROM isn't called Flash in this sense (even though that is what it is.)  The EEPROM is meant for non-volatile storage by the running program.  (e.g. storing calibration factors.)
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks PROGMEM will be my friend from now. smiley
Logged

Pages: [1]   Go Up
Jump to: