<< Back Home UK uk   Donate Donate

Arduino Zero-copy I2C (Wire) library

I'm developing one tool and need simple/cheap Wire I2C для Arduino converter. It's separate story, would be released soon. And I decided to use Arduino. Everything was ok, except one test. Appeared that standard TwoWire library has 32 bytes limit. And uses a lot of memory, 5 buffers of 32 bytes. Two (2) ones on upper level (Wire) and three (3) buffers in twi which works directly with I2C controller. In general, it is possible to increase up to 64 bytes, but not more, since we have only 2kb memory.

Not critical problem for original task, but I've added several features in UART-to-I2C and it would be dumb to have such limitation. Google search propose several solutions, but either inconvenient or a bit incomplete. Finally I've changed original library and reduced internal buffers to 2 of 32 bytes (and it is possible to reduce even more) , added possibility to use single user buffer for all operations without additional memory copy with max possible size up to 255 bytes.


#include <stdint.h>
#include "WireZ.h"

#define Wire WireZ

#define I2C_MAX_TRANSFER  255
uint8_t i2cbuffer[I2C_MAX_TRANSFER];    // I2C input buffer

void setup() {

  Wire.setUserBuffer(&i2cbuffer[0], I2C_MAX_TRANSFER, true /*twi ZeroCopy and shared buffer with Wire*/);






See also:

FB or mail (remove X)   Share
designed by Alter aka Alexander A. Telyatnikov powered by Apache+PHP under FBSD © 2002-2024