cancel
Showing results for 
Search instead for 
Did you mean: 

Integrating TOF and SPD with VL53L8CX - second try

BrianWhite
Associate II

(I deleted the content by accident) 

I'm working on a project that uses Smart Presence Detection to control a LED strip using the X-NUCLEO-53L8A1 board. I started a blank project in STM32CubeIDE and included the X-CUBE-TOF1 bundle. I have added several other features to control the LEDs (SPI, DMA, timers, etc). I am able to get ranging data from the ToF sensor.

I would like to add the Smart Presence Detection from STSW-IMG048 but I'm having a great deal of difficulty integrating the SPD code with the existing code that talks to the VL53L8. It seems that the SPD code makes extensive use of function calls to control the sensor using the VL53LMZ_ULD_API but these calls do not work in the context of my existing project - perhaps it some incompatibility in the GPIO or I2C setup but I cannot be sure. I would prefer to be able to use calls to the sensor-control functions in the X-CUBE-TOF1 package to satisfy the requirements of the SPD but it does not look possible - the TOF1 functions do not seem to have the access to low-level sensor parameters that the SPD needs to change.

Alternatively, I could try to add my LED code onto the code in IMG048 but that will be very difficult as the IMG048 lacks an .ioc file.

Has anyone had success in integrating the SPD library into an existing project? How did you do it?
Thank you for your time.
Brian

4 REPLIES 4
TDK
Guru

 

> It seems that the SPD code makes extensive use of function calls to control the sensor using the VL53LMZ_ULD_API but these calls do not work in the context of my existing project

What makes you think it doesn't work in the context of your existing project? What error messages are you getting?

It's better to post specifics. Most code can work alongside each other, especially if they're independent pieces.

 

(For next time, you can edit your post here rather than reposting.)

TDK_0-1737824966991.png

 

If you feel a post has answered your question, please click "Accept as Solution".
John E KVAM
ST Employee

Brian -

You are correct. In that the X-ToF code is a bit different from the API delivered on ST.com. 
The X-TOF code supports all the TOF sensors and so it’s abstracted quit a bit.  And that’s why you have an array of function pointers. 
one way to do this is take your project and delete the X-TOF files. Then replace them with the files from the API. 
Another way to do it is build your project and don’t include the X-TOF files. Then compare your project to the examples in the API. That’s what I would do. 


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.

TDK

Thanks for the quick reply and for the editing tip.

Here's a more specific description:

I took my working LED code and stripped out all the TOF-related code from X-CUBE-TOF1 and then, bit by bit, tried building up the SPD code.

I began by adding the VL53LMZ_ULD_API folder to the project as well as the platform.c and .h files to the Core/ folder.

I then started adding function by function using main.c from the SPDKit's code as a reference. I also copied in the I2C pin definitions and MX_I2C1_Init() from SPDKit's main.c

It fails at the first real function call in main.c:

    status = init_vl53lmz_sensor();

digging in, it is failing here in main.c at the call to vl53lmz_init()

int init_vl53lmz_sensor(){
	int status = 0;
	VL53LMZ_ModuleInfo module_info;
	VL53LMZ_FWVersion fw_version;

	// Ideally do a HW reset of the sensor by toggling AVDD & IOVDD
	Reset_Sensor(&(LMZDev.platform));		/* Platform function, not in API */

	// Finally init sensor (SW reset sequence + sensor boot)
	status = vl53lmz_init(&LMZDev);
	if (status != VL53LMZ_STATUS_OK){
		printf("vl53lmz_init failed : %d\n",status);
		return status;
	}

 looking further, it fails at the first attempt to write to the sensor (in vl53lmz_api.c's vl53lmz_is_alive():

status |= WrByte(&(p_dev->platform), 0x7fff, 0x00);

I'm not 100&% positive, but it looks like WrByte is failing with a timeout error. This makes me think that the GPIO pins may not be set up properly but I'm not sure where to look to see what to fix.

the printout is:

LED Strip and Sprites Initialized
tried to write and read bytes status = 1
vl53lmz_init failed : 1
init_vl53lmz_sensor failed : 1

I've attached my main.c since it contains most of the initialization code as well as vl53lmz_api.c just in case it helps. I added some print statements for debugging.

I appreciate any suggestions you may have. Thank you very much for your time.

All the best

Brian

 

John

Thanks - I think your suggestion to start without any X-CUbe-TOF1 and then add the SPD is the best. I will give that a try.

thanks again

Brian