2024-04-30 03:23 AM - last edited on 2024-04-30 03:34 AM by Peter BENSCH
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.
2024-05-02 12:15 AM
Hello Andrew,
You can delete my previous message, because I got the screen shots,