cancel
Showing results for 
Search instead for 
Did you mean: 

How do I verify I have my I2C configured correctly for the VL53L5CX?

John E KVAM
ST Employee
 

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.
1 ACCEPTED SOLUTION

Accepted Solutions
John E KVAM
ST Employee

Here is a function. Put it at the top of your program. When it runs correctly, you can remove it secure that your I2C is not byte or word swapped.

/* --------------------------------------------------
 * --- This function can be used to test VL53L5CX I2C 
 * --------------------------------------------------
 */
 
uint8_t vl53l5cx_test_i2c(VL53L5CX_Configuration *p_dev){
	uint8_t status = VL53L5CX_STATUS_OK;
	printf("Starting VL53L5CX I2C test...\n");
 
/* To check the I2C RdByte/WrByte function :
 * Inside the function “vl53l5cx_is_alive()�?, it will call I2C RdByte/WrByte to
 * read device and verion ID. which can help you to verify the I2C RdByte/WrByte
 * functions at same time.
 */
	uint8_t device_id, revision_id;
	status |= WrByte(&(p_dev->platform), 0x7fff, 0x00);
	status |= RdByte(&(p_dev->platform), 0, &device_id);
	status |= RdByte(&(p_dev->platform), 1, &revision_id);
	status |= WrByte(&(p_dev->platform), 0x7fff, 0x02);
 
	if(status)
	{
		printf("Error Rd/Wr byte: status %u\n", status);
		return status;
	}
 
/* To check the I2C RdMulti/WrMulti function:
 * Below is example codes which can help you vefify the I2C RdMulti/WrMulti
 * function.
 */
 
	uint8_t Data_write[4]={0x5A,0xA5,0xAA,0x55};
	uint8_t Data_read[4]={0,0,0,0};
	uint8_t Data_default[4]={0,0,0,0};
 
	status |= RdMulti(&(p_dev->platform), 0x100, Data_default, 4);
	if(status)
	{
		printf("Error RdMulti: status %u\n", status);
		return status;
	}
 
	printf("Read default value and save it at begging\n");
	printf("Data_default (0x%x)\n", Data_default[0]);
	printf("Data_default (0x%x)\n", Data_default[1]);
	printf("Data_default (0x%x)\n", Data_default[2]);
	printf("Data_default (0x%x)\n", Data_default[3]);
 
	status |= WrMulti(&(Dev.platform), 0x100, Data_write, 4);
	if(status)
	{
		printf("Error WrMulti: status %u\n", status);
		return status;
	}
	printf("Writing values 0x5A 0xA5 0xAA 0x55\n");
 
	status |= RdMulti(&(p_dev->platform), 0x100, Data_read, 4);
	if(status)
	{
		printf("Error RdMulti: status %u\n", status);
		return status;
	}
 
	printf("Reading:\n");
	printf("Data_read (0x%x)\n", Data_read[0]);
	printf("Data_read (0x%x)\n", Data_read[1]);
	printf("Data_read (0x%x)\n", Data_read[2]);
	printf("Data_read (0x%x)\n", Data_read[3]);
 
 
	status |= WrMulti(&(Dev.platform), 0x100, Data_default, 4);
	printf("Write back default value\n");
	if(status)
	{
		printf("Error WrMulti: status %u\n", status);
		return status;
	}
 
	status |= RdMulti(&(Dev.platform), 0x100, Data_default, 4);
	if(status)
	{
		printf("Error RdMulti: status %u\n", status);
		return status;
	}
 
	printf("Read value again to make sure default value was correct loaded\n");
	printf("Data_default (0x%x)\n", Data_default[0]);
	printf("Data_default (0x%x)\n", Data_default[1]);
	printf("Data_default (0x%x)\n", Data_default[2]);
	printf("Data_default (0x%x)\n", Data_default[3]);
 
	printf("I2C test done - everything works fine.\n");
 
	return status;
}


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.

View solution in original post

1 REPLY 1
John E KVAM
ST Employee

Here is a function. Put it at the top of your program. When it runs correctly, you can remove it secure that your I2C is not byte or word swapped.

/* --------------------------------------------------
 * --- This function can be used to test VL53L5CX I2C 
 * --------------------------------------------------
 */
 
uint8_t vl53l5cx_test_i2c(VL53L5CX_Configuration *p_dev){
	uint8_t status = VL53L5CX_STATUS_OK;
	printf("Starting VL53L5CX I2C test...\n");
 
/* To check the I2C RdByte/WrByte function :
 * Inside the function “vl53l5cx_is_alive()�?, it will call I2C RdByte/WrByte to
 * read device and verion ID. which can help you to verify the I2C RdByte/WrByte
 * functions at same time.
 */
	uint8_t device_id, revision_id;
	status |= WrByte(&(p_dev->platform), 0x7fff, 0x00);
	status |= RdByte(&(p_dev->platform), 0, &device_id);
	status |= RdByte(&(p_dev->platform), 1, &revision_id);
	status |= WrByte(&(p_dev->platform), 0x7fff, 0x02);
 
	if(status)
	{
		printf("Error Rd/Wr byte: status %u\n", status);
		return status;
	}
 
/* To check the I2C RdMulti/WrMulti function:
 * Below is example codes which can help you vefify the I2C RdMulti/WrMulti
 * function.
 */
 
	uint8_t Data_write[4]={0x5A,0xA5,0xAA,0x55};
	uint8_t Data_read[4]={0,0,0,0};
	uint8_t Data_default[4]={0,0,0,0};
 
	status |= RdMulti(&(p_dev->platform), 0x100, Data_default, 4);
	if(status)
	{
		printf("Error RdMulti: status %u\n", status);
		return status;
	}
 
	printf("Read default value and save it at begging\n");
	printf("Data_default (0x%x)\n", Data_default[0]);
	printf("Data_default (0x%x)\n", Data_default[1]);
	printf("Data_default (0x%x)\n", Data_default[2]);
	printf("Data_default (0x%x)\n", Data_default[3]);
 
	status |= WrMulti(&(Dev.platform), 0x100, Data_write, 4);
	if(status)
	{
		printf("Error WrMulti: status %u\n", status);
		return status;
	}
	printf("Writing values 0x5A 0xA5 0xAA 0x55\n");
 
	status |= RdMulti(&(p_dev->platform), 0x100, Data_read, 4);
	if(status)
	{
		printf("Error RdMulti: status %u\n", status);
		return status;
	}
 
	printf("Reading:\n");
	printf("Data_read (0x%x)\n", Data_read[0]);
	printf("Data_read (0x%x)\n", Data_read[1]);
	printf("Data_read (0x%x)\n", Data_read[2]);
	printf("Data_read (0x%x)\n", Data_read[3]);
 
 
	status |= WrMulti(&(Dev.platform), 0x100, Data_default, 4);
	printf("Write back default value\n");
	if(status)
	{
		printf("Error WrMulti: status %u\n", status);
		return status;
	}
 
	status |= RdMulti(&(Dev.platform), 0x100, Data_default, 4);
	if(status)
	{
		printf("Error RdMulti: status %u\n", status);
		return status;
	}
 
	printf("Read value again to make sure default value was correct loaded\n");
	printf("Data_default (0x%x)\n", Data_default[0]);
	printf("Data_default (0x%x)\n", Data_default[1]);
	printf("Data_default (0x%x)\n", Data_default[2]);
	printf("Data_default (0x%x)\n", Data_default[3]);
 
	printf("I2C test done - everything works fine.\n");
 
	return status;
}


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.