2021-04-06 11:19 PM
Hi forum,
I am working on nrf52 , I was communicate with sensor through I2C.
GPIO_configuration:-
nrf_gpio_cfg_output(VSHUT);
nrf_gpio_pin_write(VSHUT,0);
nrf_gpio_pin_write(VSHUT,1);
nrf_delay_ms(10);
nrf_gpio_input_disconnect(TRACEDATA1);// gpio1 interrupt pin
Sequence of APP_function are below:-
VL53L1_comms_initialise(uint8_t comms_type, uint16_t comms_speed_khz);
VL53L1_SetDeviceAddress(VL53L1_DEV Dev, uint8_t DeviceAddress);
VL53L1_DataInit(VL53L1_DEV Dev);
VL53L1_StaticInit(pMyDevice);
VL53L1_run_ref_spad_char(pMyDevice,&pcal_status);
other function for calibration .
but data_init() function return -15.
i did supplied 3.3volt external supply to my device.Actually i device gives 2.59volt thats why i connect external supply for sensor power up. Device is externally pullup through 10k resistor.
please help me to solve this error. Is their any setting required for this sensor to power up.
2021-04-07 04:28 AM
please someone help me,to set data_init() function properly .it return -15 Due to this function static_init() also return -15. I checked in error.h library
this return #define VL53L1_ERROR_DIVISION_BY_ZERO ((VL53L1_Error) - 15)
/*!< In the function a division by zero occurs */
Actually which setting required please help me.
2021-04-07 07:23 AM
first thing to try.
Put a
nrf_gpio_cfg_output(VSHUT);
nrf_gpio_pin_write(VSHUT,0);
nrf_delay_ms(10);
nrf_gpio_pin_write(VSHUT,1);
nrf_delay_ms(10);
your MCU is a LOT faster than is the sensor. By toggling the VSHUT so quickly, the sensor didn't have time to do anything.
AS to the divide by zero, I'm going to guess that you got the Byte reads and Writes corrrect but may have a problem with the words and longwords being 'byte swapped.
call the enclosed bit of code in your system just before your call to static_init(). It will verify the I2C fuctions work properly.
(once you get it to run correctly, you can remove it. It exercises and verifies all the read and write modes.
2021-04-14 12:08 AM
Thanks forum,
actually my errror not solved , i was checked internal function of driver API.In data_init() below function return err_code -15.
if (status == VL53L1_ERROR_NONE)
status = VL53L1_set_preset_mode(
Dev,
pdev->preset_mode,
pdev->dss_config__target_total_rate_mcps, /* 9.7 format 20Mcps */
pdev->phasecal_config_timeout_us,
pdev->mm_config_timeout_us,
pdev->range_config_timeout_us,
pdev->inter_measurement_period_ms);
printf("status_preset_mode : %d\n",status);
In above function I also checked internal function,
if (status == VL53L1_ERROR_NONE)
status =
VL53L1_set_inter_measurement_period_ms(
Dev,
inter_measurement_period_ms);
printf("VL53L1_set_inter_measurement_period_ms %d\n",status);
LOG_FUNCTION_END(status);
In the preset_mode() above VL53L1_set_inter_measurement_period_ms() return err_code -15.
I tried to change this default value but still getting errror.
please someone help me to solve this error.
2021-04-14 08:07 AM
A minus 15 error is a divide by 0.
It's found in vl53l1_error_codes.c
#define VL53LX_ERROR_DIVISION_BY_ZERO ((VL53LX_Error) - 15)
So how did you get that?
Well, you have a byte swap or word swap issue.
You have to verify that what you are sending and what the chip is getting is the same thing.
There is a bit of code attached to the first post.
All it does is send bytes, words and long words, and reads them back in different formats.
It will verify that your I2C interface is working.
(Clearly the byte read/write works as you have gotten this far.)
I've seen many issues like this, all resolved once the I2C interface is straightened out.
Put this bit of code in, get it to run, then you can take it out.
I'm attaching a app note. It was written for the VL53L0, so don't use the code in it.
But give it a read. It expains the problem.
Why am I so sure?
Well you haven't done anything yet. you haven't changed any parameters, or even gotten to the code you have written.
And the code works for a lot of other people.
That only leaves the I2C interface.
2021-04-15 04:01 AM
hi forum,
I am tried using i2c test() but this function it written i2c test failed and status=1;
Actually, after that What I need to do ?
I worked on nrf52 , at debug i checked device address it gives 0x00.
//nrf_gpio_cfg(VSHUT,
// NRF_GPIO_PIN_DIR_OUTPUT,
// NRF_GPIO_PIN_INPUT_DISCONNECT,
// NRF_GPIO_PIN_NOPULL,
// NRF_GPIO_PIN_S0H1,
// NRF_GPIO_PIN_NOSENSE);
// //nrf_gpio_cfg_input (VSHUT,NRF_GPIO_PIN_PULLDOWN);
nrf_gpio_cfg_output(VSHUT);
nrf_gpio_pin_write(VSHUT,0);
nrf_delay_ms(10);
nrf_gpio_pin_write(VSHUT,1);
nrf_delay_ms(10);
nrf_gpio_cfg_input(TRACEDATA1,NRF_GPIO_PIN_NOPULL);
//nrf_gpio_pin_write(VSHUT,1);
ret_code_t err_code;
uint8_t byteData;
uint16_t wordData;
// Initialize.
err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);
// Initialize Comms
MyDevice.I2cDevAddr =0x29 << 1; //0x52;
MyDevice.comms_type = 1;
MyDevice.comms_speed_khz = 100;
//MyDevice.new_data_ready_poll_duration_ms = 0x02;
//nrf_delay_ms(2);
//pMyDevice->I2cDevAddr = 0x29 << 1;
err_code = VL53L1_SetDeviceAddress(pMyDevice, pMyDevice->I2cDevAddr);
// pMyDevice->I2cDevAddr =0x29 << 1; //change address even in case of error to reduce cross-talk
if (err_code != VL53L1_ERROR_NONE) {
printf("[error] VL53L1_SetDeviceAddress(%d) failed\r\n", err_code);
//continue;
} else {
printf("[OK] VL53L1_SetDeviceAddress(%d)\r\n", err_code);
}
//nrf_delay_ms(2);
VL53L1_Version_t Version;
VL53L1_Version_t *pVersion = &Version;
uint8_t deviceRevisionMajor;
uint8_t deviceRevisionMinor;
// for start the communication
/**
* @brief Initialise platform comms.
*
* @param comms_type - selects between I2C and SPI
* @param comms_speed_khz - unsigned short containing the I2C speed in kHz
*
* @return status - status 0 = ok, 1 = error
*
*/
rd_write_verification( pMyDevice, pMyDevice->I2cDevAddr, expected_value);
i2c_test(pMyDevice);
err_code = VL53L1_comms_initialise(I2C,100);//i2c_platform.c
printf("err_code_a :%d\n",err_code);
//err_code=VL53L1_write_multi(pMyDevice->I2cDevAddr,VL53L1_FIRMWARE__ENABLE,data,1);
//for(i=0;i<40;i++)
//{
//printf("err_code_write: %d\n",err_code);
//printf("data[i]: %d",data[i]);
//}
if(VL53L1_ERROR_NONE == err_code)
{
//err_code=VL53L1_write_byte(pMyDevice->I2cDevAddr,VL53L1_FIRMWARE__ENABLE,1);
//nrf_delay_ms(2);
err_code=VL53L1_SetCalibrationData(pMyDevice,&CalibrationData);
printf("err_code_cali :%d\n",err_code);
//if(VL53L1_ERROR_NONE != err_code)
//{
//nrf_delay_ms(2);
//err_code=VL53L1_WaitDeviceBooted(pMyDevice);
//printf("err_code_boot:%d\n",err_code);
//nrf_delay_ms(2);
//VL53L1_WrByte(pMyDevice,VL53L1_I2C_SLAVE__DEVICE_ADDRESS,0x52);
VL53L1_Error VL53L1_DataInit(VL53L1_DEV Dev);
err_code = VL53L1_DataInit(pMyDevice); //
printf("err_code_data :%d\n",err_code);
after data_init() gives error. please check this code if any changes required let me know.
please help me to slove this problem.
2021-04-15 07:17 AM
let's try this diffently - you are clearly not communicating over the I2C. And without that you have no chance.
Go to github.com. They have tons of working code. And you can search it.
Find some code that uses your MCU and uses the I2C.
You might even be lucky enough to find some code that uses both your MCU and a VL53L1X.
then start with that.
But almost any project that has an I2C will do. It will get you past the basics of setting up the I2C.
the first few lines of the Verification software read the ID register from the sensor.
Dont even think about proceeding until you get that.