I2C interface problem

barlow

New Member
I'm doing something wrong in interfacing a PICAXE 18-X to an infrared distance sensor. Can anyone help?

1. The sensor is a HVW Technologies "I2C-IR" device (http://www.hvwtech.com/products_view.asp?ProductID=665) which has an i2C interface.

2. I'm connecting to a PICAXE 18X using a PICAXE EXPERIMENTER BOARD (AXE090). It has a breadboard section, and places for 8, 18, and 24 pin devices.

3. Power is 3 AA batteries, so 4.5V

4. There are four lines between the board and the device: +ve, GND, data and clk. The i2c lines are connected to the 18X as follows: Data to "Output 1" (pin 7), and Clock to "Output 4" (pin 10). The i2C lines have 2.2K pull-up resistors to the +ve line.

5. The code in question looks like this:
Code:
i2cslave %01000000, i2cslow, i2cbyte
i2cread 1, (b0)
6. The only value I get in b0 is "255". Something is going wrong somewhere, but I'm not sure where.

Any advice would be great!
Thanks,
Chris
 

Attachments

Last edited:

westaust55

Moderator
A value of 255 typically indicates that the i2c slave device is not communicating and the pull up resistors are hiolding the data line high so all bits for each byte are read as 1’s.

Have you looked at the example code provided at the site you gave a link to:
http://www.hvwtech.com/products_resources.asp?CatID=0&SubCatID=0&SubSubCatID=0&ProductID=665


You description of connections in point 4 appears to be correct and I cannot quickly see anything wrong with the lines of code you included.

Do you have the three address Jumpers JP1, JP2 and JP3 all open (no links)?

Otherwise I would first be checking that the connections are all in fact good.
You could also try 4.7KOhm resistors for the pull-ups to the i2c lines but 2.2kOhm should be okay.
 
Last edited:

barlow

New Member
I used the example code as a starting point, but it uses the newer i2c commands unsupported by the 18X.

I just hooked up another i2c device and surprise, surprise, I'm getting 255 values again - it's very frustrating. I just know I have something stupid somewhere. Reminds me of a 'lab' way back during university days when something just didnt work. Turned out a jumper wire was broken inside its insulation! A cunning distraction for poor undergrads!

Thanks,
Chris
 

barlow

New Member
Success!

I took your advice and tried a 4.7K pull-up (which I had to search around for, or I might have used it first time round). This seems to have done the trick!

My i2C reading had suggested that a pull-up in the range 1k - 10K would have been OK, but it seems that with my devices and PICAXE it is more sensative and the recommended 4.7K is the thing to use.

Thanks again for your suggestions!
Chris
 

Technical

Technical Support
Staff member
We would expect 2k2 to work.

Looking at your photo it looks like the two 2k2s where in different rails at the bottom of the breadboard.... maybe 'replacing' with 4k7s also fixed this error!
 
Top