cancel
Showing results for 
Search instead for 
Did you mean: 

SPAD Initialization error?

Chris Seto
Associate
Posted on January 23, 2017 at 18:28

I implemented the VL53L0X API in my embedded project. while the call to DataInit works fine (or, at least returns a status OK), I am getting a VL53L0X_ERROR_REF_SPAD_INIT from StaticInit.

Any ideas what this means? Also, is there some way that I can simply verify that I2C communication to the device is working? Maybe some registers that have known values on startup? I saw the examples in the datasheet, but I'd like a larger block so I could test 32bit, 16bit and 8bit reads and writes. The examples are only detailed enough to cover an 8 and 16 bit write.

Thanks,

Chris

7 REPLIES 7
Nicola Ferrini
Associate
Posted on February 21, 2017 at 14:32

Hi,

 me too I have the same problem ! Have you found out what the problem was? Could you give me some advice?

Thanks

Théo HYVON
Associate
Posted on June 13, 2017 at 10:28

Hi, I'm facing the same issue, I tracked the error to the enable_ref_spads() function. The comparison between the written and read map is throwing a VL53L0X_ERROR_REF_SPAD_INIT error. It seems like the write operation of the SPAD map isn't taken into account by the sensor even if the I²C dialog is working fine...

Any ideas ?

Thanks !
Théo HYVON
Associate
Posted on June 15, 2017 at 11:40

Hello ! I found the solution to my problem. It simply came from a bad implementation of the platform VL53L0X_WriteMulti(...). I was issuing a new start condition after writing the index... Now everything is working !

Hope it could help you if you're facing this kind of issue !
fgfg
Associate

Hey there,

I have also same problem.

Can you help me to figure out?

Here is my code,,

int32_t VL53L0X_write_multi(uint8_t address, uint8_t index, uint8_t  *pdata, int32_t count)
{
	if (HAL_I2C_Mem_Write(&hi2c1, address, index, 1, pdata, count, 100) == HAL_OK)
		return 0;
	else
		return 1;
}
 
 
int32_t VL53L0X_read_multi(uint8_t address,  uint8_t index, uint8_t  *pdata, int32_t count)
{
	if (HAL_I2C_Mem_Read(&hi2c1, address, index, 1, pdata, count, 100) == HAL_OK)
		return 0;
	else
		return 1;
}

Hi, your VL53L0X_read_multi is wrong. Take a look on datasheet:0690X0000089wL2QAI.png

You should send an address WRITE followed by command (index) and stop P transmission. Then start S transmission reading the data.

I've got something like this:

VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count)
{
    return i2c_read(Dev->fd, index, pdata, count);
}
 
static int i2c_read(int fd, uint8_t cmd, uint8_t * data, uint8_t len){
	HAL_StatusTypeDef x=0;
	//__disable_irq();
    if ((x=HAL_I2C_Master_Transmit(&hi2c1, VL53L0X_addr, &cmd, 1, 100)) != HAL_OK)
    {
        return VL53L0X_ERROR_CONTROL_INTERFACE;//-x;
    }
 
    if ((x=HAL_I2C_Master_Receive(&hi2c1, VL53L0X_addr, data, len, 100)) != HAL_OK) {
        return VL53L0X_ERROR_CONTROL_INTERFACE;//+x;
    }
    //__enable_irq();
    return VL53L0X_ERROR_NONE;
}

Nevertheless I have the same problem with VL53L0X "error to the enable_ref_spads() function". I still didn't find a solution to this problem.

Before I used the same piece of VL53 by ARDUINO and it runs smoothly w/o any problems. So I know the hardware is OK. Any idea what can be wrong?

John E KVAM
ST Employee

Here is an app note that might help. Take the code from the doc and insert it to the top of your main. It will test the endian-ness of your implementation.


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.
ms1802
Associate II

Below is a working version.

It passes the above verification code ftom ST and I get measurement data from the sensor!

(original code it taken from the net - lost the reference to the original author - sorry!)

But, there was a bug in the original version wrt to the VL53L0X_write_multi - it did not work!

Theo's note - put me onto the right track.

Cheers

Mark

