void range_finder_init() { /* MCU Configuration----------------------------------------------------------*/ /* Initialize all configured peripherals */ MX_I2C1_Init(); tca9545_init(); tca9545_set(Channel_0); /* these almost just redo what already done just above by CubeMx Init */ XNUCLEO6180XA1_GPIO_Init(); XNUCLEO6180XA1_I2C1_Init(&hi2c1); tca9545Channel_e channel; for(channel = Channel_0; channel <= Channel_3; channel++) { tca9545_set(channel); MyDev_Init(myDev); // your code init device variable MyDev_SetChipEnable(myDev); // your code assert chip enable MyDev_uSleep(1000); // your code sleep at least 1 msec VL6180x_InitData(myDev); VL6180x_Prepare(myDev); } }
void Sample_XTalkCalibrate(void) { VL6180xDev_t myDev; VL6180x_RangeData_t Range; int XTalkRate; int i, status; /* init device */ MyDev_Init(myDev); status = Sample_Init(myDev); if( status <0 ){ HandleError("Sample_Init fail"); } /* run calibration */ XTalkRate = Sample_XTalkRunCalibration(myDev); /*TODO when possible reset re-init device else set back required scaling/filter*/ VL6180x_FilterSetState(myDev, 1); // turn on wrap around filter again VL6180x_UpscaleSetScaling(myDev, 3); // set scaling /* apply cross talk */ status = VL6180x_SetXTalkCompensationRate(myDev, XTalkRate); if( status<0 ){ /* ignore warning but not error */ HandleError("VL6180x_WrWord fail"); } for( i=0; i< 10; i++){ status = VL6180x_RangePollMeasurement(myDev, &Range); MyDev_ShowRange(myDev, Range.range_mm); } }
/** * All in one device init * @param myDev The device * @return 0 on success may @a #CALIBRATION_WARNING <0 on errir */ int Sample_Init(VL6180xDev_t myDev){ int status, init_status; MyDev_Init(myDev); // your code MyDev_SetChipEnable(myDev); // your code MyDev_uSleep(2000); // your code sleep at least 1msec prior to do i2c to device init_status = VL6180x_InitData(myDev); if(init_status == 0 || init_status == CALIBRATION_WARNING ){ status = VL6180x_Prepare(myDev); if( !status ) status=init_status; // if prepare is successfull return potential init warning } return status; }
/** * @brief Simplest polling ALS * that may be your main() */ void Sample_SimpleAls(void) { #if VL6180x_ALS_SUPPORT VL6180xDev_t myDev; VL6180x_AlsData_t Als; MyDev_Init(myDev); // your code init device variable MyDev_SetChipEnable(myDev); // your code assert chip enable MyDev_uSleep(1000); // your code sleep at least 1 msec VL6180x_InitData(myDev); VL6180x_Prepare(myDev); do { VL6180x_AlsPollMeasurement(myDev, &Als); if (Als.errorStatus == 0 ) MyDev_ShowLux(myDev, Als.lux); // your code display range in mm else MyDev_ShowErr(myDev, Als.errorStatus); // your code display error code } while (!MyDev_UserSayStop(myDev)); // your code to stop looping #endif }