Skip to main content
Associate II
August 22, 2024
Solved

I2C of VL53L1

  • August 22, 2024
  • 2 replies
  • 1186 views

HI,

I am using VL53L1 sat board, can i configure I2C of the sensor to 1MHz? How should i do it? Could u please guide me on this matter?

Thank you

Best answer by John E KVAM

In the X-cube ToF1, the software is limited to 400,000. But don't worry. Just generate the code and you will see - in main.c - the I2C initialization. 

just change that one line - it's all it takes.

hi2c1.Init.ClockSpeed = 100000; (it also might be 400,000 - but it doesn't matter. 
to:
hi2c1.Init.ClockSpeed = 1000000;
 
- john

2 replies

John E KVAM
ST Employee
August 22, 2024

First we have two VL53L1 parts, and they are sligthly different as to which code they run. 

But either way when you download the API code, there will be examples. 

In main.c of the examples there is a bit of code:

* I2C1 init function */
static void MX_I2C1_Init(void)
{

  hi2c1.Instance = I2C1;
  hi2c1.Init.ClockSpeed = 100000;
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
  hi2c1.Init.OwnAddress1 = 0;
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  hi2c1.Init.OwnAddress2 = 0;
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  if (HAL_I2C_Init(&hi2c1) != HAL_OK)
  {
    Error_Handler();
  }

}
Just change that:
hi2c1.Init.ClockSpeed = 100000;
to:
hi2c1.Init.ClockSpeed = 1000000;
 
It's just the one line.
 
vishnusfAuthor
Associate II
August 23, 2024

Hi John,

Thaks for the response. I am actually using X CUBE TOF!1 project. can you tell me how to change the I2C speed there to 1MHZ?

Thank you

John E KVAM
John E KVAMBest answer
ST Employee
August 26, 2024

In the X-cube ToF1, the software is limited to 400,000. But don't worry. Just generate the code and you will see - in main.c - the I2C initialization. 

just change that one line - it's all it takes.

hi2c1.Init.ClockSpeed = 100000; (it also might be 400,000 - but it doesn't matter. 
to:
hi2c1.Init.ClockSpeed = 1000000;
 
- john
John E KVAM
ST Employee
August 26, 2024

It works just fine. I do it all the time. For some reason the XCube code refuses to allow the 1M, but it's been working for me for years. And I had one demo with 9 sensors, which ran for weeks and weeks. Not an issue.

I've reported it as a bug, but the STM32 guys don't seem too interested in changing it.