I’ve been trying to setup an I2C connection for a little while now with not much success. I just get “MASTER_SELECT_ERROR”
Here is the squirrel code
hardware.i2cFG.configure(CLOCK_SPEED_400_KHZ); local data = hardware.i2cFG.read(0x41 << 1, "", 1); server.log(data);
I was using another device, but in an attempt to remove potential variables I’ve just set it up with an Intel Edison board. Arduino code:
#define SLAVE_ADDRESS 0x41
What else can I try to get to the bottom of the issue? I’m not sure what “MASTER_SELECT_ERROR” could mean.
That error suggests the imp (master) has driven a start condition on the bus but the slave is holding one or both of the signals low (or maybe your external pull-up resistors have the wrong value).
I have 4.7kΩ pull-up resistors on the line
You do have your resistor tied high? … to 3.3V? … not to ground.
Refer to this:
Note that with the adafruit i2c device, they provide the pull-up resistors so none is needed. In your case we don’t know what pull-up resistors may already be provided by your hardware. Just know the resistors should not be going to GND.
The arduino code is doing something totally different. It’s doing the equivalent of:
hardware.i2c.write(0x41 << 1, “0”);
…there’s no reading going on at all. The address presented on the bus will be different, and the transaction is different. What device are you trying to talk to?
Yeah it’s tied to 3.3V.
So I’m trying to get the Arduino to be the slave (as the imp can’t be a slave correct?).
According to the documentation if you supply a 7-bit address to Wire.begin() then it joins the bus as a slave.
Wire.onRequest() registers a callback when the master requests data from the slave.
Wire.write() writes data from the slave in response to a request from the master.
The imp code is meant to try and read that value from the slave.
So Imp (Master) is trying to read from the Arduino (Slave).
Ah, I see. I’ve never tried that on an arduino. I would say that UART is a lot easier to deal with than I2C, though…
Well eventually I need to talk to something else via I2C the arduino is only there to more easily debug the Electric Imp issue.
Any other ideas here? I hooked up two arduino’s and the I2C communication worked fine between them. But as soon as I try with the Electric Imp as master I’m getting the “Timeout waiting for bus to be released after sending start” issue.
The pullup resistor are exactly the same I’m just switching the wires from the arduino to the imp F&G.
I’d ask, why use the Arduino at all? I understand the desire to debug the setup, but I think I’d go straight to the device you actually want to connect and try and get that working. That way you’re bypassing two platforms’ quirks and go straight to the basic device comms. For instance, I don’t know how well Arduino’s Wire library operates in slave mode when it seems clearly designed for running the Arduino as master. FWIW, I’ve connected almost a dozen I2C devices (displays, sensors, storage) as slaves to the imp and not had an issues, and I’m certainly no expert on this kind of thing. My gut feeling here is that the Arduino is just complicating things.
Here’s an invaluable tool for debugging buses, no guessing just excellent software showing you what’s happening on the wires.