"utility/twi.h" not working on platformavr

I’m porting some code I wrote initially (and is working) on arduino/esp8266. Due to the nature of the chip I’m interfacing with, I’m using the utility/twi.h portion of the Wire library rather than the Arduino-standard Wire class.

This is the minimum non-working code:

#include <Arduino.h>
#include <utility/twi.h>

void setup()
{
  twi_init();
  twi_stop();
}

void loop()
{


}

Which lints, but generates the following errors:

/var/folders/gw/hhfvl_n52w5dwvtd2c456mgm0000gn/T//cceW9bo6.ltrans0.ltrans.o: In function `main':
cceW9bo6.ltrans0.o:(.text.startup+0x15e): undefined reference to `twi_init()'
cceW9bo6.ltrans0.o:(.text.startup+0x162): undefined reference to `twi_stop()'

The complete build console is here.

Adding #include <Wire.h> does not change this condition.

My platformio.ini looks like this:

[env:feather32u4]
platform = atmelavr
board = feather32u4
framework = arduino

The minimum working code on esp8266 is this:

#include <Arduino.h>

void setup()
{
  twi_init(0,2);
  twi_stop();
}

void loop()
{


}

With this platformio.ini:

[env:esp_wroom_02]
platform = espressif8266_stage
framework = arduino
board = esp_wroom_02

What is your main file C or C++?

It’s a C++ file-- is the twi.c throwing off the linker?

Does it work with Arduino IDE?

1 Like

It does not work in Arduino (at least not 1.6.7 which is what I have installed).

I’ve solved the issue by just bringing twi.h and twi.c into the project as a library… becuase there are a lot of headers called “twi”, I switched it to mytwi.c and mytwi.h, and then ended up renaming it to mytwi.cpp and now it’s compiling.

Will know tomorrow when I have hands back on hardware if it’s actually working.