I am still having trouble with the Makefile and libraries. The LCD4Bit works with the -I mentioned some posts above. But the twi lib doesn't work. In Wire.cpp I changed #include "twi.h" to #include "utility/twi.h" (line 24), this gets me a little bit further but it still doesn't compile. This is the make output:
applet/core.a(Wire.o): In function `TwoWire::begin()':
Wire.cpp:(.text+0x38): undefined reference to `twi_init'
applet/core.a(Wire.o): In function `TwoWire::begin(unsigned char)':
Wire.cpp:(.text+0x44): undefined reference to `twi_setAddress'
Wire.cpp:(.text+0x4a): undefined reference to `twi_attachSlaveTxEvent'
Wire.cpp:(.text+0x50): undefined reference to `twi_attachSlaveRxEvent'
applet/core.a(Wire.o): In function `TwoWire::requestFrom(unsigned char, unsigned char)':
Wire.cpp:(.text+0x76): undefined reference to `twi_readFrom'
applet/core.a(Wire.o): In function `TwoWire::endTransmission()':
Wire.cpp:(.text+0xae): undefined reference to `twi_writeTo'
applet/core.a(Wire.o): In function `TwoWire::send(unsigned char)':
Wire.cpp:(.text+0x10c): undefined reference to `twi_transmit'
applet/core.a(Wire.o): In function `TwoWire::send(unsigned char*, unsigned char)':
Wire.cpp:(.text+0x15c): undefined reference to `twi_transmit'
make: *** [applet/i2c_test.elf] Error 1
I made a very simple example:
#include <Wire.h>
void setup()
{
Wire.begin();
Wire.beginTransmission(0x1D);
Wire.send(0x20);
Wire.send(0x87);
Wire.endTransmission();
}
void loop()
{
}
This compiles with the arduino IDE. The modifications to the makefile:
ARDUINO = $(INSTALL_DIR)/lib/targets/arduino
ARDUINOLIBS = $(INSTALL_DIR)/lib/targets/libraries
AVR_TOOLS_PATH = $(INSTALL_DIR)/tools/avr/bin
SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
$(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \
$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WRandom.cpp \
$(ARDUINOLIBS)/Wire/Wire.cpp
FORMAT = ihex
# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile
# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
DEBUG = stabs
OPT = s
# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)
CXXDEFS = -DF_CPU=$(F_CPU)
# Place -I options here
CINCS = -I$(ARDUINO) -I$(ARDUINOLIBS)/Wire -I$(INSTALL_DIR)/lib/targets/wiring
CXXINCS = -I$(ARDUINO)