2025-01-26 10:23 AM - last edited on 2025-01-26 11:53 PM by SofLit
Hi everybody.
Please help me.
I bought a VL53L4ED sensor and would like to learn how to use it.
I have found a number of documents and driver examples, but have been unable to find a document describing the internal registers and their function. (programming manual) .
I must be looking for it wrong. Can you please direct me to the proper document?
Thank you very much.
Jaroslav
2025-01-27 07:54 AM
I just responded to someone with a similar complaint.
Please don't hate me.
But ST does not publish the register map. Instead we publish the API. It's
It contains simple C functions that enable everything the chip can do. Start there, read that.
There are lots of examples.
There are several reasons for not publishing the register map.
1) Too many registers. I'm sure you could write a driver given the register map, but you'd end up hating ST forever.
2) Some of the register settings would cause your application to not meet the specification in the Datasheet, and again you would hate us.
3) It would be too hard to support. We'd spend the rest of our days looking through code with one wrong register setting. And when we couldn't find the error - you'd end up hating us.
But honestly it took us years to write that code; and it works; and it's validated.
There is the firmware in the chip. So rather than a bunch of I2C registers you are actually using the I2C to communicate with firmware thinly vailed as hardware registers.
Is it a perfect solution? No.
Is it annoying? Yes, undoubtedly. People hate being told they cannot dig into stuff. I don't like it either.
But it's how we've decided we can best support our customers, and so I'm going to have to live with it.
2025-01-27 12:19 PM
Hi John.
Thank You for the respons and please apologize my english.
I had downloaded the api (and a lot of pdfs) before I posted here on the forum.
I spent two days to understand the driver and to adapt it for my HW. I use Example_1_ranging_basic example.
I had some minor problems probably with the I2C timing,
I tried to upload the configuration in one block, I couldn't do it.
I succeeded with uploading byte by byte.
I can now read the correct ID by VL53L4ED_GetSensorId,
VL53L4ED_FIRMWARE__SYSTEM_STATUS as 0x03 (thats OK),
I do the configuration as VL53L4ED_SensorInit, ( with 0 and also with 0x40 on the end of array (0x87))
I tried VL53L4ED_StartRanging (I read a zero from the VL53L4ED_INTERMEASUREMENT_MS register)
but I finish in the VL53L4ED_CheckForDataReady procedure
to test the Ready state.
I read 0x11 from VL53L4ED_GPIO_HV_MUX__CTRL
and 0x03 from VL53L4ED_GPIO__TIO_HV_STATUS,
I get a 0 as result, (not ready).
Because I have no idea what is the meaning of those registers and the bits in them,
I can't look for an error. It's probably some small thing, but there's nothing to go by.
I have no idea which register to look in to see if the circuit is running.
I can read :
VL53L4ED_RESULT__RANGE_STATUS ((uint16_t)0x0089) => 0
VL53L4ED_RESULT__SPAD_NB ((uint16_t)0x008C) => 0
VL53L4ED_RESULT__AMBIENT_RATE ((uint16_t)0x0090) => 0xFF00 / may be thats no correct byte order
VL53L4ED_RESULT__SIGMA ((uint16_t)0x0092) => 0
VL53L4ED_RESULT__DISTANCE ((uint16_t)0x0096) => 0
I have my HW with Kinetis MK20Dx265 :
* pin 1 (GND) of the VL53L4ED connected to GND
* pin 2 (VDD) of the VL53L4ED connected to 3V3
* pin 3 (SCL) of the VL53L4ED connected SCL of the Kinetis MCU
* pin 4 (SDA) of the VL53L4ED connected SDA of the Kinetis MCU
* pin 5 (GPIO1) of the VL53L4ED NC
* pin 6 (XSHUT) of the VL53L4ED connected to 3V3
*/
it's very hard for me to find a bug without knowing the function of the circuit.
I need to at least know what It mean when I read the
I read 0x11 from VL53L4ED_GPIO_HV_MUX__CTRL
and 0x03 from VL53L4ED_GPIO__TIO_HV_STATUS,
and why it is not ready state.
Annoying is, that I can only look at non-functioning device now.
May be I've just made some kind of schoolboy bug rewriting the driver.
Can You help me please?
We like the circuit, we would like to use it to measure short distances.
Best regards
Jaroslav
2025-01-27 01:22 PM
you have an I2C issue and I'm 99% sure it's a byte swap issue. Although word-swap is also possible.
I put some code in below.
See if you can insert that code into your project.
Just after getting the I2C initialized and the sensor powered up, see if you can get this to run.
It writes byte and reads back words. They should match.
it also does longwords and strings of bytes.
Give it a shot.
- john
2025-01-27 01:25 PM
That code lacks a little documentation. So look at this as well.
The doc was written with an VL53L1 in mind, so it's not exact, but it's close enough.
all the VL53L sensors have the same I2C logic.
- john
2025-01-27 01:33 PM
One of the standard ways of dealing/debugging this type of black-box type stuff is to work with the original materials on the original platform (ie STM gear), with that knowledge/working you can pivot into secondary architectures, and can contrast the relative behaviours. This can be done by adding instrumentation, or wrapping of key function, OR externally with the logic analyzer.
Yes, does sound like an I2C or driver level porting issue.
2025-01-28 09:08 AM
Hi John,
Thank you very much for sending the test.
It has helped me a lot and is very useful. Consider adding it to STSW-IMG044, it might help other guys.
Also very useful for me is the information that register 0x3A is writable and readable.
Before I got your test I prepared a completely new project, I used your example Example_1_ranging_basic as it is.
I only added I2C read and write functions to platform.c.
After starting the project, it was the same as my previous attempts.
I get locked in the procedure VL53L4ED_CheckForDataReady where I read same data:
I read 0x11 from VL53L4ED_GPIO_HV_MUX__CTRL
and 0x03 from VL53L4ED_GPIO__TIO_HV_STATUS,
Then I got your I2C test. Beautiful.
I can read the circuit ID correctly, but I always read 0 from register 0x3A.
I spent many hours checking the I2C, found one minor bug (the read routines always physically read one more byte , but returned the correct data). Just like the ID read.
I fixed this bug. I also checked the byte order , it is ok.
I checked the SDA and SCLK signals on the I2C bus.
I've looked at them in detail and I'm convinced they are fine. Correct read address, correct write address.
The data also matches the required write.
The read and write waveforms are in the attached image.
I've tried writing a single byte repeatedly and re-reading it. I always read zero.
I've tried reading different registers and the reads seem to be ok.
So,
I believe the I2C controler is ok, but for some reason the registers are not being written to.
Isn't there any write protection? Did I inadvertently manage to activate it?
Thank you for your patience.
Could you give me some more advice, please?
Best regards
Jaroslav
2025-01-28 10:32 AM
There is one last thing to look at with I2C. And it happens to people who know how i2C works. We use 2-byte register addresses.
There are way more registers than will fit in one byte.
So, when you write to address 0x29<1, (which is 0x52) the next TWO bytes are the register address. And then the data.
This is different from all the tiny I2C devices you are used to.
(We tried using single byte address and a page resister on the VL53L0X and everyone hated it. So now we use 2-byte addresses.)
If you can't seem to get the sensor to talk, this might be the reason.
- john