AnsweredAssumed Answered

Nucleo F401RE , VL6180x issue

Question asked by vardhan_rao.kollu_ha on Mar 16, 2015
Latest reply on Mar 16, 2015 by vardhan_rao.kollu_ha
hai Im using Nucleo F401RE  and Connected Satel-VL6180x 
Below is my program in MBED online compiler. The VL6180x is not doing the ranging operation, there is no  signal transfer in the SCL and SDA lines. Please help me.

///////////////////////////////////////////////////////////////////
// Beginning of code
///////////////////////////////////////////////////////////////////
#include "mbed.h"
DigitalOut gpio0(PA_5); //using PA5 pinout as reset for VL6180x
DigitalIn gpio1(PA_6);// using PA6 as input for interrupt fromVL6180x (not using at present)
DigitalOut led1(PA_7);// using PA6 as output pin for blinking led1
DigitalOut led2(PB_6);// using PA7 as output pin for blinking led2
DigitalOut led3(PC_7);// using PB6 as output pin for blinking led3
DigitalOut led4(PA_9);// using PC7 as output pin for blinking led4
DigitalOut led5(PA_8);// using PA9 as output pin for blinking led5
I2C i2c(PB_8, PB_9); // Set up I²C on the STM32 NUCLEO-401RE
#define addr (0x52) // I²C address of VL6180X shifted by 1 bit
//(0x29 << 1) so the R/W command can be added 
///////////////////////////////////////////////////////////////////
// Split 16-bit register address into two bytes and write
// the address + data via I²C
///////////////////////////////////////////////////////////////////
void WriteByte(wchar_t reg,char data) {
char data_write[3];
data_write[0] = (reg >> 8) & 0xFF;; // MSB of register address
data_write[1] = reg & 0xFF; // LSB of register address
data_write[2] = data & 0xFF;
i2c.write(addr, data_write, 3);
}


///////////////////////////////////////////////////////////////////
// Split 16-bit register address into two bytes and write
// required register address to VL6180X and read the data back
///////////////////////////////////////////////////////////////////
char ReadByte(wchar_t reg) {
char data_write[2];
char data_read[1];
data_write[0] = (reg >> 8) & 0xFF; // MSB of register address
data_write[1] = reg & 0xFF; // LSB of register address
i2c.write(addr, data_write, 2);
i2c.read(addr, data_read, 1);
return data_read[0];
}
///////////////////////////////////////////////////////////////////
// load settings
///////////////////////////////////////////////////////////////////
int VL6180X_Init() {
char reset;
reset = ReadByte(0x016);
if (reset==1){ // check to see has it be Initialised already
///////////////////////////////////////////////////////////////////
// Added latest settings here
///////////////////////////////////////////////////////////////////


WriteByte(0x0207, 0x01);
WriteByte(0x0208, 0x01);
WriteByte(0x0096, 0x00);
WriteByte(0x0097, 0x54);
WriteByte(0x00e3, 0x00);
WriteByte(0x00e4, 0x04);
WriteByte(0x00e5, 0x02);
WriteByte(0x00e6, 0x01);
WriteByte(0x00e7, 0x03);
WriteByte(0x00f5, 0x02);
WriteByte(0x00d9, 0x05);


WriteByte(0x009f, 0x00);
WriteByte(0x00a3, 0x28);
WriteByte(0x00b7, 0x00);
WriteByte(0x00bb, 0x28);
WriteByte(0x00b2, 0x09);
WriteByte(0x00ca, 0x09);
WriteByte(0x0198, 0x01);
WriteByte(0x01b0, 0x17);
WriteByte(0x01ad, 0x00);
WriteByte(0x00ff, 0x05);
WriteByte(0x0100, 0x05);
WriteByte(0x0199, 0x05);
WriteByte(0x01a6, 0x1b);
WriteByte(0x01ac, 0x3e);
WriteByte(0x01a7, 0x1f);
WriteByte(0x0030, 0x00);
WriteByte(0x0011, 0x10);
WriteByte(0x010a, 0x30);
WriteByte(0x003f, 0x46);
WriteByte(0x0031, 0xFF);
WriteByte(0x0040, 0x63);
WriteByte(0x002e, 0x01);
WriteByte(0x002c, 0xff);
WriteByte(0x001b, 0x09);
WriteByte(0x003e, 0x31);
WriteByte(0x0014, 0x24);


 //change fresh out of set status to 0
WriteByte(0x097, 0x54); // Scalar = 253/3 = 84
WriteByte(0x01C, 0x3f); // Max convergence time 63ms
WriteByte(0x024, 0x8); // offset = offset/3 the offset depends on your part.
WriteByte(0x0A3, 0x28); // Reference convergence threshold = 40
WriteByte(0x0BB, 0x28); // Return convergence threshold = 40
//discard when no target is present
WriteByte(0x025, 0xff); // for any distance we check the return rate
WriteByte(0x026, 0x4) ; // We validate a measure only if the return rate is above 8Mcps, knowing that when there is no target we measure below 6Mcps
WriteByte(0x027, 0x00); // We validate a measure only if the return rate is above 8Mcps, knowing that when there is no target we measure below 6Mcps
WriteByte(0x02d, 0x2) ; // enable the check
// correct crostalk only above 74mm
WriteByte(0x01e, 0x3); // knowing that in a normal equipment this value is close to the no target return rate measured at 6Mcps
WriteByte(0x01f, 0x00); // knowing that in a normal equipment this value is close to the no target return rate measured at 6Mcps
WriteByte(0x020, 0x4A); // limit 74mm
}
return 0;
}
///////////////////////////////////////////////////////////////////
// Start a range measurement in single shot mode
///////////////////////////////////////////////////////////////////
int VL6180X_Start_Range() {
WriteByte(0x018,0x01);
return 0;
}
///////////////////////////////////////////////////////////////////
// poll for new sample ready ready
///////////////////////////////////////////////////////////////////
int VL6180X_Poll_Range() {
char status;
char range_status;
// check the status
status = ReadByte(0x04f);
range_status = status & 0x07;
// wait for new measurement ready status
while (range_status != 0x04) {
status = ReadByte(0x04f);
range_status = status & 0x07;
}
return 0;
}
///////////////////////////////////////////////////////////////////
// Read range result (mm)
///////////////////////////////////////////////////////////////////
int VL6180X_Read_Range() {
int range;
range=ReadByte(0x062);
return range;
}
///////////////////////////////////////////////////////////////////
// clear interrupts
///////////////////////////////////////////////////////////////////
int VL6180X_Clear_Interrupts() {
WriteByte(0x015,0x07);
return 0;
}
///////////////////////////////////////////////////////////////////
// Main Program loop
///////////////////////////////////////////////////////////////////
int main()


