cancel
Showing results for 
Search instead for 
Did you mean: 

VL53L5CX driver vl53l5cx_init() fails

Peter111
Associate II

The Ultra Light Driver (STSW-IMG023) init function vl53l5cx_init() fails in this section :

/* Get offset NVM data and store them into the offset buffer */
 
	status |= WrMulti(&(p_dev->platform), 0x2fd8,
 
		(uint8_t*)VL53L5CX_GET_NVM_CMD, sizeof(VL53L5CX_GET_NVM_CMD));
 
	status |= _vl53l5cx_poll_for_answer(p_dev, 4, 0,
 
		VL53L5CX_UI_CMD_STATUS, 0xff, 2);

The sensor does not answer with '2' as expected by _vl53l5cx_poll_for_answer. (The senosr answers '0')

This results in a failed initialization.

How can this be fixed?

51 REPLIES 51

I'm really sorry that took so long. I think you should be able to mark your solution as 'solution'. That way people can skip the zillion intermediate steps. Thanks for sticking with it.


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

somebody help the below i have write the rdmulti and

def wr_multi(self, addr: int, buffer: List[int], size: int) -> None:
        try:
            chunk_size = 32  # Set this to your hardware's max message size
            remaining_size = size
            current_address = addr
            position = 0
            while remaining_size > 0:
                current_chunk_size = chunk_size if remaining_size > chunk_size else remaining_size
                reg_bytes = [(current_address >> 8) & 0xFF, current_address & 0xFF]
                chunk = buffer[position:position + current_chunk_size]
                data = bytearray(reg_bytes + chunk)
                DSYS_Write(data, slave=self.i2c_address)
                if DEBUG_IO:
                    print(f"wr_multi addr=0x{current_address:04X}, chunk_size={current_chunk_size}, data={list(data)}")
                remaining_size -= current_chunk_size
                current_address += current_chunk_size
                position += current_chunk_size
                time.sleep(0.01)  # HAL_Delay(10) in ms
        except Exception as e:
            print(f"Error writing register 0x{addr:04X}: {e}")

    def rd_byte(self, addr: int) -> int:
            try:
                reg_bytes = [(addr >> 8) & 0xFF, addr & 0xFF]
                data = DSYS_Read(1, bytearray(reg_bytes), slave=self.i2c_address, delay_before_read=1)
                if data is not None and len(data) > 0:
                    b = data[0]
                    if DEBUG_IO:
                        print(f"rd_byte addr=0x{addr:04X}, byte=0x{b:02X}")
                    return b
                else:
                    raise Exception("Couldn't read any bytes")
            except Exception as e:
                print(f"Error reading register 0x{addr:04X}: {e}")
                return None

    def wr_byte(self, addr: int, value: int) -> None:
            try:
                reg_bytes = [(addr >> 8) & 0xFF, addr & 0xFF]
                data = bytearray(reg_bytes + [value])
                DSYS_Write(data, slave=self.i2c_address)
                if DEBUG_IO:
                    print(f"wr_byte addr=0x{addr:04X}, byte=0x{value:02X}")
            except Exception as e:
                print(f"Error writing register 0x{addr:04X}: {e}")
def rd_multi(self, addr: int, buffer: List[int], size: int) -> None:
            try:
                # Split 16-bit register into two bytes (big-endian: high, low)
                reg_bytes = [(addr >> 8) & 0xFF, addr & 0xFF]
                data = DSYS_Read(size, bytearray(reg_bytes), slave=self.i2c_address, delay_before_read=1)
                if data is not None:
                    buffer[:len(data)] = list(data)
                    if DEBUG_IO:
                        print(f"rd_multi addr=0x{addr:04X}, size={size}, read_size={len(data)}, buf_len= read=[", end="")
                        print_size = len(data)
                        if print_size > PRINT_SIZE_MAX:
                            print_size = PRINT_SIZE_MAX
                        for i in range(print_size):
                            if i > 0:
                                print(", ", end="")
                            print(f"{data[i]:#02x}", end="")
                        if print_size != len(data):
                            print(", ...", end="")
                        print("]")
                else:
                    raise Exception("Couldn't read any bytes")
            except Exception as e:
                print(f"Error reading register 0x{addr:04X}: {e}")
                raise