7

I am looking for (reasonably easy to use and well tested) alternatives to the Wire library. Wire works very well, but: I only need the Arduino to act as I2C master and the Wire library seems to be a real waste of resources:

My goal is to send out data en bloc (e.g. 32 or 64 bytes). This data is already sitting in an array in SRAM. Now when you use the Wire library, you call the TwoWire::write function which copies your data into a 2nd buffer. Afterwards, Wire makes use of the TWI library where twi_writeTo copies the data again into a 3rd buffer. That's a bit clunky, isn't it?

I have seen the DSSCircuits / I2C-Master-Library but I am not sure how mature it is because there hasn't been any commit after the initial commit which is 3 years old now.

David Hempy
  • 105
  • 5
fuenfundachtzig
  • 1,535
  • 1
  • 14
  • 26

5 Answers5

4

I don't see any objection to using DSS Circuits I2C Master Library.

It may not have been updated for a couple of years, but if it works it doesn't need to be. It's not as if libraries for micro-controllers have to support new printer drivers, video drivers, etc.

If it works, it works.

The chip hasn't changed, and the only real reason for updates these days is if the IDE changes (or the compiler changes) in such a way that it introduces compile errors. Such things have happened fairly recently with things like PROGMEM having tighter rules, for example.

Nick Gammon
  • 38,901
  • 13
  • 69
  • 125
4

Also Procyon AVR library worth be checking. It is a bit old now but very professional and kinda minimalistic. Not much dependencies, should be fine to use just I2C module only. There is hardly anything new in AVR I2C part since.

Flanker
  • 529
  • 2
  • 8
3

Cosa TWI class is a very different approach to I2C device driver support. It does not use any extra SRAM for buffers at all. If a device driver is non-blocking it must handle the necessary buffering. Also the Cosa TWI class supports typical interaction with I2C devices such as master/slave, "write register-read data"-patterns, and transactions when using multi-threading.

A software and hardware Arduino-TWI library is available. It uses the Arduino-GPIO library and can be used on AVR and SAM based boards.

Some examples: TWI Scanner, DS3231 Real-Time Clock/Calender, I2C LCD Adapter with PCF8574.

Mikael Patel
  • 7,989
  • 2
  • 16
  • 21
2

You can use completely different approach to the top question. Asking for alternatives you have given reason to this: getting rid of unused code in the binary. You can achieve removal of unused code without actually using alternative library. Please keep in mind, that you can instruct the compiler and linker to exclude unused code from the compiled binary. Just use compilation flags:

CFLAGS += -Wl,-static
CFLAGS += -ffunction-sections
CFLAGS += -Wl,--gc-sections

Rach function will be in its own section.

LDFLAGS += -Wl,-gc-sections

This tells GCC to send the -gc-sections flag to the linker which will remove unused sections. And voilla! Unused sections are removed.

Damago
  • 66
  • 1
1

I made 2 libs myself for easier use and consistant calls:

one for AVR targets:
cI2C

another using the same functions for all other targets (which basically is a wrapper for Wire library):
WireWrapper

Both are available within the IDE library manager.
They both work as master without using interrupt and are tested on different targets with different slaves:
- UNO, Nano for cI2C
- Zero, Due & ESP8266 for WireWrapper

SMFSW
  • 367
  • 2
  • 7