This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

I2C (TWI) communication problem with the VL53L1X Time of Flight sensor

Hello,

I'm trying to use the VL53L1X Time of Flight sensor on my nRF52DK, but I experience some problems.

Previously, I've successfully used the VL53L1X with an Arduino UNO using the pololu Arduino library (link below). For my project I need to use this sensor on the nRF52, so I've rewritten the vl53l1_platform.cpp and main .ino code to C (the other files are from ST's VL53L1 API, which are already in C).
When the sensor is not connected, the nRF52 is writing the correct data to the SCL and SDA lines, but if I connect the sensor, these lines give incorrect data. Instead of sending to address 0x29, it sends to address 0x7F or 0x00. And instead of sending the data 0x01 and 0x0F, it sends 0xFF and 0xFF (or 0x00 and 0x00).

I have correctly connected and initialized the INT and XSHUT lines.

I'm not sure what the problem can be, because it worked with the Arduino UNO, but not with the nRF52 (even though the I2C is working correctly without the sensor).

 

My setup:

Parents
  • Hi,

    You write that you write to the wrong address. I am not sure if you refer to the I2C address of the VL53L1X or a register address within VL53L1X. Also, I have no knowledge about your code. Perhaps you can upload your code and logic analyzer traces and explain what the trace should look like and why (with reference to code), and hold that against the trace you actually see. Then we can look at the code to try to see if we spot anything.

  • Thanks for your reply.

    I write to the address 0x29, but with my logic analyser i see address 0x7F. When i write to register 0x01 0x0F, the logic analyser reads 0xFF and 0xFF. (i hope this is more clear. See als the logic analyser results below).

    i2c signals (Arduino):

    i2c signals (nRF):

    i2c signal (nRF without sensor connected):
    (it does not send the register, because there is no sensor attached).

    My main code (my real code is a bit of a mess so here is a cleaner version):

    #define I2C_SCL_PIN     ARDUINO_SCL_PIN
    #define I2C_SDA_PIN     ARDUINO_SDA_PIN
    #define VL53_XSHUT_PIN  ARDUINO_13_PIN
    #define VL53_GPIO_PIN   ARDUINO_12_PIN
    
    VL53L1_Dev_t Device[1];
    
    int main() {
        // Initialize i2c (twi)
        itph_nrf52sdk15_i2c_init(&g_twi_instance, I2C_SCL_PIN, I2C_SDA_PIN, &g_i2c_instance);
        
        // Connect i2c Instance to library
    	VL53L1X_set_i2c_instance(&g_i2c_instance);
        
        // Initialize GPIO (INT) and XSHUT
        nrf_gpio_cfg_input(VL53_GPIO_PIN, NRF_GPIO_PIN_PULLUP);
        nrf_gpio_cfg_output(VL53_XSHUT_PIN);
        nrf_gpio_pin_set(VL53_XSHUT_PIN);
        nrf_delay_ms(10)
        nrf_gpio_pin_clear(VL53_XSHUT_PIN);
        nrf_delay_ms(10);
        nrf_gpio_pin_set(VL53_XSHUT_PIN);
        
        nrfx_gpiote_init();
        
        // Set device variables
    	Device->I2cDevAddr = 0x29;
    	Device->comms_type = 1;     // i2c
    	Device->comms_speed_khz = NRF_TWI_FREQ_400K; // 400kHz
    	Device->I2cHandle = NULL;	// no i2c handle
    	
    	// Read IDENTIFICATION__MODEL_ID
    	uint8_t address = Device->I2cDevAddr;
    	uint16_t index = IDENTIFICATION__MODEL_ID;  // 0x01 0x0F
    	uint8_t* pdata;
    	VL53L1X_read_multi(address, index, pdata, 2);
    
    }
    
    int32_t VL53L1X_read_multi(uint8_t address,  uint16_t index, uint8_t  *pdata, int32_t count) {
    	uint8_t buffer[2];
    	buffer[0] = (index >> 8) & 0xFF;    // reg high
    	buffer[1] = index & 0xFF;	        // reg low
    	int result = i2c_send(m_i2c_instance, address, buffer, 2);
    	if (result) { return result; }
    	return i2c_recv(m_i2c_instance, address, pdata, count);
    }
    

    I only added the analyser traces which result from line 44.
    Anayler result: "write [address]" and "[register high] + ACK" and "[register low] + ACK"
    Resulted from line 44: int result = i2c_send(m_i2c_instance, address, buffer, 2);

  • Hi,

    I have no knowledge of the VL53L1X driver, so the code snippet here does not show me much. From my point of view I would be interested in what you put into the nRF SDK API's (so one of the TWI drivers - which are you using?) and how that relates to what you actually see on the I2C lines.

  • Hi,

    I changed my sensor for new one. It is working correctly now.

    Thank you for your time

  • Hello frank1,

    I m trying doing the same thing but i dont get aniway and I am really unexperient :( can U suply ur code for controling the sensor using the nrf52SDK ?

Reply Children
No Data
Related