#include "stm32f4xx_hal.h"
#include "vl53l0x_def.h"
#include "vl53l0x_i2c_platform.h"
#include "string.h"
 
extern I2C_HandleTypeDef hi2c1;
 
 
int VL53L0X_i2c_init(void)
{
    return VL53L0X_ERROR_NONE;
}
 
int VL53L0X_write_multi(uint8_t deviceAddress, uint8_t index, uint8_t *pdata, uint32_t count)
{
    static uint8_t data[32];
 
    if (count >=(sizeof (data)-1) )
    {
        return  VL53L0X_ERROR_UNDEFINED;
    }
   
    data[0] = index;
    memcpy(data+1,pdata,count);
 
    HAL_StatusTypeDef status= HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)deviceAddress << 1, data, count+1, 1000);  
    return status == HAL_OK ? VL53L0X_ERROR_NONE : VL53L0X_ERROR_UNDEFINED;
}
 
int VL53L0X_read_multi(uint8_t deviceAddress, uint8_t index, uint8_t *pdata, uint32_t count)
{
    HAL_StatusTypeDef status= HAL_I2C_Mem_Read(&hi2c1, (uint16_t)deviceAddress << 1, index, 1, pdata, count, 1000);
    return status == HAL_OK ? VL53L0X_ERROR_NONE : VL53L0X_ERROR_UNDEFINED;
}
 
int VL53L0X_write_byte(uint8_t deviceAddress, uint8_t index, uint8_t data)
{
    uint8_t buff[2];
    buff[0] = index;
    buff[1] = data;
 
    HAL_StatusTypeDef status = HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)deviceAddress << 1, buff, 2, 1000);
    return status == HAL_OK ? VL53L0X_ERROR_NONE : VL53L0X_ERROR_UNDEFINED;
 
}
 
int VL53L0X_write_word(uint8_t deviceAddress, uint8_t index, uint16_t data)
{
    uint8_t buff[3];
    buff[2] = data & 0xFF;
    buff[1] = data >> 8;
    buff[0] = index;
 
    HAL_StatusTypeDef status = HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)deviceAddress << 1, buff, 3, 1000);
    return status == HAL_OK ? VL53L0X_ERROR_NONE : VL53L0X_ERROR_UNDEFINED;
 
}
 
int VL53L0X_write_dword(uint8_t deviceAddress, uint8_t index, uint32_t data)
{
    uint8_t buff[5];
 
    buff[4] = data & 0xFF;
    buff[3] = data >> 8;
    buff[2] = data >> 16;
    buff[1] = data >> 24;
    buff[0] = index;
    HAL_StatusTypeDef status = HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)deviceAddress << 1, buff, 5, 1000);
    return status == HAL_OK ? VL53L0X_ERROR_NONE : VL53L0X_ERROR_UNDEFINED;
 
}
 
int VL53L0X_read_byte(uint8_t deviceAddress, uint8_t index, uint8_t *data)
{
   HAL_StatusTypeDef status = HAL_I2C_Mem_Read(&hi2c1, (uint16_t)deviceAddress << 1, index, 1, data, 1, 1000);
   return status == HAL_OK ? VL53L0X_ERROR_NONE : VL53L0X_ERROR_UNDEFINED;
 
}
 
int VL53L0X_read_word(uint8_t deviceAddress, uint8_t index, uint16_t *data)
{
    uint8_t buff[2];
    int r = VL53L0X_read_multi(deviceAddress, index, buff, 2);
 
    uint16_t tmp;
    tmp = buff[0];
    tmp <<= 8;
    tmp |= buff[1];
    *data = tmp;
 
    return r;
}
 
int VL53L0X_read_dword(uint8_t deviceAddress, uint8_t index, uint32_t *data)
{
    uint8_t buff[4];
    int r = VL53L0X_read_multi(deviceAddress, index, buff, 4);
 
    uint32_t tmp;
    tmp = buff[0];
    tmp <<= 8;
    tmp |= buff[1];
    tmp <<= 8;
    tmp |= buff[2];
    tmp <<= 8;
    tmp |= buff[3];
 
    *data = tmp;
 
    return r;
}