Newbe I2C (SRF08 + CMPS03) questions...

27 Dec 2010

Hi All,

Moved from the "I2C freeze"

It seems I have have the I2C freeze problem... But I'm new at this stuff, so it is likely that it is just my own error ;-) but:

I’m trying to make an SRF08 to work, I have remember the 2 pullup resistors (1.4K).

And when the SRF08 is powered up it flashes the address, so it is alive, and i know the address.

But my program hangs for ever, on the first I2C write... and just stops there... the mbed just stops with the LED's as my program left them.

I have tried to use the SRF08 lib, same problem…

I have tried both p9+p10 and p28+p27… same problem…

To see if it was a problem with my SRF08, I tryed an CMPS03 but with same result, it hangs for ever on my first write...

Any ideas…my robot is driving around blind and keeps bumping into stuff ;-)

#include "mbed.h"
//#include "SRF08.h"

DigitalOut l1(LED1);
DigitalOut l2(LED2);
DigitalOut l3(LED3);
DigitalOut l4(LED4);
//SRF08 srf08(p9, p10, 0xE0);
Serial pc(USBTX,USBRX);
I2C sonar(p28,p27);

const int addr = 0xE0;
char cmd[2];
char echo[2];

int main() {
    pc.printf("Start up v.01 \n");
    l1=1;
    wait(1);

    cmd[0] = 0x02;
    cmd[1] = 0x1C;
    l2=1;
    pc.printf("--->Sonar.write\n");
    sonar.write(addr,cmd,2); // <--------------- My program will never exit this line of code.
    l3=1;
    pc.printf("<---Sonar.write\n");
    cmd[0] = 0x01;
    cmd[1] = 0x1B;
    sonar.write(addr,cmd,2);
    l4=1;

    pc.printf("Link OK to Sonar \n");

    while(1) {
        l1=!l1;

        wait(0.2);
    }
}
27 Dec 2010

Hi Nicolai,

If I2C is hanging, that suggests a problem with the bus. Perhaps recheck the wiring. Looking at the device, it says it is powered from 5v so I assume you are using the VU 5v output, but I suspect the I2C bus pull ups should pull to 3.3v, not 5v. Maybe also evaluate the values.

Another thing for reference; I wrote a simple program a while back to search for I2C devices on a bus:

This can be useful to find device addresses, but will still not function if the bus is not working.

See if some experimentation with the wiring and pull ups helps; I'd suspect that is where the problem lies.

Simon

27 Dec 2010

Hi Nicolai,

If I2C is hanging, that suggests a problem with the bus. Perhaps recheck the wiring. Looking at the device, it says it is powered from 5v so I assume you are using the VU 5v output, but I suspect the I2C bus pull ups should pull to 3.3v, not 5v. Maybe also evaluate the values.

Another thing for reference; I wrote a simple program a while back to search for I2C devices on a bus:

This can be useful to find device addresses, but will still not function if the bus is not working.

See if some experimentation with the wiring and pull ups helps; I'd suspect that is where the problem lies.

Simon

27 Dec 2010

Look at this example http://mbed.org/handbook/I2C

addr,cmd,x - address of the device, first cmd cmd[0]- address of the internal register .. and than cmd[1]- the command itself, x=2 bytes

in the pdf i saw for srf08.. you must send 0x51 cmd at addr 0x00 in order to get ranging in cm . That's exactly like the example above in the handbook.

To clear up things a little bit study the i2c bus and try simpler by sending

start()

write(byte)    - i2c hardware address of the slave device

write(byte)    - address of the register

write(byte)   - cmd to that register

stop()

27 Dec 2010 . Edited: 27 Dec 2010

Hi All,

Ok..I have tried a 1.8K and a 4.7K pull up to both 3.3v and 5v...same result...

I have tried to brake my write down to the:

start()

write(byte)    - i2c hardware address of the slave device

write(byte)    - address of the register

write(byte)   - cmd to that register

stop()

But still same result, it hangs on my first contact with the I2c Bus, now the start().

So it is likely my I2C bus, that is not up and running….hm..I have tried with an “empty” bus, only the pull up resistors, and still get the same result, but I’m not sure what to expect her.

Anyone else that have made an SRF08 to work, what are your pull up resistor values, and are you connecting them to 3.3v or 5v ?

 

28 Dec 2010

Ok...will try to eliminate the problems... one by one... Will an mbed with only 2 pull up resistors on the I2C bus work ? Will i be able to run the I2CU program and get no other result than I can talk on the bus ?

28 Dec 2010

What do you mean by "only 2 pull up resistors"? . There must me exactly 2 resistors ! Not more!

Or by that you mean - no slave devices on the bus? Without them you will not get any ACK. 

29 Dec 2010

Yeps... I mean, with no slave device, i will still be able to write to the bus like in Simons I2CU program... I will test some more :-)

01 Jan 2011

Hm....now it all works fine... have my SRF98 up and running...

Must have been a faulty wirring, I have just unpluged it all and remade it to day... Thanx to you all...I will now try to bring some of my other I2C devices to live :-)

02 Jan 2011 . Edited: 02 Jan 2011

OK..now i got an SRF08, CMPS03 and an LM75AD to run on the same I2C bus. I'm using 47K Ohm as pull up resistors to +5V.

Just a simple diagram, to show how I finaly got it to work :-)

And by running the I2CU program I get:

I2CU! Searching for I2C devices...
- I2C device found at address 0x00
- I2C device found at address 0x9E
- I2C device found at address 0xC0
- I2C device found at address 0xE0
4 devices found