cancel
Showing results for 
Search instead for 
Did you mean: 

About VL53L0X with Renesas Microcontroller

Ashish123
Visitor

hello Team,

                   I am using your sensor VL53L0X distance sensor in my project. The problem is your library not support with this Renesas RX71 microcontroller so i did send the register and receive the register with FIT module function in Renesas provide.

but i don't get the distance value i read the 0x14 register and store in the array and shift LSB to MSB to get range data i get some value as i move my hand from the sensor the value are move means the sensor leaser position is movement is done the value is move is difference is more. so couldn't  match actual distance.
i am attaching my code plz see and revert as soon as possible.

i am attaching video just see.

best regard's

Ashish.

 

this are variable declaration and register

/////VL53L0X/////
#define DATA_LENGTH 14

uint8_t tx_buf[2] = {0x00,0x02};// Command to start a measurement
uint8_t rx_buf1[1]={0x14};
uint8_t rx_buf2[1]={0x1e};
uint8_t rx_buf3[1]={0x1f};

uint8_t tx_buf4[2]={0x80,0x01};
uint8_t tx_buf5[2]={0xff,0x01};
uint8_t tx_buf6[2]={0x00,0x00};
uint8_t tx_buf7[2]={0xff,0x06};
uint8_t tx_buf8[2]={0x83,0x04};
uint8_t tx_buf9[2]={0xff,0x07};
uint8_t tx_buf10[2]={0x81,0x01};
uint8_t tx_buf11[2]={0x80,0x01};
uint8_t tx_buf12[2]={0x94,0x6b};
uint8_t tx_buf13[2]={0x83,0x00};
uint8_t tx_buf14[2]={0x83,0x01};
uint8_t tx_buf15[2]={0x81,0x00};
uint8_t tx_buf16[2]={0xff,0x06};
uint8_t tx_buf17[2]={0xff,0x01};
uint8_t tx_buf18[2]={0x00,0x01};
uint8_t tx_buf19[2]={0xff,0x00};
uint8_t tx_buf20[2]={0x80,0x00};
uint8_t tx_buf21[2]={0x88,0x00};
uint8_t tx_buf22[2]={0x80,0x01};
uint8_t tx_buf23[2]={0xff,0x01};
uint8_t tx_buf24[2]={0x00,0x00};
uint8_t tx_buf25[2]={0x00,0x01};
uint8_t tx_buf26[2]={0xff,0x00};
uint8_t tx_buf27[2]={0x80,0x00};
uint8_t tx_buf28[2]={0x4f,0x00};
uint8_t tx_buf29[2]={0x4e,0x2c};
uint8_t tx_buf30[2]={0xb6,0xb4};
uint8_t tx_buf31[2]={0x0e,0x06};

uint8_t spadcount=0;
uint8_t samples4=0;
uint16_t accumulator=0;
uint16_t average=0;
uint16_t duty=0;
uint8_t gbuf[16];
//uint8_t distance4=0;
uint8_t distance1=0;
uint16_t data[DATA_LENGTH];
uint8_t i4=0;
uint16_t DIST_SCAL=0;
uint16_t sensor_range=0;
uint16_t distance_cm=0;
uint16_t cm_size=0;
uint16_t deverror=0;
uint16_t DIST_COUNT;
MD_STATUS response;
uint8_t j4=0;
uint8_t sz=12;
uint16_t final_scale=0;
uint8_t gbuf1[12];
uint8_t test_buf[5];
uint8_t samples5=0;
//uint16_t accumulator1=0;
uint16_t Updated_scale=0;
//uint16_t duty1=0;
uint8_t data_entry_buf_con1[2] = {0x00,0x00};
uint8_t page1=0;
//how read VL53L0X distance sensor value using i2c in renesas rx71//
uint16_t batteryPercentage=0;
//function prototypes//
//void R_RIIC2_Start(void);
void delay(int t);
void send();
void read_vl53l0x();
void read_block_data_at(uint8_t reg, uint8_t sz);
void vl53l0x();
void user_rebound_no();
uint16_t user_entry_rebound_count();

///////////////main/////////////

 this are main function.

 

 

void send()
{
//i2c_init();
// RIIC2.ICCR2.BIT.ST = 1U; 
 R_RIIC2_Start();
 R_RIIC2_Master_Send(0x29,tx_buf,2);
 //R_RIIC2_StopCondition();
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf4,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf5,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf6,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf7,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf8,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf9,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf10,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf11,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf12,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf13,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf14,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf15,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf16,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf17,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf18,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf19,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf20,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf21,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf22,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf23,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf24,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf25,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf26,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf27,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf28,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf29,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf30,2);
 delay(5);
 R_RIIC2_Master_Send(0x29,tx_buf31,2);
 delay(5);
 R_RIIC2_StopCondition();
 delay(5);
 
}
 
void read_vl53l0x()
{
    //R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_MPC); // Re-lock the MPC register.
 
  i2c_init();
   // R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_MPC); // Re-lock the MPC register.
  
 R_RIIC2_Start();
 //RIIC2.ICCR2.BIT.ST = 1U;  
 delay(50);
 R_RIIC2_Master_Send(0x29,rx_buf2,1);
   delay(1000);
 // R_RIIC2_Master_Send(0x29,rx_buf2,12);
   R_RIIC2_StopCondition();
   delay(1000);
  R_RIIC2_Start();
//  RIIC2.ICCR2.BIT.ST = 1U;   
  delay(1000);
   R_RIIC2_Master_Receive(0x29,&data,2);
   
   deverror =(data[0] & 0x78) >> 3;
   distance_cm = (data[1] << | data[0];
   
    //distance_cm = (data[1] << | data[0];
   //DIST_COUNT=16896+distance_cm;
   duty = distance_cm;
      
             accumulator += duty;
              samples++;
        if ( samples == 5)
         {
               average = (accumulator/5);
      /// average=average+30;
       //delay(200);
                   accumulator = 0;
                    samples = 0;
         }
   delay(5);
   
   R_RIIC2_StopCondition();
   delay(5);
    RIIC2.ICCR1.BIT.IICRST = 1U;
   
   
}

 

1 REPLY 1
Ashish123
Visitor

Hello Team,

    i am attaching video for reference. Kindly see this.

 

thanks and regard's

Ashish.