读取距离部分,程序卡在了while(!(VL6180X_ReadByte(VL6180X_REG_RESULT_RANGE_STATUS) & 0x01));循环中
//单位毫米
uint8_t VL6180X_Read_Range(void)
{
uint8_t range = 0;
//开启传输
while(!(VL6180X_ReadByte(VL6180X_REG_RESULT_RANGE_STATUS) & 0x01));
VL6180X_WriteByte(VL6180X_REG_SYSRANGE_START,0x01); //单次触发模式
//等待新样本就绪阈值事件(New Sample Ready threshold event)
while(!(VL6180X_ReadByte(VL6180X_REG_RESULT_INTERRUPT_STATUS_GPIO) & 0x04));
range = VL6180X_ReadByte(VL6180X_REG_RESULT_RANGE_VAL);
//获取完数据,清楚中断位
VL6180X_WriteByte(VL6180X_REG_SYSTEM_INTERRUPT_CLEAR,0x07); //0111b 清除了三种中断标志
return range;
}
编译未报错
将两个while循环注释掉,返回值一直为0xff,因此该办法无效
uint8_t VL6180X_Read_Range(void)函数可以返回有效值