Pages: [1] 2   Go Down
Author Topic: Serial Library requiring a lot of memory?  (Read 1354 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been using avr-size.exe to track my memory foot print for my project to ensure I am within the save limits depending on what chip I am on. I started adding the Serial communication functions today and noticed a spike in SRAM usage by 680bytes by just initializing Serial.

With Serial.being(9600) in the setup loop:
text    data     bss     dec     
  30538    1652    1001   33191   

Without Serial.being(9600) in the setup loop:
text    data     bss     dec
  27998    1636     321   29955

I tested this with several baud rates and it stays at 680 bytes. And btw I am using an Arduino Mega 2560 R2 if it matters.

Does anyone know if 680 byte consumption is normal? Is there another library alternative that has less overhead requirement (have another project where I need Serial communication but I cannot spare 680 bytes of RAM)?

FYI I did this test without ANY serial commands being used other than Serial.begin.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well if it's compiling for a mega board then it defines serial send and rec software buffers (in SRAM) for all four possible hardware serial ports even if you aren't using them. Others have complained of this behaviour but don't know if more intelligent method is forthcoming.

Lefty
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27425
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A good chunk of that is the Tx and Rx buffers for the serial data.

If you need more SRAM, consider the '1284P - 16 Kbyte of SRAM, twice what the '2560 has. Dual serial ports, 32 IO lines.
I have a nice Duemilanove style board for the 366/644/1284 series of chips.

http://www.crossroadsfencing.com/BobuinoRev17/
Can use onboard FTDI module, mikroe483 from mouser.com, or offboard with FTDI Cable, FTDI Basic, or similar CP2102 module.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
A good chunk of that is the Tx and Rx buffers for the serial data.

If you need more SRAM, consider the '1284P - 16 Kbyte of SRAM, twice what the '2560 has. Dual serial ports, 32 IO lines.
I have a nice Duemilanove style board for the 366/644/1284 series of chips.

http://www.crossroadsfencing.com/BobuinoRev17/
Can use onboard FTDI module, mikroe483 from mouser.com, or offboard with FTDI Cable, FTDI Basic, or similar CP2102 module.

Bob, I've finally gotten around to populating the 1284 Duemilanove board you sold me. Still waiting on the 1284p chip but it's checking out with a 644P chip I had on hand. I really think if you or someone offered this in a completed assembled package with a included CP2102 cable that it could be a good seller.

 Have you had any problems yet with the software mods needed for the IDE? Any libraries not work? I've only run blink and a few other simple sketches just to verify basic operation so far.

Only question I have is the intended purpose of the 6 pin header in the corner of the board. Not real clear to me from the schematic what pins it actually breaks out? So far I didn't put header pins on it.

Lefty
« Last Edit: January 07, 2013, 11:18:57 pm by retrolefty » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27425
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have not seen any problems with 1.0. I tend not to use many libraries - Serial, SPI, I2C, VirtualWire are about it. Anything else, I read the datasheet and write my own stuff.

Maybe I'll look into 1284 kits after tax season. I can't take that on right now. Got fencing club taxes, personal taxes, college financial aid forms, and a 56 seven-segment display project to finish first.
Just delivered another 10 Mega screwshields, those are pretty popular. Board & 4 connector types, easy to package up, no ESD concerns.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have not seen any problems with 1.0. I tend not to use many libraries - Serial, SPI, I2C, VirtualWire are about it. Anything else, I read the datasheet and write my own stuff.

Maybe I'll look into 1284 kits after tax season. I can't take that on right now. Got fencing club taxes, personal taxes, college financial aid forms, and a 56 seven-segment display project to finish first.
Just delivered another 10 Mega screwshields, those are pretty popular. Board & 4 connector types, easy to package up, no ESD concerns.

And about my last question?

Quote
Only question I have is the intended purpose of the 6 pin header in the corner of the board. Not real clear to me from the schematic what pins it actually breaks out? So far I didn't put header pins on it.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27425
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, missed that one - it's to select whether A4/D18 & A5/D19 show up on the Analog  header pins, or whether SDA/SCL show up there.
I would put male pins there with two 2-pin jumpers like these to select.
http://www.dipmicro.com/store/JUMPER2

Finally got the schematic on the website too.


* ATMega1284_thruhole_sch1.png (80.48 KB, 2444x1233 - viewed 25 times.)
« Last Edit: January 08, 2013, 12:12:04 am by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Sorry, missed that one - it's to select whether A4/D18 & A5/D19 show up on the Analog  header pins, or whether SDA/SCL show up there.
I would put male pins there with two 2-pin jumpers like these to select.
http://www.dipmicro.com/store/JUMPER2

Ah, got it, I'll have to add that.

Thanks;

Lefty
Logged

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

Well if it's compiling for a mega board then it defines serial send and rec software buffers (in SRAM) for all four possible hardware serial ports even if you aren't using them. Others have complained of this behaviour but don't know if more intelligent method is forthcoming.

Lefty


Thanks for the info, I will need to do a test on my Uno board which only has 1 serial port.
Logged

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

A good chunk of that is the Tx and Rx buffers for the serial data.

If you need more SRAM, consider the '1284P - 16 Kbyte of SRAM, twice what the '2560 has. Dual serial ports, 32 IO lines.
I have a nice Duemilanove style board for the 366/644/1284 series of chips.

http://www.crossroadsfencing.com/BobuinoRev17/
Can use onboard FTDI module, mikroe483 from mouser.com, or offboard with FTDI Cable, FTDI Basic, or similar CP2102 module.


My main project is actually using one of these chips (love em! the extra ram is awesome) but my issue was that I need to communicated to individual devices over longer range than I2C will allow without a booster chip and my cheapest solution that I could find was the ATTiny45-20PU chip (NeWark sells these at 62 cent a piece if you buy 25 or more at a time) and I was worried about the memory foot print. I guess I will just order one and run software serial on it (or attempt to run it... 250 bytes of memory) and see where I stand. All the ATTinyies will have to do is read things like sensor values and transmit them to the main board which if I can get software serial to work on it would be perfect solution for the project.
« Last Edit: January 08, 2013, 04:42:39 am by InitialForce » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Does the ATtiny45 need to receive data or just send?
Logged

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


Does the ATtiny45 need to receive data or just send?

Just needs to send. Basically all I need it to do is identify itself with a byte value, then sent it's sensor info
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Is it possible for multiple ATtiny45s to transmit simultaneously on the same wire?
Logged

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


Is it possible for multiple ATtiny45s to transmit simultaneously on the same wire?


Good point... on second thought I guess the best option would be for it to be called on by the main board, then send its data, then stop transmitting until called upon again. Anyone know the distance limitation of an Arduino RX TX signal? This project is for an home automation system I am working on. If the distance RX TX can travel is not sufficient I will need to start looking into forwarding hubs (which should be simple enough by using yet again another ATTiny45 as in: receive signal, forward signal to other ATTiny's within range, read received return signal, forward return signal to main board).
Logged

Offline Offline
Sr. Member
****
Karma: 9
Posts: 254
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want, you can edit HardwareSerial.cpp and HardwareSerial.h and either change the buffer size (very easy), or turn off some of the serial ports (a bit harder but still relatively easy). Currently they allocate 64 byte buffers on Tx and Rx, which comes to 640 bytes (4 hardware UART and the USB connection as well gets allocated a serial port and pulls in more resources from the USB libraries). If you still need all of these you have no choice really but to leave them all on, and reduce buffer size, but be aware that if you do this you need to check the serial ports regularly to make sure there isn't any data to read.
Logged

Pages: [1] 2   Go Up
Jump to: