Strange problem with ICSC library

I'm working on a sensorial project.

ICSC library, made by majenko, is perfect for what I want.
I use a RS485 BUS and it worked very well... but only when my program was small and simple.

In short, this lib enable to communicate between nodes. All nodes can be identified with a number, and with commands which can callback other functions.
The communication can be started at anytime.

Now, I had to make libs for all routines on my program, to mantain all code tidy, but I'm having problems... very strange problems.

=> The problem:

I'm using a Datalogger (Seeeduino Stalker board) near Master node (Arduino Mega). The serial ports used are Serial1 on Master (Node 1) and Serial0 on Datalogger (Node 2). The other nodes aren't relevant for now.

== Datalogger libs and functions (only relevant):

  • logger
  • exportConfigFile (read from SD and send via serial)
  • checkFiles (verify if all needed files exists to start logging)
  • rs485com (deals with all communication data)
  • configSens (callback function to start exportConfigFile from logger lib)
  • startAq (callback function to start checkFiles from logger lib)

1- Master send a command to request config file from Datalogger: 'C' This command will callback configSens function;
2- Datalogger read the text file from SDcard. The memory is very limited, so I don't have space to store it on a variable (the file will be much bigger)... I read a byte from SDcard and send it to Master until a char '@' appear. (exportConfigFile function, called inside configSens function - class logger);
3- Datalogger send a confirmation command to Master: 'S'. This command will callback check function on Master; (just for test, and works well but only from Datalogger to Master);
4- then Master send a confirmation command to Datalogger: 'F'. This command will callback finished function;
And the problem is here! Datalogger stops to accept commands once configSens was executed.

You can download my attached code.

I commented non relevant code on Datalogger (I'm testing only this problem). The code of Master is only a simple version.
I already tested different baud values, commented serial communication (apart of ICSC) and many many other things, but nothing fixes this.

Does anyone knows what can be the problem?

Thanks,
regards

Does anyone knows what can be the problem?

How much memory is available on the machine that doesn't work properly? Not enough would be my guess. SD cards take a lot of memory.

http://playground.arduino.cc/Code/AvailableMemory

Can you point me in the direction of the DS3231 library you're using? None of the versions I have found will work with your code (not a class, no .begin(), etc).

PaulS:

Does anyone knows what can be the problem?

How much memory is available on the machine that doesn't work properly? Not enough would be my guess. SD cards take a lot of memory.

Arduino Playground - HomePage

The Seeeduino Stalker board is a 328p based board by the looks of things. 2K's all you've got there.

Yes, Seeeduino Stalker board have a 328p. On Arduino IDE, the board is "Arduino Pro or Pro Mini (3.3V, 8MHz) w/ ATmega 328".

I have around 500 bytes available, running last function of that playground page.
On Arduino IDE, the compile return this info:
Binary sketch size: 25,290 bytes (of a 30,720 byte maximum)
Estimated used SRAM memory: 1,484 bytes (of a 2048 byte maximum)

I attached RTC library I'm using. Sorry for that.

Thank you all.

DS3231.rar (17.1 KB)

Here's a breakdown of all the .bss and .data usage of the compiled sketch:

001 timer0_fract
001 twi_error
001 twi_inRepStart
001 twi_masterBufferIndex
001 twi_masterBufferLength
001 twi_rxBufferIndex
001 twi_sendStop
001 twi_slarw
001 twi_state
001 twi_txBufferIndex
001 twi_txBufferLength
001 _ZN14SoftwareSerial20_receive_buffer_headE
001 _ZN14SoftwareSerial20_receive_buffer_tailE
001 _ZN7TwoWire12transmittingE
001 _ZN7TwoWire13rxBufferIndexE
001 _ZN7TwoWire13txBufferIndexE
001 _ZN7TwoWire14rxBufferLengthE
001 _ZN7TwoWire14txBufferLengthE
001 _ZN7TwoWire9txAddressE
001 _ZN8SdVolume11cacheDirty_E
002 __brkval
002 __flp
002 twi_onSlaveReceive
002 twi_onSlaveTransmit
002 _ZN14SoftwareSerial13active_objectE
002 _ZN6SdFile9dateTime_E
002 _ZN8SdVolume7sdCard_E
004 RTC3231
004 timer0_millis
004 timer0_overflow_count
004 _ZN8SdVolume17cacheMirrorBlock_E
007 RTCchip
012 Wire
013 rs485
028 mySerial
032 twi_masterBuffer
032 twi_rxBuffer
032 twi_txBuffer
032 _ZN7TwoWire8rxBufferE
032 _ZN7TwoWire8txBufferE
034 Serial
059 datalog
064 _ZN14SoftwareSerial15_receive_bufferE
068 rx_buffer
068 tx_buffer
073 SD
084 ICSC
512 _ZN8SdVolume12cacheBuffer_E

As you can see the volume cache buffer of the SD card is huge compared to everything else.

ICSC is the next biggest. You can reduce the footprint of ICSC by tweaking some #define entries in the header file:

// This defines the maximum size of any message that can be sent
// between chips.  Reduce this to conserve memory at the cost
// of smaller packet sizes.  Note that this only affects the
// size of packets that can be received - you can always send
// up to 255 bytes.  If the remote end can't receive them all
// the packet will be silently discarded.
#define MAX_MESSAGE 25

// The maximum number of registered commands.  If you're not
// going to have many commands reducing this can save memory.
// If you want lots of commands you may need to increase this
// value.  Note that this ony affects the commands registerable
// at the receiving end
#define MAX_COMMANDS 10

In the data logger the MAX_COMMANDS could be reduced to 7. If you're not actively using the data portion sent in the packets you can reduce them down to just an empty string "" and drop the max packet size to 9 (8 bytes of packet, and 1 byte of empty string), or use the longer form of the send routine that takes a data pointer and a length, and set the length to 0 and the data pointer to null. Then you can set the max size to 8.

Or you can enable dynamic mode:

// Uncomment the definition of ICSC_DYNAMIC if you want to use
// dynamic memory allocation
//#define ICSC_DYNAMIC

which is even more memory efficient, but allocates memory on the fly. It might be better, or it might not.

Thank you for your reply.

I know SD lib takes a huge volume of memory. Initially a tried to use a tiny lib to read/write from SD (don't remember what lib), but something went wrong...
I can test without SoftwareSerial too, it's only for debug.

I will try your hints now and I will post feedback soon.

Thank you!

It's working now!

I really don't know why, but I already have uncommented the line #define ICSC_DYNAMIC (maybe because a previously problem I had with SD card, I tried to change this and forgot to reverse... :blush:). A noob mistake but very unfair :stuck_out_tongue:

Now, I commented it (disabled dynamic memory allocation) and everything working as expected.

Thank you!