cancel
Showing results for 
Search instead for 
Did you mean: 

VL6180X set_register and get_register functions for PIC18F

bmete21
Associate II

Hello Everyone,

I'm working on a project where I need to use the VL6180X sensor with the PIC18F. However, I could not adapt the set register and get register functions in Arduino to the PIC using CCS C. All I want from the experts here is to adapt the two functions I shared below to work in the CCS C program in accordance with PIC.

uint8_t VL6180x::VL6180x_getRegister(uint16_t registerAddr)
{
  uint8_t data;

  Wire.beginTransmission(_i2caddress);    // Address set on class instantiation
  Wire.write((registerAddr >> 8) & 0xFF); // MSB of register address
  Wire.write(registerAddr & 0xFF);        // LSB of register address
  Wire.endTransmission(false); // Send address and register address bytes
  Wire.requestFrom(_i2caddress, 1);
  data = Wire.read(); // Read Data from selected register

  return data;
}

void VL6180x::VL6180x_setRegister(uint16_t registerAddr, uint8_t data)
{
  Wire.beginTransmission(_i2caddress);    // Address set on class instantiation
  Wire.write((registerAddr >> 8) & 0xFF); // MSB of register address
  Wire.write(registerAddr & 0xFF);        // LSB of register address
  Wire.write(data);                       // Data/setting to be sent to device.
  Wire.endTransmission(); // Send address and register address bytes
}

Thanks to everyone who supported.

10 REPLIES 10

Hello Andrew,

You can delete my previous message, because I got the screen shots, 

(1) no i2c_read()(1) no i2c_read()(2) no i2c_read()(2) no i2c_read()(3) no i2c_read()(3) no i2c_read()(4) with i2c_read()(4) with i2c_read()(5) with i2c_read()(5) with i2c_read()(6) with i2c_read()(6) with i2c_read()(7) with i2c_read()(7) with i2c_read()(8) with i2c_read()(8) with i2c_read()