{  
int p1;
int p2;
gpio0 = 1;
wait (0.1);
int range;


// load settings onto VL6180X
VL6180X_Init();
/////////////////////////////////**********************///////////////////
p1 = ReadByte(0x026);
p2 = ReadByte(0x028);


if(ReadByte(0x026)!=0 )
{
   
    WriteByte(0x0da, p1);
    WriteByte(0x0dc, p2);
     
}
if(ReadByte(0x026) == 0 )
{
    WriteByte(0xda, 0x00);
    WriteByte(0xdb, 0xce);
    WriteByte(0xdc, 0x03);
    WriteByte(0x03, 0xf8);
}
        
/////////////////////////////////**********************///////////////////




while (1){
// start single range measurement
VL6180X_Start_Range();
// poll the VL6180X till new sample ready
VL6180X_Poll_Range();
// read range result
range = VL6180X_Read_Range();
if((range>0x23) && (range<0x2D))//a and b are the lower and upper ranges for switch1 aperture (hex value of millimeters)
{led1 = 1;
led2=0;
led3=0;
led4=0;
led5=0;


}
if((range>0x3C) && (range<0x45))//c and d are the lower and upper ranges for switch1 aperture (hex value of millimeters)
{
led2 = 1;
led1=0;
led3=0;
led4=0;
led5=0;
}
if((range>0x6E) && (range<0x78))//e and f are the lower and upper ranges for switch1 aperture (hex value of millimeters)
{
led3=1;
led1=0;
led2=0;
led4=0;
led5=0;
}
if((range>0x81) && (range<0x88))//g and h are the lower and upper ranges for switch1 aperture (hex value of millimeters)
{
led4=1;
led1=0;
led2=0;
led3=0;
led5=0;
}
if((range>0xA5) && (range<0xB9))//i and j are the lower and upper ranges for switch1 aperture (hex value of millimeters)
{
led5=1;
led1=0;
led2=0;
led3=0;
led4=0;
}


// clear the interrupt on VL6180X
VL6180X_Clear_Interrupts();
}
}

Outcomes