Go Down

Topic: Huge I2C RAM usage (Read 1 time) previous topic - next topic

joe912

I am trying to send large amounts of data for a rgb led array from 1 arduino to another.  So i am planning on using i2c since the tlc5940 uses the spi port.
The problem is when i increase the buffer size the ram usage increases by a factor of 5

i used the available ram function found in the playground
(i know it may not be perfect)

                                                 free             used for library
ram free with only serial initiated  798 B

ram free with 128 B buffer           121 B                 677 B
ram free with 64 B buffer             441 B                 357 B
ram free with 16 B buffer             681 B                 117 B


so the i2c library uses

used Ram  = 5*BufferSize + 37 B

i would ideally like to use a buffer of 128 B but seeing as i need more than 121B of ram for the led array im at a loss

looking through Wire.cpp i see that calloc is called once for rxBuffer then again for txBuffer
Code: [Select]
void TwoWire::begin(void)
{
 // init buffer for reads
 rxBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t));
 rxBufferIndex = 0;
 rxBufferLength = 0;

 // init buffer for writes
 txBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t));
 txBufferIndex = 0;
 txBufferLength = 0;

 twi_init();
}


then in twi.c calloc is called three times
Code: [Select]
     // allocate buffers
 twi_masterBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t));
 twi_txBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t));
 twi_rxBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t));


My question is why does the twi/i2c bus need 5 separate buffers?
Seems like 2 buffers should be fine.

looks like i might have to upgrade to the 328

Thanks for you Help.

wizhippo

I saw this today too looking at the code.

I think the buffing in the c++ class should be removed as it is already done in the underying c code.

Go Up