欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
VL53L0x激光測(cè)距STM32源程序
[打印本頁(yè)]
作者:
glory_gm
時(shí)間:
2020-2-17 20:28
標(biāo)題:
VL53L0x激光測(cè)距STM32源程序
激光測(cè)距資料,移植參考的資料
單片機(jī)源程序如下:
#include "vl53l0.h"
#include "usart.h"
u8 sendbuff[6]={0,0,0,0,0,0};
VL53L0X_Dev_t vl53l0x_dev;
VL53L0X_DeviceInfo_t vl53l0x_dev_info;
VL53L0X_RangingMeasurementData_t vl53l0x_data;
VL53L0X_Error vl53l0x_status;
/***************************************************************************************/
void print_pal_error(VL53L0X_Error Status)
{
char buf[VL53L0X_MAX_STRING_LENGTH];
VL53L0X_GetPalErrorString(Status, buf); //得到錯(cuò)誤碼與字符串
printf("API Status: %i : %s\n", Status, buf);
}
void print_range_status(VL53L0X_RangingMeasurementData_t* pdata)
{
char buf[VL53L0X_MAX_STRING_LENGTH];
uint8_t RangeStatus;
// New Range Status: data is valid when pdata->RangeStatus = 0
RangeStatus = pdata->RangeStatus;
VL53L0X_GetRangeStatusString(RangeStatus, buf);
printf("Range Status: %i : %s\n", RangeStatus, buf);
}
VL53L0X_Error vl53l0x_start_single_test(VL53L0X_Dev_t *pdev, \
VL53L0X_RangingMeasurementData_t *pdata)
{
int i=0,j=0,sum=0;
VL53L0X_Error status = VL53L0X_ERROR_NONE;
if(vl53l0x_status != VL53L0X_ERROR_NONE)
return vl53l0x_status;
status = VL53L0X_PerformSingleRangingMeasurement(pdev, pdata); //VL53L0X執(zhí)行單一測(cè)量范圍
if(status != VL53L0X_ERROR_NONE){
printf("error:Call of VL53L0X_PerformSingleRangingMeasurement\n");
return status;
}
print_range_status(pdata);
for(i=0;i<5;i++)
sum+=pdata->RangeMilliMeter;
pdata->RangeMilliMeter=sum/5;
printf("Measured distance: %i\n\n", pdata->RangeMilliMeter);
sendbuff[0]=200;
sendbuff[1]=201;
sendbuff[2]=pdata->RangeMilliMeter%100;
sendbuff[3]=pdata->RangeMilliMeter/100;
sendbuff[4]=data1;
sendbuff[5]=data2;
for(j=0;j<6;j++)
{
USART1->DR = sendbuff[j];
while((USART1->SR&0X40)==0);//循環(huán)發(fā)送,直到發(fā)送完畢
}
return status;
}
VL53L0X_Error vl53l0x_measure_init(VL53L0X_Dev_t *pMyDevice)
{
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
//FixPoint1616_t LimitCheckCurrent;
uint32_t refSpadCount;
uint8_t isApertureSpads;
uint8_t VhvSettings;
uint8_t PhaseCal;
// Device Initialization
Status = VL53L0X_StaticInit(pMyDevice); //基本設(shè)備初始化
if(Status != VL53L0X_ERROR_NONE){ //判斷是否初始化成功 失敗打印錯(cuò)誤信息
printf ("Call of VL53L0X_StaticInit\n");
print_pal_error(Status);
return Status;
}
// Device Initialization
Status = VL53L0X_PerformRefCalibration(pMyDevice, &VhvSettings, &PhaseCal); //執(zhí)行參考校準(zhǔn)
if(Status != VL53L0X_ERROR_NONE){ //判斷是否校準(zhǔn)成功
printf ("Call of VL53L0X_PerformRefCalibration\n");
print_pal_error(Status);
return Status;
}
// needed if a coverglass is used and no calibration has been performed
Status = VL53L0X_PerformRefSpadManagement(pMyDevice,&refSpadCount, &isApertureSpads);
if(Status != VL53L0X_ERROR_NONE){
printf ("Call of VL53L0X_PerformRefSpadManagement\n");
printf ("refSpadCount = %d, isApertureSpads = %d\n", refSpadCount, isApertureSpads);
print_pal_error(Status);
return Status;
}
// no need to do this when we use VL53L0X_PerformSingleRangingMeasurement 當(dāng)我們使用VL53L0X_PerformSingleRangingMeasurement不需要
Status = VL53L0X_SetDeviceMode(pMyDevice, VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode 設(shè)置單一測(cè)量模式
if(Status != VL53L0X_ERROR_NONE){
printf ("Call of VL53L0X_SetDeviceMode\n");
print_pal_error(Status);
return Status;
}
// Enable/Disable Sigma and Signal check
if(Status == VL53L0X_ERROR_NONE){
Status = VL53L0X_SetLimitCheckEnable(pMyDevice, //啟用/禁用特定限制檢查
VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1);
}
if(Status == VL53L0X_ERROR_NONE){
Status = VL53L0X_SetLimitCheckEnable(pMyDevice,
VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
}
if(Status == VL53L0X_ERROR_NONE){
Status = VL53L0X_SetLimitCheckValue(pMyDevice,
VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
(FixPoint1616_t)(0.25*65536));
}
if(Status == VL53L0X_ERROR_NONE){
Status = VL53L0X_SetLimitCheckValue(pMyDevice,
VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
(FixPoint1616_t)(18*65536));
}
if(Status == VL53L0X_ERROR_NONE){
Status = VL53L0X_SetMeasurementTimingBudgetMicroSeconds(pMyDevice, //設(shè)置微秒時(shí)間
200000);
}
if(Status != VL53L0X_ERROR_NONE){
printf ("Sigma and Signal check error\n");
print_pal_error(Status);
return Status;
}
/*
* Step 4 : Test ranging mode
*/
/* for(i=0;i<10;i++){
printf ("Call of VL53L0X_PerformSingleRangingMeasurement\n");
Status = VL53L0X_PerformSingleRangingMeasurement(pMyDevice,
&vl53l0x_data);
print_pal_error(Status);
print_range_status(&vl53l0x_data);
VL53L0X_GetLimitCheckCurrent(pMyDevice,
VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, &LimitCheckCurrent);
printf("RANGE IGNORE THRESHOLD: %f\n\n", (float)LimitCheckCurrent/65536.0);
if (Status != VL53L0X_ERROR_NONE) break;
printf("Measured distance: %i\n\n", vl53l0x_data.RangeMilliMeter);
}
*/
return Status; //返回0
}
VL53L0X_Error vl53l0x_init(void)
{
VL53L0X_Error Status = VL53L0X_ERROR_NONE; //初始值賦值為0
VL53L0X_Dev_t *pMyDevice = &vl53l0x_dev; //得到設(shè)備地址
pMyDevice->I2cDevAddr = 0x52; //iic地址
pMyDevice->comms_type = 1; //選擇IIC還是SPI iic=1;SPI=0
pMyDevice->comms_speed_khz = 400; //iic速率
VL53L0X_i2c_init(); //IIC配置
Status = VL53L0X_DataInit(pMyDevice); // Data initialization //VL53L0X_DataInit:一次設(shè)備的初始化,初始化成功返回0
if(Status != VL53L0X_ERROR_NONE){ //判斷如果狀態(tài)不為0 打印錯(cuò)誤信息
print_pal_error(Status);
return Status; // 返回錯(cuò)誤值 可通過此值DEBUG查找錯(cuò)誤位置
}
Status = VL53L0X_GetDeviceInfo(pMyDevice, &vl53l0x_dev_info); //讀取給定設(shè)備的設(shè)備信息
if(Status != VL53L0X_ERROR_NONE){
print_pal_error(Status);
return Status;
}
printf("VL53L0X_GetDeviceInfo:\n");
printf("Device Name : %s\n", vl53l0x_dev_info.Name); //設(shè)備名
printf("Device Type : %s\n", vl53l0x_dev_info.Type); //產(chǎn)品類型VL53L0X = 1, VL53L1 = 2
printf("Device ID : %s\n", vl53l0x_dev_info.ProductId); // 設(shè)備ID
printf("ProductRevisionMajor : %d\n", vl53l0x_dev_info.ProductRevisionMajor);
printf("ProductRevisionMinor : %d\n", vl53l0x_dev_info.ProductRevisionMinor);
if ((vl53l0x_dev_info.ProductRevisionMajor != 1) && (vl53l0x_dev_info.ProductRevisionMinor != 1)){
printf("Error expected cut 1.1 but found cut %d.%d\n",
vl53l0x_dev_info.ProductRevisionMajor, vl53l0x_dev_info.ProductRevisionMinor);
Status = VL53L0X_ERROR_NOT_SUPPORTED;
print_pal_error(Status);
return Status;
}
Status = vl53l0x_measure_init(pMyDevice); //測(cè)量配置
vl53l0x_status = Status;
if(Status != VL53L0X_ERROR_NONE){ //判斷如果不為0打印錯(cuò)誤信息
print_pal_error(Status);
return Status;
}
return Status; //返回0
}
復(fù)制代碼
全部資料51hei下載地址:
VL53L0X激光測(cè)距傳感器.7z
(449.71 KB, 下載次數(shù): 76)
2020-2-21 00:02 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
苦味單片機(jī)
時(shí)間:
2020-3-1 21:21
謝謝大佬,請(qǐng)問有sstm32f4的激光測(cè)距程序嗎
作者:
做夢(mèng)的孩子
時(shí)間:
2023-4-6 16:17
他這個(gè)現(xiàn)象是什么
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1