I2C not able to write to slave device

I’m trying to get I2C functioning, but when I try writing to the slave devices, the result I get back is -2.

I have built an impee that uses I2C on pins 8 & 9, connecting to three devices. One is a PCA9531 8-bit LED dimmer, the other two are DS2482-100 onewire masters. I have 4.7K pullup resistors on both SDA and SCL. I have confirmed that SDA and SCL do indeed go to the correct pins on all ICs. The relevant part of the circuit board is attached with SDA highlighted.

The PCA9531 should be at address 192 (0xC0) and the DS2482s should be at 48 and 50 (0x30 and 0x32). The code below only tries to write to the PCA9531, but I can’t get a response from the DS2482s either. I’ve tried scanning every address, and I always get a result of -2.

`server.log(“Starting I2C Test Application”);

local i2c = hardware.i2c89;
local Address = 0xC0;

function loop() {
local e = i2c.write(Address, “\x11\x97”);
server.log(format(“Result = %d”, e));

imp.wakeup(1, loop);


imp.configure(“I2C-Test-App”, [], []);

I don’t believe I have a hardware issue, but anything is possible. Any suggestions would be very much appreciated.


Looking at your PCB, I can’t see that the pullups are actually attached to power (nor is pin 16 of the PCA9531). The pullups are attached to pin 16 of the PCA, but that’s not going to help much unless they’re also connected to power :slight_smile:

The vias are hidden in that image. The copper between the pullups and pin 16 of the PCA has two vias connecting to the bottom of the board where the 3.3v is. I have used a volt meter to confirm that there is 3.3v at pin 16 and on the pullups.

Ack, just wrote a reply and lost it :frowning:

I’d check the socket connections. Some code like this will help determine if the imp pin is indeed getting to your board:

testpin <- hardware.pin8; function low() { imp.wakeup(2, high); testpin.write(0); } function high() { imp.wakeup(2, low); testpin.write(1); } low();

…these transitions should be slow enough to see on a meter.

Yeah, that solder joint would have fooled me too. Glad it’s working now!

Resolved. I had a bad solder joint between pin 9 of the card socket and the pad on the PCB for SDA. It visually looked connected, but didn’t have continuity. I used a soldering iron to re-solder that connection.

I took Hugo’s code and tweaked it a bit into the following application:

`pin8 <- hardware.pin8;
pin9 <- hardware.pin9;

function low() {
imp.wakeup(2, high);
function high() {
imp.wakeup(2, low);

imp.configure(“Pin89-high-low”, [], []);

I found pin 8 was changing voltage, but pin 9 wasn’t. It was stuck at 3.3v due to the pull-up resistor holding it there and was never pulled low. I moved the Imp to an April development board and confirmed that the pin on the Imp does indeed work, which narrowed the problem to the socket or a bad solder joint. I found that the solder on the pad was connected to the pad, but not to the socket pin. In my prior continuity tests, my test lead must have been touching the solder, so I was getting good readings.