Go Down

Topic: I2C longer packet lengths/ more efficient SRAM use (Read 6419 times) previous topic - next topic

Kano

Hi there,

I'm new to the arduino environment but am fairly familiar with pic and avr controllers and C.

I've managed to get two arduinos to communicate over I2C using the "wire.h" libs however i needed to increase the packet size of my I2C comms from the default 32 bytes up to 264 bytes for my application.

I've been into the wire.h and twi.h files and changed the defined size of the TWI buffers up to 128 and all is good but when i try to get up to 256 i run into problems.

Firstly the buffer length  pointers are only defined as uint8_t which limits me to 256 byte packets.

The second problem is that when i take the buffer size up to 255 (so still within the limits of uint8_t) i see odd behaviour which looks very much like running out of SRAM to me. A scout through the TWI.h and Wire.h seems to suggest that between them these define a total of 5 buffers each of length TWI_BUFFER_LENGTH (in my case 256)! Add to this the fact that i need to have an array of transmit and receive data in my program to pass to these and you soon get up to 7*256 = 1.8kB! :o

Does anyone have a library that will cope with transmitting larger packet sizes over I2C?

The first uint8_t limit seems reasonable and i understand that longer packets are unusual so i may have to mod a library myself for this but the multiple buffers in the wire.h library seem to be an uneccesary inefficiency.

Thanks for any advice people might have.

Cheers

Alan

jluciani

I have been using the AVR TWI library in my RTC library.
The TWI code is from the AVR site. I made some minor
modifications and added doxygen comments.

There is a link under "Libraries" in the sidebar at

http://wiblocks.luciani.org/PICO/index.html

(* jcl *)

http://www.wiblocks.com

Kano

thanks very much (* jcl *).

I had downloaded the Atmel master and slave example code but had been having trouble getting it working. The changes I had made seem pretty similar to those you have made (basically modifying the definition of the interupt vector table). Having now downloaded your libs i'm having the same trouble so i'm obviously doing something wrong in the IDE to include a new lib.

At present i've unzipped your TWI lib into a folder called TWI in the libraries folder of the IDE.

I've then included

extern "C"
{
#include <inttypes.h>
#include "WConstants.h"
#include "TWI.h"
}

At the start of my sketch. when i compile this i get no error so i then included

void setup(void)
{
 twi_master_init();
}

which produces the following error on compile

wiblock.cpp.o: In function `setup':
C:\Users\ALANK~1.CLY\AppData\Local\Temp\build2903788061906935170.tmp/wiblock.cpp:18: undefined reference to `twi_master_init'

I assume i've done something wrong and the library isnt actually being included?

PaulS

Quote
I've then included

Code: [Select]

extern "C"
{
#include <inttypes.h>
#include "WConstants.h"
#include "TWI.h"
}

Why are you wrapping these with the extern "C"?

jluciani

Code: [Select]
I've then included

extern "C"
{
#include <inttypes.h>
#include "WConstants.h"
#include "TWI.h"
}

At the start of my sketch. when i compile this i get no error so i then included

void setup(void)
{
twi_master_init();
}

which produces the following error on compile

wiblock.cpp.o: In function `setup':
C:\Users\ALANK~1.CLY\AppData\Local\Temp\build2903788061906935170.tmp/wiblock.cpp
:18: undefined reference to `twi_master_init'

I assume i've done something wrong and the library isnt actually being included?


Is twi_master_init a function you wrote? I do not
recall that function in my library (it has been a while since
I looked at the library ;)

Take a look at any of the sketches on my site that use the
the RTC library. The RTC IC has an I2C interface and uses
the TWI library.

(* jcl *)

http://www.wiblocks.com


Go Up