Skip to main content
KWine
Senior
August 8, 2021
Solved

Multiple byte read for VL53L5CX?

  • August 8, 2021
  • 3 replies
  • 1535 views

We seem to be having trouble getting through the vl53l5cx_init(&Dev); function for the VL53L5CX. We can read single bytes but multiple byte (4) reads trigger the TIMEOUT and the ULD doesn't load successfully. Here is our RdMulti function:

uint8_t RdMulti(
 VL53L5CX_Platform *p_platform,
 uint16_t RegisterAddress,
 uint8_t *p_values,
 uint32_t size)
{
 uint8_t DeviceAddress = p_platform->address;
 
 Wire.beginTransmission(DeviceAddress); 
 Wire.write((RegisterAddress & 0xFF00) >> 8); //MSB
 Wire.write(RegisterAddress & 0x00FF); //LSB
 
 uint8_t status = Wire.endTransmission(false); 
 if (status) { // failed
 return status;
 }
 
 uint32_t i = 0;
 status = Wire.requestFrom(DeviceAddress, size);
 if(status != size){
 return 1; // failed
 }
 
 while (Wire.available()) {
 p_values[i++] = Wire.read();
 }
 
 return 0;
}

This is a pretty standard multiByte read function for Arduino so we are a bit surprised it doesn't work. There doesn't seem to be enough diagnostics to determine why not. Any ideas about what we might be missing? Any way to change the TIMEOUT?

Can you suggest a way for us to verify our I2C communications besides uint8_t error = vl53l5cx_is_alive(&Dev, &isAlive); which we successfully negotiate?

We have tried this at 100kHz and 400 kHz I2C bus speeds on multiple platforms with the same result. We have used a similar multiByte read function to successfully talk with dozens of I2C sensors including the VL6180X, VL53L0, and VL53L1. Not sure what we could be missing...Thanks for any suggestions you might offer.

This topic has been closed for replies.
Best answer by KWine

Just for completeness, we have this working with the Arduino IDE using this library now. We had to modify the usual multiple byte read/write functions to handle large variable byte sizes. Probably more than one way to manage this but what is in the repo works.

3 replies

John E KVAM
ST Employee
August 18, 2021

I'm going to bet that the Arduino has a limit to their multi-byte write.

The chip has no program in it when it boots. It's simply running a bootloader.

The Init function downloads some 80K of program.

So 'size' in the code is huge.

And the Arduinto might be limited to 128 or 256 bytes.

You might have to break the multi-byte write into chunks of 100 bytes or so.

  • john
KWine
KWineAuthor
Senior
August 18, 2021

Thanks for the answer John. I did try to increase the buffer to 1024 bytes but the program hung; at least I didn't get an error!.

At 256 bytes I see the same behavior as with the 32 and 64 byte buffer sizes described above

I will try breaking the multi-read and write functions into smaller byte chunks...

KWine
KWineAuthorBest answer
Senior
August 20, 2021

Just for completeness, we have this working with the Arduino IDE using this library now. We had to modify the usual multiple byte read/write functions to handle large variable byte sizes. Probably more than one way to manage this but what is in the repo works.