cancel
Showing results for 
Search instead for 
Did you mean: 

VL53L1X problem with write value to register

toman
Associate II

Hello, I solve a problem with writing the value to the register of sensor VL53L1X. It is the main purpose, why the sensor doesn´t read distance because the init state is invalid.

For example, I tried to write the value 0x2 to the register 0x30 on the Arduino board and then on the BluePill board with chip STM32f103C8T6. On the Arduino, it worked, but on the STM didnť work.

I´m adding PrintScreens from the oscilloscope with the same message in Arduino and in STM for comparison. The messages are different in length and count of peaks. It looks like, then STM has an incorrect SCL.

0693W00000Y7UChQAN.png0693W00000Y7UFzQAN.png I´m also adding the STM code using vl53l1_platform.c

// STM write and read byte 
 status += VL53L1_WrByte(dev, 0x30, 0x2);
 status += VL53L1_RdByte(dev, 0x30, &byteData);
 
 
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data) {
		 StatusErr = 0;
	     int32_t status_int;
 
	    _I2CBuffer[0] = (uint8_t)(index >> 8);
	    _I2CBuffer[1] = (uint8_t)(index & 0xFF);
	    _I2CBuffer[2] = (uint8_t)data;
 
 
	    status_int = _I2CWrite(dev, _I2CBuffer, 3);
 
	    if (status_int != 0) {
	        //comm error 
	    	//return 255;
	    	StatusErr = 13;
	    }
 
	    return StatusErr;
 
}
 
int _I2CWrite(uint16_t Dev, uint8_t *pdata, uint32_t count) {
    int status;
    int i2c_time_out = I2C_TIME_OUT_BASE+ count* I2C_TIME_OUT_BYTE;
 
    status = HAL_I2C_Master_Transmit(&hi2c2,(Dev<<1),pdata, count, 1000); //(Dev<<1)
 
    // if status 1 - error 
    if (status) {
        return 255;
    }
    // if Ok return 0 
    return status;
}

Please, has anyone dealt with the same problem?

1 ACCEPTED SOLUTION

Accepted Solutions
toman
Associate II

The problem with writing values ​​to the sensor registers was caused by a bad BluePill board. The fourth byte of the message was never sent (you can see it at the PrintScreens from the oscilloscope), the clock always dropped after the three byte.

When replacing the board and using the same I2C bus settings, everything worked. 

Beware of non-original boards from Aliexpress, they may contain this error.

View solution in original post

4 REPLIES 4
John E KVAM
ST Employee

If you are using the ST platform.c code then we can assume that is not the problem. And if you have proved that the register is write-able on your other board, then that's not the issue.

So that leaves configuration of the I2C bus itself. Or really long wires.

Unfortunately that code returns 255 for all I2C errors. One might put a break in and see what error the I2C was throwing.

But I'm betting the I2C is mis-configured.

  • john

If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
toman
Associate II

@John E KVAM​ thanks for you answer. The I2C mis-configured is possible. I´m adding the actual configuration.

0693W00000Y7egCQAR.pngReally long wires are not the cause of this problem. I use the same wires for testing on the Arduino board and it works.

Tomas

John E KVAM
ST Employee

In your code, add some prints to indicate why the I2C failed.

you need to know why the function like   status_int = _I2CWrite(dev, _I2CBuffer, 3);

Failed. What is status_int?

I'm also going to include some code. Put it at the top of your stuff and get it to run. it will verify the I2C is working correctly


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
toman
Associate II

The problem with writing values ​​to the sensor registers was caused by a bad BluePill board. The fourth byte of the message was never sent (you can see it at the PrintScreens from the oscilloscope), the clock always dropped after the three byte.

When replacing the board and using the same I2C bus settings, everything worked. 

Beware of non-original boards from Aliexpress, they may contain this error.