Skip to main content
Wasabinary
Associate
February 7, 2023
Question

VL53L5CX initialization fails with ULD driver v1.3.6

  • February 7, 2023
  • 4 replies
  • 3860 views

I tried using VL53L5CX with ULD API v1.3.6 with an ESP32-S3. I successfully ported the base C function for I2C, as I can talk with the sensor during the first part of the initialization process.

Unfortunately, when I reach the NVM part, the function _vl53l5cx_poll_for_answer() fails, and I keep getting VL53L5CX_MCU_ERROR as the return value:

0693W00000YA8JvQAL.png 

I was looking for answers online, especially around ST Community, but I cannot find anything about this specific part of the function failing. As I haven't modified the API itself, I really need some external help to resolve this issue.

Does anyone know how to revolve this ?

This topic has been closed for replies.

4 replies

Julien NGUYEN
ST Employee
February 7, 2023

Hello,

Have you tried the VL53L5CX Arduino library on your ESP32 ?

https://www.arduinolibraries.info/libraries/stm32duino-vl53-l5-cx

Julien

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
Wasabinary
Associate
February 7, 2023

Hi, thank you for your answer. No I haven't try this library, I wanted to use the official ESP32 framwork ESP-IDF, but I will look into the library examples to this if I do anything wrong in the power up sequence, just in case.

Wasabinary
Associate
February 9, 2023

I actually found the issue: the WrMulti function was sending adress bytes in the wrong order. It was actually the previous call to WrMulti(&(p_dev->platform), 0x2fd8, (uint8_t*)VL53L5CX_GET_NVM_CMD, sizeof(VL53L5CX_GET_NVM_CMD)); that failed because the 0x2fd8 adress was sent as 0xd82f. My bad, I implemented the function wrongly.

WParr.1
Visitor II
January 25, 2024

Is this for the Linux VL53L5CX ULD?

Is this function still correct?

 

int32_t write_read_multi(
		int fd,
		uint16_t i2c_address,
		uint16_t reg_address,
		uint8_t *pdata,
		uint32_t count,
		int write_not_read)
{

#ifdef STMVL53L5CX_KERNEL
	struct comms_struct cs;

	cs.len = count;
	cs.reg_address = reg_address;
	cs.buf = pdata;
	cs.write_not_read = write_not_read;

	if (ioctl(fd, ST_TOF_IOCTL_TRANSFER, &cs) < 0)
		return VL53L5CX_COMMS_ERROR;
#else

	struct i2c_rdwr_ioctl_data packets;
	struct i2c_msg messages[2];

	uint32_t data_size = 0;
	uint32_t position = 0;

	if (write_not_read) {
		do {
			data_size = (count - position) > (VL53L5CX_COMMS_CHUNK_SIZE-2) ? (VL53L5CX_COMMS_CHUNK_SIZE-2) : (count - position);

			memcpy(&i2c_buffer[2], &pdata[position], data_size);

			i2c_buffer[0] = (reg_address + position) >> 8;
			i2c_buffer[1] = (reg_address + position) & 0xFF;

			messages[0].addr = i2c_address >> 1;
			messages[0].flags = 0; //I2C_M_WR;
			messages[0].len = data_size + 2;
			messages[0].buf = i2c_buffer;

			packets.msgs = messages;
			packets.nmsgs = 1;

			if (ioctl(fd, I2C_RDWR, &packets) < 0)
				return VL53L5CX_COMMS_ERROR;
			position += data_size;

		} while (position < count);
	}

	else {
		do {
			data_size = (count - position) > VL53L5CX_COMMS_CHUNK_SIZE ? VL53L5CX_COMMS_CHUNK_SIZE : (count - position);

			i2c_buffer[0] = (reg_address + position) >> 8;
			i2c_buffer[1] = (reg_address + position) & 0xFF;

			messages[0].addr = i2c_address >> 1;
			messages[0].flags = 0; //I2C_M_WR;
			messages[0].len = 2;
			messages[0].buf = i2c_buffer;

			messages[1].addr = i2c_address >> 1;
			messages[1].flags = I2C_M_RD;
			messages[1].len = data_size;
			messages[1].buf = pdata + position;

			packets.msgs = messages;
			packets.nmsgs = 2;

//			int ret = ioctl(fd, I2C_RDWR, &packets);
//			if (ret < 0){		//throws error here
//				return VL53L5CX_COMMS_ERROR;
//			}
			if (ioctl(fd, I2C_RDWR, &packets) < 0)
				return VL53L5CX_COMMS_ERROR;

			position += data_size;

		} while (position < count);
	}
#endif
	return 0;
}

 

I am having iniitialisation issues here status throwing -1 thrown by the above ioctl during the read:

 

	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);

	status |= RdMulti(&(p_dev->platform), VL53L5CX_UI_CMD_START, p_dev->temp_buffer, VL53L5CX_NVM_DATA_SIZE); //ErrorHere

	(void)memcpy(p_dev->offset_data, p_dev->temp_buffer, VL53L5CX_OFFSET_BUFFER_SIZE);

	status |= _vl53l5cx_send_offset_data(p_dev, VL53L5CX_RESOLUTION_4X4);

 

Julien NGUYEN
ST Employee
February 9, 2023

Thanks for the update. Simple I2C read write function checks at the first step are helpful ;)

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.