My simple starter project uses an Imp breakout board from SparkFun connected to an Arduino. The Arduino is configured as in I2C slave (with arbitrary address 0xD3). The imp is configured as master (I’m assuming at any rate). My logic analyzer shows only traffic on the SDL line and the SCL line is quiet. I have soldered up the 4k7 pullup resistors. I have verified that the logic analyzer and Arduino both work by changing the Arduino’s firmware to be an I2C master and observed both the SCL and SDA lines active (the was successfully asking for slave 0x08 which doesn’t exists). Is there something I’m missing? Is there some secret sauce needed to get the Imp to generate a clock on pin1/SCL line? Code below…
Imp code:
`local ARDUINO_SLAVE_ADDR = 0xD3;
//------------------------------------------------------------------------
// Class to interact with the Arduino as an IC2 slave device
class ArduinoI2CSlave
{
i2cPort = null;
i2cAddress = null;
i2cRegister = “\x00”;
constructor(port, address)
{
if (port == I2C_12)
{
// Configure I2C bus on pins 1 & 2
hardware.configure(I2C_12);
i2cPort = hardware.i2c12;
hardware.pin1.configure(DIGITAL_OUT);
}
else if (port == I2C_89)
{
// Configure I2C bus on pins 8 & 9
hardware.configure(I2C_89);
i2cPort = hardware.i2c89;
}
else
{
server.log("Invalid I2C port specified.");
}
i2cPort.configure(CLOCK_SPEED_100_KHZ);
i2cAddress = address << 1;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// returns a block of data from the arduino
function read(numBytes)
{
local data = i2cPort.read(i2cAddress, "", numBytes);
if (data == null)
{
server.log("I2C Arduino Read Failure");
return null;
}
return data;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// writes a block of data to the arduino
function write(data)
{
i2cPort.write(i2cAddress, data);
}
}
//---------------------------------------------------------------------------------
function startSlave()
{
// write greeting to the slave
arduino.write("\xA0");
imp.wakeup(0.25, readFromArduino);
}
//---------------------------------------------------------------------------------
function readFromArduino()
{
// read data from the i2c device
local greeting = arduino.read(17);
if (null != greeting)
{
server.show(greeting);
}
else
{
server.show("No response from arduino: " + time());
}
imp.wakeup(5.0, startSlave);
}
imp.configure(“Foo”, [], []);
// construct an arduino object
arduino <- ArduinoI2CSlave(I2C_12, ARDUINO_SLAVE_ADDR);
startSlave();
`