how to configure a I2C in MCB1700 with LPC1758?

how to configure a I2C in MCB1700 with LPC1758?

I have a MCB1700 board with LPC1758, I am trying to use the I2C on it as a master to run a ultrasonic sensor srf08.

How should I configure the I2C setting on the LPC1758?

Parents
  • Sorry I am a bit confuse right now.

    For the I2C write to Sensor

    I2CWriteLength[PORT_USED] = 3;                            //writelength=3 because 1 for sensor_addr(0xE8), 1 for 0x00 and 1 for0x51 right?

      I2CReadLength[PORT_USED] = 0;                           //readlength=0 because it is write only

      I2CMasterBuffer[PORT_USED][0] = sensor_addr;      //first port is sensor addr telling the i2c what the sensor addr is

      I2CMasterBuffer[PORT_USED][1] = 0x00;                //second port is command register

      I2CMasterBuffer[PORT_USED][2] = 0x51;                //command for sensor start in range cm

      I2CEngine( PORT_USED );                                     //I2CEngine do the scheduling

    Do I need a delay after write and then do a read 1 byte from sensor?

      I2CWriteLength[PORT_USED] = 0;                          //writelength=0 because read only

      I2CReadLength[PORT_USED] = 1;                          //read 1 byte only

      I2CMasterBuffer[PORT_USED][0] = sensor_addr;     //telling the i2c what the sensor addr is

      I2CEngine( PORT_USED );                                     //I2CEngine do the scheduling

      while ( 1 );                                                              //loop forever

    }

    So the byte read from the sensor will be in the masterbuffer?

    Sorry for having so many question, it is because this is my first to write a program and learn a I2C!

    And thank you for you being patient to me

Reply
  • Sorry I am a bit confuse right now.

    For the I2C write to Sensor

    I2CWriteLength[PORT_USED] = 3;                            //writelength=3 because 1 for sensor_addr(0xE8), 1 for 0x00 and 1 for0x51 right?

      I2CReadLength[PORT_USED] = 0;                           //readlength=0 because it is write only

      I2CMasterBuffer[PORT_USED][0] = sensor_addr;      //first port is sensor addr telling the i2c what the sensor addr is

      I2CMasterBuffer[PORT_USED][1] = 0x00;                //second port is command register

      I2CMasterBuffer[PORT_USED][2] = 0x51;                //command for sensor start in range cm

      I2CEngine( PORT_USED );                                     //I2CEngine do the scheduling

    Do I need a delay after write and then do a read 1 byte from sensor?

      I2CWriteLength[PORT_USED] = 0;                          //writelength=0 because read only

      I2CReadLength[PORT_USED] = 1;                          //read 1 byte only

      I2CMasterBuffer[PORT_USED][0] = sensor_addr;     //telling the i2c what the sensor addr is

      I2CEngine( PORT_USED );                                     //I2CEngine do the scheduling

      while ( 1 );                                                              //loop forever

    }

    So the byte read from the sensor will be in the masterbuffer?

    Sorry for having so many question, it is because this is my first to write a program and learn a I2C!

    And thank you for you being patient to me

Children