lpcware

I2C code problem with Srf08 ultrasonic sensors with LPC1758

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by hoiyin00 on Thu Apr 24 13:06:09 MST 2014
Hi all,
I have studied how to set up for I2C for Srf08 sensor. however, I dont know how to write it to the LPC1758 I2C controller.
From the I2C Example I used in MCB1700 example code bundle. I dont understand how to the step below in the i2cmst.c
Can anyone share their experience on that to help solve the problem please?

Here is the steps for the I2C to write and read to sensor
write to sensor
i2c_start();              // send start sequence
i2c_tx(0xE0);             // SRF08 I2C address with R/W bit clear
i2c_tx(0x00);             // SRF08 command register address
i2c_tx(0x51);             // command to start ranging in cm
i2c_stop();               // send stop sequence

read from sensor
i2c_start();              // send start sequence
i2c_tx(0xE0);             // SRF08 I2C address with R/W bit clear
i2c_tx(0x01);             // SRF08 light sensor register address
i2c_start();              // send a restart sequence
i2c_tx(0xE1);             // SRF08 I2C address with R/W bit set
lightsensor = i2c_rx(1);  // get light sensor and send acknowledge. Internal register address will increment automatically.
rangehigh = i2c_rx(1);    // get the high byte of the range and send acknowledge.
rangelow = i2c_rx(0);     // get low byte of the range - note we don't acknowledge the last byte.
i2c_stop();               // send stop sequence

Outcomes