{"id":80,"date":"2021-07-22T15:13:00","date_gmt":"2021-07-22T15:13:00","guid":{"rendered":"https:\/\/zhewana.cn\/?p=80"},"modified":"2021-07-22T15:13:00","modified_gmt":"2021-07-22T15:13:00","slug":"80","status":"publish","type":"post","link":"https:\/\/zhewana.cn\/?p=80","title":{"rendered":"VL53L0X\u6a21\u5757\u7b14\u8bb0"},"content":{"rendered":"<blockquote>\n<p>\u6709\u5173\u6a21\u5757\u5b66\u4e60\u7684\u8d44\u6599\u5df2\u7ecf\u6574\u7406\u540e\u4e0a\u4f20\u4e86\uff1a<\/p>\n<p><a href=\"https:\/\/wws.lanzoui.com\/izIHArp85pa\">https:\/\/wws.lanzoui.com\/izIHArp85pa<\/a><\/p>\n<p>\u5bc6\u7801:ayr4<\/p>\n<\/blockquote>\n<h2>\u6a21\u5757\u4ecb\u7ecd<\/h2>\n<p><del>VL53L0\u662f\u4e00\u6b3e\u610f\u6cd5\u534a\u5bfc\u4f53\u63a8\u51fa\u7684\u6fc0\u5149\u6d4b\u8ddd\u6a21\u5757<\/del><\/p>\n<p>\u679c\u7136\u8fd8\u662f\u590d\u5236\u5b98\u65b9\u7684\u8bf4\u6cd5\u6bd4\u8f83\u9760\u8c31\uff1a<\/p>\n<blockquote>\n<p>\u4ee5\u4e0b\u5185\u5bb9\u6765\u81ea\u6570\u636e\u624b\u518c\u201cDescription\u201d\u548c\u67d0\u7ffb\u8bd1<\/p>\n<p>The VL53L0X is a new generation Time-of-Flight (ToF) laser-ranging module housed in the smallest package on the market today, providing accurate distance measurement whatever the target reflectances unlike conventional technologies. It can measure absolute distances up to 2m, setting a new benchmark in ranging performance levels, opening the door to various new applications.<\/p>\n<p>VL53L0X\u662f\u65b0\u4e00\u4ee3\u7684\u98de\u884c\u65f6\u95f4\uff08ToF\uff09\u6fc0\u5149\u6d4b\u8ddd\u6a21\u5757\uff0c\u91c7\u7528\u5f53\u4eca\u5e02\u573a\u4e0a\u6700\u5c0f\u7684\u5c01\u88c5\uff0c\u4e0e\u4f20\u7edf\u6280\u672f\u4e0d\u540c\uff0c\u65e0\u8bba\u76ee\u6807\u53cd\u5c04\u5982\u4f55\uff0c\u90fd\u80fd\u63d0\u4f9b\u7cbe\u786e\u7684\u8ddd\u79bb\u6d4b\u91cf\u3002\u5b83\u53ef\u4ee5\u6d4b\u91cf\u9ad8\u8fbe2\u7c73\u7684\u7edd\u5bf9\u8ddd\u79bb\uff0c\u4e3a\u6027\u80fd\u6c34\u5e73\u7684\u8303\u56f4\u8bbe\u5b9a\u4e86\u65b0\u7684\u57fa\u51c6\uff0c\u4e3a\u5404\u79cd\u65b0\u7684\u5e94\u7528\u6253\u5f00\u4e86\u5927\u95e8\u3002<\/p>\n<p>The VL53L0X integrates a leading-edge SPAD array (Single Photon Avalanche Diodes) and embeds ST\u2019s second generation FlightSenseTM patented technology.<\/p>\n<p>VL53L0X\u96c6\u6210\u4e86\u5148\u8fdb\u7684SPAD\u9635\u5217\uff08\u5355\u5149\u5b50\u96ea\u5d29\u4e8c\u6781\u7ba1\uff09\uff0c\u5e76\u5d4c\u5165ST\u7684\u7b2c\u4e8c\u4ee3FlightSenseTM\u4e13\u5229\u6280\u672f\u3002<\/p>\n<p>The VL53L0X\u2019s 940nm VCSEL emitter (Vertical Cavity Surface-Emitting Laser), is totally invisible to the human eye, coupled with internal physical infrared filters, it enables longer ranging distance, higher immunity to ambient light and better robustness to cover-glass optical cross-talk.  <\/p>\n<p>VL53L0X\u7684940nm VCSEL\u53d1\u5c04\u5668\uff08\u5782\u76f4\u8154\u9762\u53d1\u5c04\u6fc0\u5149\u5668\uff09\u5bf9\u4eba\u773c\u5b8c\u5168\u4e0d\u53ef\u89c1\uff0c\u518d\u52a0\u4e0a\u5185\u90e8\u7269\u7406\u7ea2\u5916\u6ee4\u5149\u7247\uff0c\u5b83\u53ef\u4ee5\u5b9e\u73b0\u66f4\u957f\u7684\u6d4b\u8ddd\u8ddd\u79bb\u3001\u66f4\u9ad8\u7684\u73af\u5883\u5149\u514d\u75ab\u529b\u548c\u66f4\u597d\u7684\u9c81\u68d2\u6027\uff0c\u4ee5\u8986\u76d6\u73bb\u7483\u5149\u5b66\u4e32\u6270\u3002<\/p>\n<\/blockquote>\n<p>\u9644\u6a21\u5757\u539f\u7406\u56fe\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/210403525.jpg\" alt=\"53l0x_SCH\" title=\"53l0x_SCH\"><\/p>\n<h3>\u901a\u4fe1\u63a5\u53e3\u53ca\u5f15\u811a\u5b9a\u4e49<\/h3>\n<p>\u6a21\u5757\u91c7\u7528IIC\u901a\u4fe1\uff0c\u6545\uff1a<\/p>\n<p><strong>SCL\uff1aIIC\u65f6\u949f\u7ebf<\/strong><\/p>\n<p><strong>SDA\uff1aIIC\u6570\u636e\u7ebf<\/strong><\/p>\n<p>\u6b64\u5916\uff1a<\/p>\n<p><strong>VIN\uff1a\u7535\u6e90<\/strong><\/p>\n<p><strong>GND\uff1a\u63a5\u5730<\/strong><\/p>\n<p><strong>XShut\uff1a\u8bbe\u5907\u5524\u9192\u5f15\u811a<\/strong><\/p>\n<blockquote>\n<p>PS\uff1aXShut\u7684\u63a5\u7ebf\u65b9\u6cd5\u51b3\u5b9a\u4e86\u8bbe\u5907\u7684\u6d4b\u91cf\u6a21\u5f0f\uff0c\u5f15\u7528\u624b\u518c\u4e2d\u7684\u8bf4\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>There are two options available for device power up\/boot.<\/p>\n<p>Option 1: <\/p>\n<p><strong>XSHUT pin connected and controlled from host.<\/strong>This option helps to optimize power consumption as the VL53L0X can be completely powered off when not used, and then woken up through host GPIO (using XSHUT pin).<\/p>\n<p>HW Standby mode is defined as the period when AVDD is present and XSHUT is low.  <\/p>\n<p>Option 2: <\/p>\n<p><strong>XSHUT pin not controlled by host, and tied to AVDD through pull-up resistor.<\/strong><\/p>\n<p>In case XSHUT pin is not controlled, the power up sequence is presented in Figure 11. In this case, the device is going automatically in SW STANDBY after FW BOOT, without entering HW STANDBY.<\/p>\n<\/blockquote>\n<p><strong>GPIO1\uff1a\u4e2d\u65ad\u8f93\u51fa<\/strong><\/p>\n<blockquote>\n<p>PS\uff1aGPIO1\u4e3a\u4e2d\u65ad\u8f93\u51fa\uff0c\u5728\u624b\u518c\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u5f53\u91c7\u7528\u4e2d\u65ad\u6d4b\u91cf\u6a21\u5f0f\u7684\u65f6\u5019\uff0c\u6bcf\u6b21\u5f53\u8bbe\u5907\u51c6\u5907\u5c31\u7eea\u8fdb\u884c\u65b0\u7684\u6d4b\u91cf\u65f6\uff0c\u4e2d\u65ad\u5f15\u811a\u5c31\u4f1a\u8fdb\u884c\u8f93\u51fa\u6765\u89e6\u53d1\u4e3b\u673a\u7684\u4e2d\u65ad\uff0c\u624b\u518c\u4e2d\u8bf4\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>Interrupt mode: An interrupt pin (GPIO1) sends an interrupt to the host when a new measurement is available.<\/p>\n<\/blockquote>\n<h2>API<\/h2>\n<p>\u5bf9\u4e8e\u8be5\u6a21\u5757\uff0c\u4e0d\u5f97\u4e0d\u63d0\u7684\u4e8b\u60c5\u5c31\u662f\u5b98\u65b9\u4e3a\u5176\u5199\u4e86\u4e00\u4e2aAPI\u5e93\u53ef\u4ee5\u65b9\u4fbf\u6211\u4eec\u7684\u5e94\u7528\u5c42\u5f00\u53d1\uff0c\u800c\u6211\u4eec\u7684\u4efb\u52a1\u5c31\u662f\u8fdb\u884c\u8be5\u5e93\u7684\u79fb\u690d\u3002<\/p>\n<p>\u672c\u6765\u8fd9\u4e2a\u5e93\u7684\u6700\u5927\u96be\u70b9\u5c31\u5728\u4e8e\u79fb\u690d\uff0c\u4f46\u662f\u5728\u7f51\u4e0a\u6211\u627e\u5230\u4e86\u6709\u4eba\u505a\u8fc7\u4e86HAL\u5e93\u7684\u79fb\u690d\u7248\u672c\uff0c\u56e0\u6b64\u6211\u4eec\u81ea\u5df1\u5c31\u4e0d\u518d\u505aHAL\u79fb\u690d\u4e86\u3002\u4f46\u662f\u4e3a\u4e86\u65b9\u4fbf\u81ea\u5df1\u4ee5\u540e\u5728\u5176\u4ed6\u7684\u5e73\u53f0\u4e0a\u8fdb\u884c\u5f00\u53d1\uff0c\u6211\u8fd8\u662f\u4f1a\u5bf9\u6bd4\u5df2\u7ecf\u79fb\u690d\u5b8c\u7684\u51fd\u6570\u5e93\u8fdb\u884c\u4e00\u6b21\u79fb\u690d\uff0c\u8fd9\u6bb5\u5185\u5bb9\u5c31\u653e\u5728\u540e\u9762\u4e86\u3002<\/p>\n<p>\u6211\u4eec\u9996\u5148\u6765\u8bf4API\u51fd\u6570\u5e93\uff1a<\/p>\n<h3>\u6d4b\u91cf\u6570\u636e\u7ed3\u6784\u4f53<\/h3>\n<p>\u7ed3\u6784\u4f53\u6e90\u7801\u5982\u4e0b\uff0c\u5404\u4e2a\u53d8\u91cf\u7684\u542b\u4e49\u5747\u5728\u5e93\u51fd\u6570\u4e2d\u6709\u6240\u63d0\u53ca\uff1a<\/p>\n<pre><code class=\"lang-C\">typedef struct {\n    uint32_t TimeStamp;        \/*!&lt; 32-bit time stamp. *\/\n    uint32_t MeasurementTimeUsec;\n        \/*!&lt; Give the Measurement time needed by the device to do the\n         * measurement.*\/\n\n\n    uint16_t RangeMilliMeter;    \/*!&lt; range distance in millimeter. *\/\n\n    uint16_t RangeDMaxMilliMeter;\n        \/*!&lt; Tells what is the maximum detection distance of the device\n         * in current setup and environment conditions (Filled when\n         *    applicable) *\/\n\n    FixPoint1616_t SignalRateRtnMegaCps;\n        \/*!&lt; Return signal rate (MCPS)\\n these is a 16.16 fix point\n         *    value, which is effectively a measure of target\n         *     reflectance.*\/\n    FixPoint1616_t AmbientRateRtnMegaCps;\n        \/*!&lt; Return ambient rate (MCPS)\\n these is a 16.16 fix point\n         *    value, which is effectively a measure of the ambien\n         *    t light.*\/\n\n    uint16_t EffectiveSpadRtnCount;\n        \/*!&lt; Return the effective SPAD count for the return signal.\n         *    To obtain Real value it should be divided by 256 *\/\n\n    uint8_t ZoneId;\n        \/*!&lt; Denotes which zone and range scheduler stage the range\n         *    data relates to. *\/\n    uint8_t RangeFractionalPart;\n        \/*!&lt; Fractional part of range distance. Final value is a\n         *    FixPoint168 value. *\/\n    uint8_t RangeStatus;\n        \/*!&lt; Range Status for the current measurement. This is device\n         *    dependent. Value = 0 means value is valid.\n         *    See \\ref RangeStatusPage *\/\n} VL53L0X_RangingMeasurementData_t;<\/code><\/pre>\n<p>\u5728\u4f7f\u7528\u4e4b\u524d\u5e94\u8be5\u5b9a\u4e49\u4e00\u4e2a\u7528\u4e8e\u6d4b\u91cf\u6570\u636e\u5b58\u50a8\u7684\u7ed3\u6784\u4f53\u53d8\u91cf\u4ee5\u4f9b\u540e\u7eed\u51fd\u6570\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"lang-C\">VL53L0X_RangingMeasurementData_t RangingData;<\/code><\/pre>\n<blockquote>\n<p>\u5176\u4e2dRangeMilliMeter\u4e3a\u6211\u4eec\u671f\u671b\u7684\u6d4b\u91cf\u8ddd\u79bb\u503c\uff0c\u5355\u4f4d\uff1amm<\/p>\n<\/blockquote>\n<h3>\u8bbe\u5907\u7ed3\u6784\u4f53<\/h3>\n<p>\u8bbe\u5907\u7ed3\u6784\u4f53\u662fAPI\u51fd\u6570\u5e93\u548c\u6240\u7528\u5e73\u53f0\u4e4b\u95f4\u8fde\u63a5\u7684\u7ebd\u5e26<del>\uff08\u53cd\u6b63\u624b\u518c\u662f\u8fd9\u4e48\u8bf4\u7684\uff09<\/del>\uff0c\u7ed3\u6784\u4f53\u6e90\u7801\u5982\u4e0b\uff0c\u53d8\u91cf\u542b\u4e49\u5df2\u7ecf\u5728\u6e90\u7801\u4e2d\u7ed9\u51fa\uff1a<\/p>\n<pre><code class=\"lang-C\">typedef struct {\n    VL53L0X_DevData_t Data;               \/*!&lt; embed ST Ewok Dev  data as &quot;Data&quot;*\/\n\n    \/*!&lt; user specific field *\/\n\n    I2C_HandleTypeDef *I2cHandle;\n    uint8_t   I2cDevAddr;\n\n    char    DevLetter;\n\n    int     Id;\n    int     Present;\n    int     Enabled;\n    int        Ready;\n\n    uint8_t   comms_type;\n    uint16_t  comms_speed_khz;\n\n    int LeakyRange;\n    int LeakyFirst;\n    uint8_t RangeStatus;\n    uint8_t PreviousRangeStatus;\n    FixPoint1616_t SignalRateRtnMegaCps;\n    uint16_t EffectiveSpadRtnCount;\n    uint32_t StartTime;\n\n} VL53L0X_Dev_t;\n<\/code><\/pre>\n<p>\u5728\u4f7f\u7528\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u8bbe\u5907\u7ed3\u6784\u4f53\u53d8\u91cf\u4ee5\u4f9b\u540e\u7eed\u51fd\u6570\u4f7f\u7528\uff0c\u540c\u65f6\u8981\u5728\u5b9a\u4e49\u65f6\u5c06I2C\u53e5\u67c4\uff08&hi2c1\uff09\u4ee5\u53caI2C\u8bbe\u5907\u5730\u5740\uff080x52\uff09\u8d4b\u503c:<\/p>\n<pre><code class=\"lang-C\">VL53L0X_Dev_t Dev = {\n        .I2cHandle=&amp;hi2c1,\n        .I2cDevAddr=0x52\n};<\/code><\/pre>\n<blockquote>\n<p>PS:\u4f17\u6240\u5468\u77e5\uff0cHAL\u5e93\u4f7f\u7528\u7684\u662f8\u4f4d\u5730\u5740\uff0c\u56e0\u6b64\u624b\u518c\u4e2d\u76847\u4f4d\u5730\u5740\u9700\u8981\u5de6\u79fb\u4e00\u4f4d\u624d\u80fd\u88ab\u6b63\u786e\u8bfb\u53d6\uff0c\u4f46\u662f\u4e3a\u4ec0\u4e480x52\u6ca1\u6709\u5de6\u79fb\u5462\uff1f<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1350362884.png\" alt=\"image-20210722112409582.png\" title=\"image-20210722112409582.png\"><\/p>\n<p>\u56e0\u4e3a\u663e\u7136\u5b83\u5728\u624b\u518c\u4e2d\u4f7f\u7528\u7684\u5c31\u662f8\u4f4d\u5730\u5740\u683c\u5f0f\uff08\u6700\u540e\u4e00\u4f4d\u4e3a\u8bfb\u5199\u4f4d\uff09\u3002<\/p>\n<\/blockquote>\n<h3>\u91cd\u547d\u540d\u7684\u53d8\u91cf<\/h3>\n<p>API\u4e2d\u5927\u90e8\u5206\u51fd\u6570\u8fd4\u56de\u503c\u5747\u4e3aVL53L0X_Error\u7c7b\u578b\uff0c\u8fd9\u4e2a\u7c7b\u578b\u5176\u5b9e\u662f\u5bf9\u4e8e\u6709\u7b26\u53f7\u5b57\u7b26\u578b\u7684\u91cd\u547d\u540d\uff1a<\/p>\n<pre><code class=\"lang-C\">typedef int8_t VL53L0X_Error;<\/code><\/pre>\n<p>\u4e3a\u4e86\u4fdd\u8bc1\u7c7b\u578b\u7684\u4e00\u81f4\u6027\uff0c\u6240\u4ee5\u5728\u8c03\u8bd5\u770b\u8fd4\u56de\u503c\u7684\u65f6\u5019\u53ef\u4ee5\u540c\u6837\u7528\u8fd9\u4e2a\u7c7b\u578b\u6765\u5b9a\u4e49\u53d8\u91cf\u6765\u5b58\u50a8\u8fd4\u56de\u7684\u9519\u8bef\u4fe1\u606f\uff1a<\/p>\n<pre><code class=\"lang-c\">VL53L0X_Error re = 0;<\/code><\/pre>\n<h3>API\u5e38\u7528\u51fd\u6570<\/h3>\n<h4>\u8bbe\u5907\u521d\u59cb\u5316\u9636\u6bb5<\/h4>\n<p>API\u51fd\u6570\u5e93\u91cc\u9762\u7684\u5e94\u7528\u51fd\u6570\u5f88\u5168\uff0c\u4f46\u662f\u6211\u4eec\u5176\u5b9e\u4e5f\u53ea\u4f1a\u7528\u5230\u5176\u4e2d\u7684\u5f88\u5c0f\u4e00\u90e8\u5206\uff0c\u4e0b\u9762\u6839\u636e\u8c03\u7528\u987a\u5e8f\u4e00\u4e00\u5217\u4e3e\uff1a<\/p>\n<pre><code class=\"lang-C\">\/**\n * @brief Wait for device booted after chip enable (hardware standby)\n * This function can be run only when VL53L0X_State is VL53L0X_STATE_POWERDOWN.\n *\n * @note This function is not Implemented\n *\n * @param   Dev      Device Handle\n * @return  VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented\n *\n *\/\nVL53L0X_API VL53L0X_Error VL53L0X_WaitDeviceBooted(VL53L0X_DEV Dev);<\/code><\/pre>\n<blockquote>\n<p>\u7b49\u5f85\u8bbe\u5907\u542f\u52a8<\/p>\n<\/blockquote>\n<hr>\n<pre><code class=\"lang-C\">\/**\n *\n * @brief One time device initialization\n *\n * To be called once and only once after device is brought out of reset\n * (Chip enable) and booted see @a VL53L0X_WaitDeviceBooted()\n *\n * @par Function Description\n * When not used after a fresh device &quot;power up&quot; or reset, it may return\n * @a #VL53L0X_ERROR_CALIBRATION_WARNING meaning wrong calibration data\n * may have been fetched from device that can result in ranging offset error\\n\n * If application cannot execute device reset or need to run VL53L0X_DataInit\n * multiple time then it  must ensure proper offset calibration saving and\n * restore on its own by using @a VL53L0X_GetOffsetCalibrationData() on first\n * power up and then @a VL53L0X_SetOffsetCalibrationData() in all subsequent init\n * This function will change the VL53L0X_State from VL53L0X_STATE_POWERDOWN to\n * VL53L0X_STATE_WAIT_STATICINIT.\n *\n * @note This function Access to the device\n *\n * @param   Dev                   Device Handle\n * @return  VL53L0X_ERROR_NONE     Success\n * @return  &quot;Other error code&quot;    See ::VL53L0X_Error\n *\/\nVL53L0X_API VL53L0X_Error VL53L0X_DataInit(VL53L0X_DEV Dev);<\/code><\/pre>\n<blockquote>\n<p>\u8bbe\u5907\u521d\u59cb\u5316\u51fd\u6570<\/p>\n<p>\u6ce8\u610f\uff1a\u53ea\u80fd\u88ab\u8c03\u7528\u4e00\u6b21\uff01<\/p>\n<\/blockquote>\n<hr>\n<pre><code class=\"lang-C\">\/**\n * @brief Do basic device init (and eventually patch loading)\n * This function will change the VL53L0X_State from\n * VL53L0X_STATE_WAIT_STATICINIT to VL53L0X_STATE_IDLE.\n * In this stage all default setting will be applied.\n *\n * @note This function Access to the device\n *\n * @param   Dev                   Device Handle\n * @return  VL53L0X_ERROR_NONE     Success\n * @return  &quot;Other error code&quot;    See ::VL53L0X_Error\n *\/\nVL53L0X_API VL53L0X_Error VL53L0X_StaticInit(VL53L0X_DEV Dev);<\/code><\/pre>\n<blockquote>\n<p>\u8fdb\u884c\u57fa\u7840\u8bbe\u5907\u521d\u59cb\u5316<\/p>\n<\/blockquote>\n<hr>\n<pre><code class=\"lang-C\">\/**\n * @brief Perform Reference Calibration\n *\n * @details Perform a reference calibration of the Device.\n * This function should be run from time to time before doing\n * a ranging measurement.\n * This function will launch a special ranging measurement, so\n * if interrupt are enable an interrupt will be done.\n * This function will clear the interrupt generated automatically.\n *\n * @warning This function is a blocking function\n *\n * @note This function Access to the device\n *\n * @param   Dev                  Device Handle\n * @param   pVhvSettings         Pointer to vhv settings parameter.\n * @param   pPhaseCal            Pointer to PhaseCal parameter.\n * @return  VL53L0X_ERROR_NONE    Success\n * @return  &quot;Other error code&quot;   See ::VL53L0X_Error\n *\/\nVL53L0X_API VL53L0X_Error VL53L0X_PerformRefCalibration(VL53L0X_DEV Dev,\n    uint8_t *pVhvSettings, uint8_t *pPhaseCal);<\/code><\/pre>\n<blockquote>\n<p>\u5bf9\u8bbe\u5907\u6267\u884c\u6821\u51c6<\/p>\n<\/blockquote>\n<hr>\n<pre><code class=\"lang-C\">\/**\n * @brief Set Reference Calibration Parameters\n *\n * @par Function Description\n * Set Reference Calibration Parameters.\n *\n * @note This function Access to the device\n *\n * @param   Dev                            Device Handle\n * @param   VhvSettings                    Parameter for VHV\n * @param   PhaseCal                       Parameter for PhaseCal\n * @return  VL53L0X_ERROR_NONE              Success\n * @return  &quot;Other error code&quot;             See ::VL53L0X_Error\n *\/\nVL53L0X_API VL53L0X_Error VL53L0X_SetRefCalibration(VL53L0X_DEV Dev,\n    uint8_t VhvSettings, uint8_t PhaseCal);<\/code><\/pre>\n<blockquote>\n<p>\u5bf9\u6821\u51c6\u4e2d\u83b7\u5f97\u7684\u53c2\u6570\u8fdb\u884c\u8bbe\u7f6e\u4ee5\u5b8c\u6210\u8bbe\u5907\u7684\u6821\u51c6<\/p>\n<\/blockquote>\n<hr>\n<pre><code class=\"lang-C\">\/**\n * @brief Performs Reference Spad Management\n *\n * @par Function Description\n * The reference SPAD initialization procedure determines the minimum amount\n * of reference spads to be enables to achieve a target reference signal rate\n * and should be performed once during initialization.\n *\n * @note This function Access to the device\n *\n * @note This function change the device mode to\n * VL53L0X_DEVICEMODE_SINGLE_RANGING\n *\n * @param   Dev                          Device Handle\n * @param   refSpadCount                 Reports ref Spad Count\n * @param   isApertureSpads              Reports if spads are of type\n *                                       aperture or non-aperture.\n *                                       1:=aperture, 0:=Non-Aperture\n * @return  VL53L0X_ERROR_NONE            Success\n * @return  VL53L0X_ERROR_REF_SPAD_INIT   Error in the Ref Spad procedure.\n * @return  &quot;Other error code&quot;           See ::VL53L0X_Error\n *\/\nVL53L0X_API VL53L0X_Error VL53L0X_PerformRefSpadManagement(VL53L0X_DEV Dev,\n    uint32_t *refSpadCount, uint8_t *isApertureSpads);<\/code><\/pre>\n<hr>\n<pre><code class=\"lang-C\">\/**\n * @brief  Set a new device mode\n * @par Function Description\n * Set device to a new mode (ranging, histogram ...)\n *\n * @note This function doesn't Access to the device\n *\n * @param   Dev                   Device Handle\n * @param   DeviceMode            New device mode to apply\n *                                Valid values are:\n *                                VL53L0X_DEVICEMODE_SINGLE_RANGING\n *                                VL53L0X_DEVICEMODE_CONTINUOUS_RANGING\n *                                VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING\n *                                VL53L0X_DEVICEMODE_SINGLE_HISTOGRAM\n *                                VL53L0X_HISTOGRAMMODE_REFERENCE_ONLY\n *                                VL53L0X_HISTOGRAMMODE_RETURN_ONLY\n *                                VL53L0X_HISTOGRAMMODE_BOTH\n *\n *\n * @return  VL53L0X_ERROR_NONE               Success\n * @return  VL53L0X_ERROR_MODE_NOT_SUPPORTED This error occurs when DeviceMode is\n *                                          not in the supported list\n *\/\nVL53L0X_API VL53L0X_Error VL53L0X_SetDeviceMode(VL53L0X_DEV Dev,\n    VL53L0X_DeviceModes DeviceMode);<\/code><\/pre>\n<blockquote>\n<p>\u8bbe\u5b9a\u8bbe\u5907\u5de5\u4f5c\u6a21\u5f0f<\/p>\n<\/blockquote>\n<hr>\n<pre><code class=\"lang-C\">\/**\n * @brief Start device measurement\n *\n * @details Started measurement will depend on device parameters set through\n * @a VL53L0X_SetParameters()\n * This is a non-blocking function.\n * This function will change the VL53L0X_State from VL53L0X_STATE_IDLE to\n * VL53L0X_STATE_RUNNING.\n *\n * @note This function Access to the device\n *\n\n * @param   Dev                  Device Handle\n * @return  VL53L0X_ERROR_NONE                  Success\n * @return  VL53L0X_ERROR_MODE_NOT_SUPPORTED    This error occurs when\n * DeviceMode programmed with @a VL53L0X_SetDeviceMode is not in the supported\n * list:\n *                                   Supported mode are:\n *                                   VL53L0X_DEVICEMODE_SINGLE_RANGING,\n *                                   VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,\n *                                   VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING\n * @return  VL53L0X_ERROR_TIME_OUT    Time out on start measurement\n * @return  &quot;Other error code&quot;   See ::VL53L0X_Error\n *\/\nVL53L0X_API VL53L0X_Error VL53L0X_StartMeasurement(VL53L0X_DEV Dev);<\/code><\/pre>\n<blockquote>\n<p>\u5f00\u59cb\u6267\u884c\u6d4b\u91cf<\/p>\n<\/blockquote>\n<hr>\n<h4>\u6d4b\u91cf\u9636\u6bb5<\/h4>\n<pre><code class=\"lang-C\">\/**\n * @brief Retrieve the measurements from device for a given setup\n *\n * @par Function Description\n * Get data from last successful Ranging measurement\n * @warning USER should take care about  @a VL53L0X_GetNumberOfROIZones()\n * before get data.\n * PAL will fill a NumberOfROIZones times the corresponding data\n * structure used in the measurement function.\n *\n * @note This function Access to the device\n *\n * @param   Dev                      Device Handle\n * @param   pRangingMeasurementData  Pointer to the data structure to fill up.\n * @return  VL53L0X_ERROR_NONE        Success\n * @return  &quot;Other error code&quot;       See ::VL53L0X_Error\n *\/\nVL53L0X_API VL53L0X_Error VL53L0X_GetRangingMeasurementData(VL53L0X_DEV Dev,\n    VL53L0X_RangingMeasurementData_t *pRangingMeasurementData);<\/code><\/pre>\n<blockquote>\n<p>\u83b7\u53d6\u6d4b\u91cf\u503c<\/p>\n<\/blockquote>\n<h4>\u6a21\u5757\u5de5\u4f5c\u6d41\u7a0b<\/h4>\n<p>\u5728\u6570\u636e\u624b\u518c\u4e2d\u5176\u5b9e\u7ed3\u5408API\u51fd\u6570\u5e93\u7ed9\u51fa\u4e86\u6a21\u5757\u63a8\u8350\u7684\u5de5\u4f5c\u6d41\u7a0b\uff0c\u5982\u4e0b\uff1a<\/p>\n<p>\u9996\u5148\u662f\u521d\u59cb\u5316\u6d41\u7a0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/904909696.png\" alt=\"\u6fc0\u5149\u6d4b\u8ddd\u521d\u59cb\u5316\u6d41\u7a0b-1626938862721.png\" title=\"\u6fc0\u5149\u6d4b\u8ddd\u521d\u59cb\u5316\u6d41\u7a0b-1626938862721.png\"><\/p>\n<p>\u63a5\u4e0b\u6765\u662f\u6d4b\u91cf\u6d41\u7a0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3867581705.png\" alt=\"\u6fc0\u5149\u6d4b\u8ddd\u6d4b\u91cf\u6d41\u7a0b-1626938867288.png\" title=\"\u6fc0\u5149\u6d4b\u8ddd\u6d4b\u91cf\u6d41\u7a0b-1626938867288.png\"><\/p>\n<p>API\u4f7f\u7528\u4e3e\u4f8b\uff08main.c\uff09\uff1a<\/p>\n<p><strong>\u73af\u5883\uff1aSTM32F401CCU6+CubeMX+HAL<\/strong><\/p>\n<p>\u5728100Hz\u5b9a\u65f6\u5668\u4e2d\u8fdb\u884c\u6d4b\u91cf\uff0c\u5e76\u5c06\u6d4b\u91cf\u6807\u5fd7\u4f4d\u7f6e\u4e00\uff0c\u7136\u540e\u5728\u4e3b\u5faa\u73af\u4e2d\u5c06\u83b7\u5f97\u7684\u6d4b\u91cf\u6570\u636e\u4f7f\u7528\u4e32\u53e3\u6253\u5370\u51fa\u6765\u3002<\/p>\n<pre><code class=\"lang-C\">\/* USER CODE BEGIN Header *\/\n\/**\n  ******************************************************************************\n  * @file           : main.c\n  * @brief          : Main program body\n  ******************************************************************************\n  * @attention\n  *\n  * &lt;h2&gt;&lt;center&gt;&amp;copy; Copyright (c) 2021 STMicroelectronics.\n  * All rights reserved.&lt;\/center&gt;&lt;\/h2&gt;\n  *\n  * This software component is licensed by ST under BSD 3-Clause license,\n  * the &quot;License&quot;; You may not use this file except in compliance with the\n  * License. You may obtain a copy of the License at:\n  *                        opensource.org\/licenses\/BSD-3-Clause\n  *\n  ******************************************************************************\n  *\/\n\/* USER CODE END Header *\/\n\/* Includes ------------------------------------------------------------------*\/\n#include &quot;main.h&quot;\n#include &quot;i2c.h&quot;\n#include &quot;tim.h&quot;\n#include &quot;usart.h&quot;\n#include &quot;gpio.h&quot;\n\n\/* Private includes ----------------------------------------------------------*\/\n\/* USER CODE BEGIN Includes *\/\n#include &quot;stdarg.h&quot;\n#include &quot;stdio.h&quot;\n#include &quot;vl53l0x_api.h&quot;\n\/* USER CODE END Includes *\/\n\n\/* Private typedef -----------------------------------------------------------*\/\n\/* USER CODE BEGIN PTD *\/\n\n\/* USER CODE END PTD *\/\n\n\/* Private define ------------------------------------------------------------*\/\n\/* USER CODE BEGIN PD *\/\n\/* USER CODE END PD *\/\n\n\/* Private macro -------------------------------------------------------------*\/\n\/* USER CODE BEGIN PM *\/\n#define log UART_printf\n\/* USER CODE END PM *\/\n\n\/* Private variables ---------------------------------------------------------*\/\n\n\/* USER CODE BEGIN PV *\/\nVL53L0X_RangingMeasurementData_t RangingData;\nVL53L0X_Dev_t Dev = {\n        .I2cHandle=&amp;hi2c1,\n        .I2cDevAddr=0x52\n};\nvolatile uint8_t TofDataRead;\n\/* USER CODE END PV *\/\n\n\/* Private function prototypes -----------------------------------------------*\/\nvoid SystemClock_Config(void);\n\n\/* USER CODE BEGIN PFP *\/\nint UART_printf(UART_HandleTypeDef *huart, const char *fmt, ...);\n\nVL53L0X_Error re = 0;\n\/* USER CODE END PFP *\/\n\n\/* Private user code ---------------------------------------------------------*\/\n\/* USER CODE BEGIN 0 *\/\n\n\/* USER CODE END 0 *\/\n\n\/**\n  * @brief  The application entry point.\n  * @retval int\n  *\/\nint main(void) {\n    \/* USER CODE BEGIN 1 *\/\n    uint32_t refSpadCount;\n    uint8_t isApertureSpads;\n    uint8_t VhvSettings;\n    uint8_t PhaseCal;\n    \/* USER CODE END 1 *\/\n\n    \/* MCU Configuration--------------------------------------------------------*\/\n\n    \/* Reset of all peripherals, Initializes the Flash interface and the Systick. *\/\n    HAL_Init();\n\n    \/* USER CODE BEGIN Init *\/\n\n    \/* USER CODE END Init *\/\n\n    \/* Configure the system clock *\/\n    SystemClock_Config();\n\n    \/* USER CODE BEGIN SysInit *\/\n\n    \/* USER CODE END SysInit *\/\n\n    \/* Initialize all configured peripherals *\/\n    MX_GPIO_Init();\n    MX_I2C1_Init();\n    MX_TIM3_Init();\n    MX_USART1_UART_Init();\n    \/* USER CODE BEGIN 2 *\/\n    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); \/\/ Disable XSHUT\n    HAL_Delay(20);\n    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); \/\/ Enable XSHUT\n    HAL_Delay(20);\n\n    HAL_NVIC_DisableIRQ(TIM3_IRQn);\n\n    re = VL53L0X_WaitDeviceBooted(&amp;Dev);\n    log(&amp;huart1, &quot;%d\\n&quot;, re);\n    re = VL53L0X_DataInit(&amp;Dev);\n    log(&amp;huart1, &quot;%d\\n&quot;, re);\n    re = VL53L0X_StaticInit(&amp;Dev);\n    log(&amp;huart1, &quot;%d\\n&quot;, re);\n    re = VL53L0X_PerformRefCalibration(&amp;Dev, &amp;VhvSettings, &amp;PhaseCal);\n    log(&amp;huart1, &quot;%d\\n&quot;, re);\n    re = VL53L0X_SetRefCalibration(&amp;Dev, VhvSettings, PhaseCal);\n    log(&amp;huart1, &quot;%d\\n&quot;, re);\n    re = VL53L0X_PerformRefSpadManagement(&amp;Dev, &amp;refSpadCount, &amp;isApertureSpads);\n    log(&amp;huart1, &quot;%d\\n&quot;, re);\n    re = VL53L0X_SetDeviceMode(&amp;Dev, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING);\n    log(&amp;huart1, &quot;%d\\n&quot;, re);\n    re = VL53L0X_StartMeasurement(&amp;Dev);\n    log(&amp;huart1, &quot;%d\\n\\n&quot;, re);\n\n    HAL_NVIC_EnableIRQ(TIM3_IRQn);\n    \/* USER CODE END 2 *\/\n\n    \/* Infinite loop *\/\n    \/* USER CODE BEGIN WHILE *\/\n    HAL_TIM_Base_Start_IT(&amp;htim3);\n    while (1) {\n        if (TofDataRead == 1) {\n            log(&amp;huart1, &quot;Measured distance: %i\\n\\r&quot;, RangingData.RangeMilliMeter);\n            TofDataRead = 0;\n        }\n        \/* USER CODE END WHILE *\/\n\n        \/* USER CODE BEGIN 3 *\/\n    }\n    \/* USER CODE END 3 *\/\n}\n\n\/**\n  * @brief System Clock Configuration\n  * @retval None\n  *\/\nvoid SystemClock_Config(void) {\n    RCC_OscInitTypeDef RCC_OscInitStruct = {0};\n    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};\n\n    \/** Configure the main internal regulator output voltage\n    *\/\n    __HAL_RCC_PWR_CLK_ENABLE();\n    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);\n    \/** Initializes the RCC Oscillators according to the specified parameters\n    * in the RCC_OscInitTypeDef structure.\n    *\/\n    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;\n    RCC_OscInitStruct.HSEState = RCC_HSE_ON;\n    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;\n    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;\n    RCC_OscInitStruct.PLL.PLLM = 25;\n    RCC_OscInitStruct.PLL.PLLN = 168;\n    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;\n    RCC_OscInitStruct.PLL.PLLQ = 4;\n    if (HAL_RCC_OscConfig(&amp;RCC_OscInitStruct) != HAL_OK) {\n        Error_Handler();\n    }\n    \/** Initializes the CPU, AHB and APB buses clocks\n    *\/\n    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK\n                                  | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;\n    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;\n    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;\n    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;\n    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;\n\n    if (HAL_RCC_ClockConfig(&amp;RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {\n        Error_Handler();\n    }\n}\n\n\/* USER CODE BEGIN 4 *\/\nvoid HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {\n    if (htim3.Instance == TIM3) {\n        VL53L0X_GetRangingMeasurementData(&amp;Dev, &amp;RangingData);\n\/\/        VL53L0X_ClearInterruptMask(&amp;Dev, VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);\n        TofDataRead = 1;\n    }\n}\n\nint UART_printf(UART_HandleTypeDef *huart, const char *fmt, ...) {\n    va_list ap;\n    va_start(ap, fmt);\n\n    int length;\n    char buffer[128];\n\n    length = vsnprintf(buffer, 128, fmt, ap);\n\n    HAL_UART_Transmit(huart, (uint8_t *) buffer, length, HAL_MAX_DELAY);\n\n    va_end(ap);\n    return length;\n}\n\/* USER CODE END 4 *\/\n\n\/**\n  * @brief  This function is executed in case of error occurrence.\n  * @retval None\n  *\/\nvoid Error_Handler(void) {\n    \/* USER CODE BEGIN Error_Handler_Debug *\/\n    \/* User can add his own implementation to report the HAL error return state *\/\n    __disable_irq();\n    while (1) {\n    }\n    \/* USER CODE END Error_Handler_Debug *\/\n}\n\n#ifdef  USE_FULL_ASSERT\n\/**\n  * @brief  Reports the name of the source file and the source line number\n  *         where the assert_param error has occurred.\n  * @param  file: pointer to the source file name\n  * @param  line: assert_param error line source number\n  * @retval None\n  *\/\nvoid assert_failed(uint8_t *file, uint32_t line)\n{\n  \/* USER CODE BEGIN 6 *\/\n  \/* User can add his own implementation to report the file name and line number,\n     ex: printf(&quot;Wrong parameters value: file %s on line %d\\r\\n&quot;, file, line) *\/\n  \/* USER CODE END 6 *\/\n}\n#endif \/* USE_FULL_ASSERT *\/\n\n\/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****\/\n<\/code><\/pre>\n<h2>\u6ce8\u610f\u4e8b\u9879<\/h2>\n<blockquote>\n<ul>\n<li>\u8bbe\u5907\u521d\u59cb\u5316\u7684\u65f6\u5019\u4e0d\u8981\u5f00\u4e2d\u65ad\uff01\uff01\uff01<\/li>\n<li>\u6ce8\u610fXShut\u7684\u8fde\u63a5\u65b9\u5f0f\uff0c\u5982\u679c\u548c\u4e3b\u8bbe\u5907\u8fde\u63a5\u4e86\uff0c\u5219\u9700\u8981\u5728\u6d4b\u91cf\u4e4b\u524d\u8fdb\u884c\u5524\u9192\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<\/blockquote>\n<h2>\u5173\u4e8eAPI\u7684\u79fb\u690d<\/h2>\n<p>\u6316\u5751\uff0c\u4ee5\u540e\u586b......<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u5173\u6a21\u5757\u5b66\u4e60\u7684\u8d44\u6599\u5df2\u7ecf\u6574\u7406\u540e\u4e0a\u4f20\u4e86\uff1a https:\/\/wws.lanzoui.com\/izIHArp85pa  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[15,14],"class_list":["post-80","post","type-post","status-publish","format-standard","hentry","category-embedded","tag-vl53l0x","tag-14"],"_links":{"self":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts\/80","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=80"}],"version-history":[{"count":0,"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts\/80\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}