2025-06-03 2:31 PM
The most viewed and commented post on the Imaging page had to do with an Init failure on the multizone part.
These parts have large I2C writes at the beginning, which is downloading the Firmware (on the L5 and L7) and downloading patch updates on the L8.
The solution was:
uint8_t WrMulti(VL53L8CX_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_values, uint32_t size) {
uint8_t status = HAL_OK; // Initialize status as HAL_OK
uint32_t remaining_size = size; // Calculate remaining size to write
uint16_t current_address = RegisterAddress; // Initialize current address
// Loop until all data is written
while (remaining_size > 0) {
// Calculate the current chunk size to write
uint32_t current_chunk_size = (remaining_size > chunk_size) ? chunk_size : remaining_size;
// Perform write operation for current chunk
status = HAL_I2C_Mem_Write(&hi2c2, addr, current_address, I2C_MEMADD_SIZE_16BIT, p_values, current_chunk_size, 100);
// Check for error
if (status != HAL_OK) {
APP_LOG(TS_ON, 3, "[WrMulti] error. status %d, regADDR %d, size %d, remaining_size %d\n", status, current_address, size, remaining_size);
return status; // Return error status
}
// Update remaining size and pointer to move to the next chunk
remaining_size -= current_chunk_size;
current_address += current_chunk_size; // Increment register address for next chunk
p_values += current_chunk_size;
HAL_Delay(10);
}
return status; // Return status (HAL_OK if all writes were successful)
}
Notice how he used the HAL command to write 16-bit addr and had to manually recalculate the current address before each loop.
chunk_size was defined as:
#define chunk_size (1<<8)
The same has to be done for RdMulti. as it tries to read 420 bytes at once at some point.
Do not try to read the registers after downloading firmware, to check if they match with the firmware, you just downloaded it. It will make init fail. And of course he used the default firmware download code.