cancel
Showing results for 
Search instead for 
Did you mean: 

Modifying the API of the VL53L0X for use with other uCs

mchatouri9
Associate
Posted on September 21, 2016 at 16:19

Hello,

I have some questions to the developers of the API of the VL53L0X (Help from fellow users of this sensor is also highly appreciated). In the next paragraph you find the text which I already shared with customer technical support, from which I got no answer. Finally they appointed me to this forum. My request:

In order to use the above mentioned sensor and get the best results out of it I am intending to use the delivered API instead of having to deal with all numerous registers of the sensor. This proposal is made open your recommendation to use the API (and since there is no real ma of the registers).

My only problem is to adapt (modify) the API to match the microcontroller I want to use, namely the Amel ARM Cortex-M7.

In my opinion the most important part to modify is the I2C communication interface.

My question is:

- I would like to have some headlines from your software developers. I would like to know what are the important spots of the software which have be modified in order to get the API working without having to rewrite the API and having to deal with the sensor at the lowest register level. The API should be adjustable for all platforms, at least it is written so on your website.

I'd be very pleased if you would answer quickly.

Thanks in advance

#cortex-m #vl53l0x #atmel-studio
6 REPLIES 6
harald
Associate III
Posted on October 05, 2016 at 14:26

Hy Manuel,

I just went through porting the software to my target hardware (TI ARM). It was pretty straightforward: I just needed to adjust the vl53l0x_platform.c and vl53l0x_platform.h to my system.

Actually, there is one pitfall: Apparently there are two different philosopies about I2C addresses: The 7 bit address appears in the control word on bit 7..1, so in the control word the address is shifted one bit left. ST.com names the I2C address as it appears on the bus (0x52), my I2C interface expects the real I2C address (0x29).

Anything else works just fine.

Best regards

Harald

Posted on February 17, 2017 at 10:25

From Soren Karlsen:

Hi Harald, I'm sitting with the same problem about adapting platform code for VL53L0X as you answered in this thread:

https://community.st.com/0D50X00009XkdtPSAR

When you say you just needed to adjust the files to your system, what did you actually do, and is it possible that you can show me and example?

Best regards

Søren

Posted on February 17, 2017 at 10:52

Hy Soren,

during the development I had a working

http://www.st.com/content/st_com/en/products/ecosystems/stm32-open-development-environment/stm32-nucleo-expansion-boards/stm32-ode-sense-hw/p-nucleo-53l0a1.html

, that helped a lot.

To port it into my own system (TI ARM, 3 x VL53L0X, discrete shut down pins) I first copied all files from vl53l0x folder into my project

vl53l0x

Release_Notes.html

VL53L0X_API_v1.0.0.4570_externalx.chm

VL53L0X_API_v1.0.0.4570_externalx.chw

vl53l0x_api.c

vl53l0x_api.h

vl53l0x_api_calibration.c

vl53l0x_api_calibration.h

vl53l0x_api_core.c

vl53l0x_api_core.h

vl53l0x_api_ranging.c

vl53l0x_api_ranging.h

vl53l0x_api_strings.c

vl53l0x_api_strings.h

vl53l0x_def.h

vl53l0x_device.h

vl53l0x_interrupt_threshold_settings.h

vl53l0x_platform.c

vl53l0x_platform.h

vl53l0x_platform_log.c

vl53l0x_platform_log.h

vl53l0x_tuning.h

vl53l0x_types.h

Then I needed to do adjust only the file 'vl53l0x_platform.c' and rewrite all functions in there to suit my own hardware. There is this one pitfall with the different interpretation of I2C addresses, but all the rest worked quite smoothly.

Then I tested and implemented step by step the functionality: Test shutdown pins, test read of the signature byte, test changing the I2C address, test start a measurement and the read the result. I ended up using two functions: startSingleMeas

VL53L0X_Error startSingleMeas(VL53L0X_DEV Dev)

{

    VL53L0X_Error Status = VL53L0X_ERROR_NONE;

    VL53L0X_DeviceModes DeviceMode;

    /* This function will do a complete single ranging

     * Here we fix the mode! */

    Status = VL53L0X_SetDeviceMode(Dev, VL53L0X_DEVICEMODE_SINGLE_RANGING);

    /* Get Current DeviceMode */

    if (Status == VL53L0X_ERROR_NONE)

        Status = VL53L0X_GetDeviceMode(Dev, &DeviceMode);

    /* Start immediately to run a single ranging measurement in case of

     * single ranging or single histogram */

    if (Status == VL53L0X_ERROR_NONE

        && DeviceMode == VL53L0X_DEVICEMODE_SINGLE_RANGING)

        Status = VL53L0X_StartMeasurement(Dev);

    return Status;

}

and pollAndReadMeasurement

/**

 * polls for data ready and reads data if ready

 * returns 0 if data was read, 100 if still busy and negative on error

 */

VL53L0X_Error pollAndReadMeasurement(VL53L0X_DEV Dev,

    VL53L0X_RangingMeasurementData_t *pRangingMeasurementData)

{

    VL53L0X_Error Status = VL53L0X_ERROR_NONE;

    if (Status == VL53L0X_ERROR_NONE)

    {

        uint8_t NewDataReady = 0;

        Status = VL53L0X_GetMeasurementDataReady(Dev, &NewDataReady);

        if ((Status == VL53L0X_ERROR_NONE) && (NewDataReady == 0))

        {

            Status = 100;   // still measuring

        }

    }

    if (Status == VL53L0X_ERROR_NONE)

    {

        // measurement done, read out values

        PALDevDataSet(Dev, PalState, VL53L0X_STATE_IDLE);

        Status = VL53L0X_GetRangingMeasurementData(Dev, pRangingMeasurementData);

        if (Status == VL53L0X_ERROR_NONE)

            Status = VL53L0X_ClearInterruptMask(Dev, 0);

    }

    return Status;

}

Maybe that helps...

Best regards

Harald

Posted on February 27, 2017 at 15:17

Well, my first attempts didn't work anyway (even though the code works, it takes too much space). But when you say that you 'adjust vl53l0x_platform.c and rewrite all functions in there to suit my own hardware' what do you actually do? what do you adjust?

Marek Frydrysiak
Associate
Posted on March 29, 2017 at 22:44

Hello guys. Let me ask you maybe a silly question but I just can't get my program even building with the VL53L0X API. I downloaded it from the ST website (v 1.0.2) and included all .h and .c files into the project workspace (from the 'Api' folder). I currently work with the Nucleo F103 board, using the Ac6 IDE. All I need is just to perform a single ranging measurement and perform a certain action depending on the results, I do not care about some fancy serial communication with any GUI app. While building I get an error that the <Windows.h> in vl53l0x.c library cannot be found... Well, even if I resolve this issue I get exponentially more errors than in the very beginning. Do I really need to somehow adjust this API to proceed through a simplest functionality? Is there any description how to do it? In my opinion I have checked everywhere, in sensor and api documentation...

Mark Shoe
Senior
Posted on October 14, 2017 at 18:35

HI Harald,

Your code 

startSingleMeas and 

pollAndReadMeasurement nearly works. Im starting and after some time the poll gets true. Now i printed the whole output structure:

TimeStamp 0

MeasurementTimeUsec 0

RangeMilliMeter 0

RangeDMaxMilliMeter 2048

SignalRateRtnMegaCps 33553920

AmbientRateRtnMegaCps 33553920

EffectiveSpadRtnCount 65535

RangeFractionalPart 0

ZoneId 0

RangeStatus 5

And rangeStatus has to be 0 to have a valid measurement. Any idea why this happens?