Well, first thing I'd advise you to get a logic analyzer, such as the logic
or the openbench
or the buspirate
or an arduino based one (or any other more expensive options that can interpret i2c
).
Then, you'll see if there is no electronic problem.
There are a few parameters you should test:
- is there line continuity between both components, many i2c problems can come from a faulty cable or bad trace on the PCB:
- Use a tester, or better, do a HIGH/LOW loop on the three pins you use for i2c on the arduino, and see if you can read it on the PIC side.
- did you wire i2c correctly on both sides?
- this may look stupid, but shit happens… Is
SDA
really wired toSDA
,SCL
toSCL
?
- this may look stupid, but shit happens… Is
- is the i2c speed configured the same on both sides?
- per default, speed is set up at 100kHz on arduino (though doublecheck your
twi.c
file). You can change that setting to higher speed by setting it to 400kHz before includingWire.h
, i.e.:#define TWI_FREQ 400000L
- I do not know much about PIC's side of things, but check that the speed is correctly set.
- using the logic analyzer, check that the clock line is indeed spinning at the advertised value. As all clocks are related on an AVR, sometimes you may expect a given speed, but get only half of it because a fuse is set wrongly or some setting is wrong making the MCU's clock half speed (and all other clocks as well).
- per default, speed is set up at 100kHz on arduino (though doublecheck your
- as I said, I don't know much about PIC, but are the pins you're using on the PIC able to cope with i2c's speed?
- I know that on AVR, bit banged i2c communication may need to be done at a slower speed. Could it be the case for PIC?
if none of what I said works, then I guess it's time for you do determine which of the devices is mute or deaf, from an i2c perspective…
Then, try to use both of your boards with another i2c device. i.e., try to communicate with your computer with the PIC board, either by using a buspirate, an i2c dongle or your display connector and then use i2cdetect
to play with it.
On the other end, try to connect to any kind of industrial i2c component using your Arduino. Knowing the one that does not work will help you investigate which one is not working, or misbehaving.
And finally, if you're comfortable enough with software engineering, I advice you a lot to use the i2cdev
library, which actually makes a decent abstraction on top of the flawed Arduino implementation.
HTH