logo elektroda
logo elektroda
X
logo elektroda

ESP32-S3 ESP-IDF - VL53L4CD I2C, IO.WriteReg/Address indicators null, Guru Meditation

kaczmarekabt 87 7
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 21814239
    kaczmarekabt
    Level 2  
    Good day, I am programming an esp32s3 microprocessor in an ESP-IDF environment. I would like to connect it with one sensor (in the future with four) TOF VL53L4CD from ST Microelectronics (LINK1). I managed to establish communication with the sensor in the Arduino IDE, it works fine there without problems. In ESP-IDF I also manage to communicate with the sensor via i2c. However, I am a beginner and I am having a lot of problems implementing the library for this sensor (LINK2). I get an error when calling the function VL53L4CD_SetI2CAddress() :
    Code: text
    Log in, to see the code

    I get a Guru Meditation error when calling this function:
    Code: text
    Log in, to see the code


    Line 48 in the platform.c file is :
    Code: text
    Log in, to see the code

    I used the debugger and it turned out that the indices
    Code: text
    Log in, to see the code
    and
    Code: text
    Log in, to see the code
    have the value 0x00 despite their previous declaration :
    Code: text
    Log in, to see the code

    If there is a knowledgeable person on the forum who would be willing to help me, I would be grateful. I am using ESP_IDF via Visual Studio Code
    ESP32-S3 ESP-IDF - VL53L4CD I2C, IO.WriteReg/Address indicators null, Guru Meditation
    , I have imported all the files from the sensor library into the main folder for convenience I hope this is not a problem:
    View of the main folder in Visual Studio Code with VL53L4CD project files
    I will be happy to post additional details if needed.




    Kind regards Stanisław Kaczmarek





    LINK1: https://www.st.com/resource/en/datasheet/vl53l4cd.pdf
    LINK2: https://github.com/STMicroelectronics/x-cube-tof1
    The whole code (in the dirt) :
    Code: text
    Log in, to see the code

    [i]AI: Could you show how you create and initialise the dev structure (e.g. VL53L4CD_Dev_t) and how you pass it to the VL53L4CD_SetI2CAddress function? I'm referring to the bit of code where you assign the pointer to the IO and call the library functions.

    VL53L4CD_IO_t io_config = {
    .Init = My_I2C_Init,
    .DeInit = My_I2C_DeInit,
    .Address = 0x29,
    .WriteReg = My_WriteReg,
    .ReadReg = My_ReadReg,
    .GetTick = My_GetTick
    };
    AI: Have you made any changes to the VL53L4CD library files or the way it integrates into the ESP-IDF project (e.g. modifications to structures, header files, or other unusual steps when importing into the main folder)? If so, please describe them briefly.
    I have only added additional logs to facilitate debugging via the serial port, I have not changed the mechanics of the code.
  • ADVERTISEMENT
  • #2 21814401
    p.kaczmarek2
    Moderator Smart Home
    What is a dev_t? Rather than an address, but a pointer to an object?
    Code: C / C++
    Log in, to see the code

    Why are you setting it to 0x29?
    Code: C / C++
    Log in, to see the code

    It should rather be an object created by malloc() or by a function designed for this purpose, I am not familiar with this library.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 21814448
    kaczmarekabt
    Level 2  
    As far as I know this dev_t is a pointer to a VL53L4CD_Object_t:
    Code: text
    Log in, to see the code

    this is the code from the platform.h file.
    Actually I guess it doesn't make sense to write any value like that since it's a pointer, I corrected the code to make it more readable
    Code: C / C++
    Log in, to see the code
  • ADVERTISEMENT
  • #4 21814460
    p.kaczmarek2
    Moderator Smart Home
    Since it is a pointer to an object of type VL53L4CD_Object_t, by setting it to 0x29 you are pointing to a memory cell with that address, no wonder there is a crash.

    Is your new code complete?

    For example, I don't see you using there:
    Code: C / C++
    Log in, to see the code

    Looking around the web, there is a function for this:
    https://github.com/search?q=VL53L4CD_RegisterBusIO&type=code
    Helpful post? Buy me a coffee.
  • #5 21814466
    kaczmarekabt
    Level 2  
    After removing the dev indicator definition
    Code: Text
    Log in, to see the code

    My dev->IO.WriteReg is still 0x00, is there any possibility to write some value to this object ?
    ESP32-S3 ESP-IDF - VL53L4CD I2C, IO.WriteReg/Address indicators null, Guru Meditation
    Sorry for my non-technical language, I am just learning :)
  • #6 21814510
    p.kaczmarek2
    Moderator Smart Home
    The problem is more on the side of C-language knowledge, not ESP.

    You have in the code:
    Code: C / C++
    Log in, to see the code

    Dev_t is defined as a pointer to this object, a pointer uninitialised as a global variable has a value of 0. It points into the void, there is no object.

    For this object to exist, you must first create it. You can do this by using malloc.

    You can also make this object as a global variable, e.g:
    Code: C / C++
    Log in, to see the code

    and then instead of dev give &myObject(pointer to myObject).

    I'm sure it will help you a lot if you read up on pointers in C, etc, as this limits your work with ESP.

    You can also look generally at how others are using this library, e.g. by searching on GitHub:
    ESP32-S3 ESP-IDF - VL53L4CD I2C, IO.WriteReg/Address indicators null, Guru Meditation
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 21814586
    kaczmarekabt
    Level 2  
    Thank you, I will try to learn the c language, I have ordered 3 books on the subject and will read in the coming days. I managed to solve the guru meditation error by following the tips, I still have minor hardware issues with the sensor but I think I can handle that myself :) .
    So thank you very much for your help. I still have a question if I can contact you when I have other problems with the ESP-IDF or should I post on the forum ?
  • #8 21814595
    p.kaczmarek2
    Moderator Smart Home
    You can always post boldly in the forum, and you can give me a link on PW to the topic so I can find it quicker.
    Helpful post? Buy me a coffee.
ADVERTISEMENT