{"id":119,"date":"2021-04-05T00:00:00","date_gmt":"2021-04-05T00:00:00","guid":{"rendered":"https:\/\/zhewana.cn\/?p=119"},"modified":"2021-04-05T00:00:00","modified_gmt":"2021-04-05T00:00:00","slug":"119","status":"publish","type":"post","link":"https:\/\/zhewana.cn\/?p=119","title":{"rendered":"\u8bb0MPU6050\u6a21\u5757\u7684\u5b66\u4e60\u8fc7\u7a0b"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/03\/2567660697.png\" alt=\"wallhaven-q26k9q_1920x1080.png\" title=\"wallhaven-q26k9q_1920x1080.png\">\u5b66\u4e60\u8fc7\u7a0b\u4e2d\u7528\u5230\u7684\u8d44\u6599\u6574\u7406\u4e86\u4e0b\u5b58\u4e86\u8d77\u6765\uff1a<\/p>\n<blockquote>\n<p><a href=\"https:\/\/wwe.lanzouv.com\/iROIKnjuo6h\">https:\/\/wwe.lanzouv.com\/iROIKnjuo6h<\/a> <br \/>\u5bc6\u7801:gzai<\/p>\n<\/blockquote>\n<p>\u73af\u5883\uff1a<strong>STM32F401CCU6+CubeMX+HAL\u5e93<\/strong><\/p>\n<hr>\n<h2>\u6a21\u5757\u7ec4\u6210\uff1a<\/h2>\n<p>MPU6050+HMC5883L+MS5611<\/p>\n<h3>MPU6050\uff1a\u52a0\u901f\u5ea6\u8ba1+\u9640\u87ba\u4eea<\/h3>\n<h3>HMC5883L\uff1a  3\u8f74\u6570\u5b57\u7f57\u76d8<\/h3>\n<h3>MS5611 \uff1a\u6c14\u538b\u4f20\u611f\u5668<\/h3>\n<hr>\n<h2>\u6a21\u5757\u5f15\u811a\u5b9a\u4e49\uff1a<\/h2>\n<p>\u4ee5\u4e0b\u5f15\u811a\u7528\u9014\u4ee5\u53ca\u914d\u7f6e\u4e3a\u4e2a\u4eba\u5bf9\u4e0e\u6570\u636e\u624b\u518c\u5185\u5bb9\u7684\u7406\u89e3\uff0c\u53ef\u80fd\u6709\u8bef\u3002<\/p>\n<h3>VCC_IN:5V\u7535\u6e90\u8f93\u5165<\/h3>\n<h3>3.3V\uff1a3.3V\u7535\u6e90\u8f93\u5165<\/h3>\n<h3>GND\uff1a\u63a5\u5730<\/h3>\n<h3>SCL\uff1aIIC\u603b\u7ebf\u65f6\u949f<\/h3>\n<h3>SDA\uff1aIIC\u603b\u7ebf\u6570\u636e\u8f93\u5165<\/h3>\n<h3>FSYNC\uff1a\uff08MPU6050\uff09<\/h3>\n<p>\u200b    Frame synchronization digital input. Connect to GND if unused<\/p>\n<p>\u200b    \u5e27\u540c\u6b65\u6570\u5b57\u8f93\u5165\u3002 \u5982\u679c\u672a\u4f7f\u7528\uff0c\u5219\u8fde\u63a5\u5230GND<\/p>\n<h3>\uff08GND\uff09<\/h3>\n<h3>INTA\uff1a\uff08MPU6050\uff09<\/h3>\n<p>\u200b    Interrupt digital output (totem pole or open-drain)<\/p>\n<p>\u200b    \u4e2d\u65ad\u6570\u5b57\u8f93\u51fa\uff08\u56fe\u817e\u67f1\u6216\u6f0f\u6781\u5f00\u8def\uff09<\/p>\n<p>\u200b     Interrupt functionality is configured via the Interrupt Configuration register. Items that are configurable include the INT pin configuration, the interrupt latching and clearing method, and triggers for the interrupt. Items that can trigger an interrupt are <\/p>\n<p>(1) Clock generator locked to new reference oscillator (used when switching clock sources); <\/p>\n<p>(2) new data is available to be read (from the FIFO and Data registers); <\/p>\n<p>(3) accelerometer event interrupts; <\/p>\n<p>(4) the MPU-60X0 did not receive an knowledge from an auxiliary sensor on the secondary I2C bus. The interrupt status can be read from the Interrupt Status register.<\/p>\n<h3>\uff08\u914d\u7f6e\u4e3a\u5916\u90e8\u4e2d\u65ad\uff09<\/h3>\n<h3>DRDY\uff1a\uff08HMC5883L\uff09<\/h3>\n<p>\u200b    Data Ready, Interrupt Pin. Internally pulled high. Optional connection. Low for 250 \u00b5sec when data is placed in the data output registers.<\/p>\n<p>\u200b    \u6570\u636e\u51c6\u5907\uff0c\u4e2d\u65ad\u5f15\u811a\u3002\u5185\u90e8\u88ab\u62c9\u9ad8\u3002\u53ef\u9009\u8fde\u63a5\uff0c\u5f53\u6570\u636e\u4f4d\u4e8e\u8f93\u51fa\u5bc4\u5b58\u5668 \u4e0a\u65f6\u4f1a\u5728\u4f4e\u7535\u4f4d\u4e0a\u505c250\u03bcs\u3002\uff08\u7406\u89e3\u4e3a\u6570\u636e\u4f20\u8f93\u5b8c\u6210\u6807\u5fd7\u5f15\u811a\uff09<\/p>\n<h3>\uff08\u914d\u7f6e\u4e3a\u5916\u90e8\u4e2d\u65ad\uff09<\/h3>\n<hr>\n<h2>\u6a21\u5757\u4f7f\u7528\uff1a<\/h2>\n<h3>\u4f2a\u524d\u8a00\uff1a<\/h3>\n<p>\u4f7f\u7528\u5206\u4e3a\u4e24\u90e8\u5206\uff0c\u9996\u5148\u662f\u4e3a\u4e86<strong>\u719f\u6089IIC\u4f7f\u7528\u4ee5\u53ca\u5bf9\u6570\u636e\u624b\u518c\u7684\u9605\u8bfb<\/strong>\u800c\u5b58\u5728\u7684<strong>\u539f\u59cb\u6570\u636e\u6253\u5370<\/strong>\u90e8\u5206\uff0c\u63a5\u4e0b\u6765\u662f\u4e3a\u4e86\u771f\u6b63\u5e94\u7528\u800c\u5b58\u5728\u7684<strong>DMP\u5e93\u79fb\u690d<\/strong>\u90e8\u5206\u3002<\/p>\n<p>\u7b2c\u4e00\u6b21\u8fdb\u884c\u5e93\u7684\u79fb\u690d\u7684\u786e\u4f1a\u51fa\u73b0\u5f88\u591a\u5947\u602a\u7684\u95ee\u9898\uff0c\u8bf7\u7ec6\u5fc3\u7ec6\u5fc3\u52a0\u8010\u5fc3\u3002<\/p>\n<p>\u5b98\u65b9\u7684\u624b\u518c\u662f\u597d\u4e1c\u897f\uff0c\u8bf7\u591a\u9605\u8bfb\u3002<\/p>\n<p><strong><em>\u5982\u679c\u53ea\u662f\u9700\u8981\u4f7f\u7528\u6b27\u62c9\u89d2\u6570\u636e\uff0c\u5219\u4e0d\u9700\u8981\u53c2\u8003\u7b2c\u4e00\u90e8\u5206\u5185\u5bb9\uff0c\u76f4\u63a5\u8fdb\u884c\u7b2c\u4e8c\u90e8\u5206\u5373\u53ef<\/em><\/strong><\/p>\n<p><strong><em>\u5982\u679c\u53ea\u662f\u9700\u8981\u4f7f\u7528\u6b27\u62c9\u89d2\u6570\u636e\uff0c\u5219\u4e0d\u9700\u8981\u53c2\u8003\u7b2c\u4e00\u90e8\u5206\u5185\u5bb9\uff0c\u76f4\u63a5\u8fdb\u884c\u7b2c\u4e8c\u90e8\u5206\u5373\u53ef<\/em><\/strong><\/p>\n<p><strong><em>\u5982\u679c\u53ea\u662f\u9700\u8981\u4f7f\u7528\u6b27\u62c9\u89d2\u6570\u636e\uff0c\u5219\u4e0d\u9700\u8981\u53c2\u8003\u7b2c\u4e00\u90e8\u5206\u5185\u5bb9\uff0c\u76f4\u63a5\u8fdb\u884c\u7b2c\u4e8c\u90e8\u5206\u5373\u53ef<\/em><\/strong><\/p>\n<hr>\n<h3>\u539f\u59cb\u6570\u636e\u7684\u6253\u5370\uff1a<\/h3>\n<p>\u9996\u5148\u65b0\u5efa\u4e00\u4e2aF401\u5de5\u7a0b\uff0c\u5728\u65b0\u5de5\u7a0b\u91cc\u9762\u5b8c\u6210IIC\u548cUART\u7684\u914d\u7f6e\u3002<\/p>\n<p>\u5176\u4e2dIIC\u9009\u62e9IIC1\uff0c\u4e0b\u62c9\u680f\u9009\u62e9IIC\uff0c\u914d\u7f6e\u9ed8\u8ba4\u5373\u53ef\u3002<\/p>\n<p>\u751f\u6210\u5de5\u7a0b\u5e76\u6253\u5f00\u3002<\/p>\n<p>\u5728\u5de5\u7a0b\u6587\u4ef6\u5939\u4e2d\u65b0\u5efa\u4e00\u4e2ampu6050.h\u6587\u4ef6\u3002<\/p>\n<p>\uff08PS\uff1a\u5982\u679c\u662f\u81ea\u5df1\u6dfb\u52a0\u7684\u6587\u4ef6\u9700\u8981\u6dfb\u52a0\u5305\u542b\u8def\u5f84\uff0c\u65b9\u6cd5\u53c2\u8003u8g2\u5c4f\u5e55\u7684\u914d\u7f6e\u6587\u6863\uff09<\/p>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u4f7f\u7528\uff0c\u9996\u5148\u628a\u8981\u7528\u5230\u7684\u5bc4\u5b58\u5668\u5728mpu6050.h\u4e2d\u8fdb\u884c\u5b8f\u5b9a\u4e49\uff1a<\/p>\n<pre><code class=\"lang-C\">\/***********************************************************************************\n *\u8bbe\u5907\u5730\u5740  \n *PS\uff1a\u5728\u6570\u636e\u624b\u518c\u91cc\u9762\u7684\u4e03\u4f4d\u5730\u5740\u662f0x68\uff0c\u4f46\u662fHAL\u5e93\u4e2d\u51fd\u6570\u524d\u9762\u7684\u6ce8\u91ca\u6709\u8bf4\u660e\u5982\u4e0b\uff1a\n *DevAddress Target device address: The device 7 bits address value\n *in datasheet must be shifted to the left before calling the interface\n *\u4e5f\u5c31\u662f\u8bf4\u6211\u4eec\u5728\u4f7f\u7528\u65f6\u8981\u5c06\u8bbe\u5907\u5730\u5740\u5de6\u79fb\u4e00\u4f4d\uff0c\u800c0x68\u5de6\u79fb\u4e00\u4f4d\u662f0xD0\u3002\n **********************************************************************************\/\n#define MPU6050_ADDR 0xD0\n\n\/\/\u91c7\u6837\u9891\u7387\u5206\u9891\u5668\u5bc4\u5b58\u5668\n#define SMPRT_DIV_REG 0x19\n\n\/\/\u9640\u87ba\u4eea\u914d\u7f6e\u5bc4\u5b58\u5668\n#define GYRO_CONFIG_REG 0x1B\n\/\/\u89d2\u901f\u5ea6\u91cf\u7a0b\n#define FSR1_GYRO 0 \/\/+-250\u00b0\/s\n#define FSR2_GYRO 1 \/\/+-500\u00b0\/s\n#define FSR3_GYRO 2 \/\/+-1000\u00b0\/s\n#define FSR4_GYRO 3 \/\/+-2000\u00b0\/s\n\/\/\u89d2\u901f\u5ea6\u6700\u4f4e\u5206\u8fa8\u7387\n#define LSB1_GYRO 131.0 \/\/+-250\u00b0\/s\n#define LSB2_GYRO 65.5 \/\/+-500\u00b0\/s\n#define LSB3_GYRO 32.8 \/\/+-1000\u00b0\/s\n#define LSB4_GYRO 16.4 \/\/+-2000\u00b0\/s\n\n\/\/\u52a0\u901f\u5ea6\u914d\u7f6e\u5bc4\u5b58\u5668\n#define ACCEL_CONFIG_REG 0x1c\n\/\/\u52a0\u901f\u5ea6\u91cf\u7a0b\n#define FSR1_ACCEL 0 \/\/+-2g\n#define FSR2_ACCEL 1 \/\/+-4g\n#define FSR3_ACCEL 2 \/\/+-8g\n#define FSR4_ACCEL 3 \/\/+-16g\n\/\/\u52a0\u901f\u5ea6\u6700\u4f4e\u5206\u8fa8\u7387\n#define LSB1_ACCEL 16384.0 \/\/+-2g\n#define LSB2_ACCEL 8192.0 \/\/+-4g\n#define LSB3_ACCEL 4096.0 \/\/+-8g\n#define LSB4_ACCEL 2048.0 \/\/+-16g\n\n\/\/\u52a0\u901f\u5ea6\u6d4b\u91cf\u503c\n#define ACCEL_XOUT_H_REG 0x3B\n\n\/\/\u6e29\u5ea6\u6d4b\u91cf\u503c\n\/\/\u6e29\u5ea6\u8ba1\u7b97\u516c\u5f0f:\u6444\u6c0f\u5ea6=(int16_t)REG\/340+36.53\n#define TEMP_OUT_H_REG 0x41\n\n\/\/\u9640\u87ba\u4eea\u6d4b\u91cf\u503c\n#define GYRO_XOUT_H_REG 0x43\n\n\/\/\u7535\u6e90\u7ba1\u7406\u5bc4\u5b58\u5668\n#define PWR_MGMT_1_REG 0x6B\n\n\/\/\u8bbe\u5907\u8eab\u4efd\u6807\u8bc6\u5bc4\u5b58\u5668\n#define WHO_AM_I_REG 0x75<\/code><\/pre>\n<p>\u5b9a\u4e49\u51e0\u4e2a\u53d8\u91cf\uff1a<\/p>\n<pre><code class=\"lang-C\">int16_t Axo = 0;\nint16_t Ayo = 0;\nint16_t Azo = 0;\n\nint16_t Gxo = 0;\nint16_t Gyo = 0;\nint16_t Gzo = 0;\n\nint16_t Temp_RAW = 0;\n\nfloat Ax,Ay,Az,Gx,Gy,Gz,Temp;<\/code><\/pre>\n<p>\u9996\u5148\u5bf9\u6a21\u5757\u8fdb\u884c\u521d\u59cb\u5316\u8bbe\u7f6e\uff1a<\/p>\n<pre><code class=\"lang-C\">void MPU6050_Init(void){\n    uint8_t check,Data;\n    \/\/\u68c0\u67e5\u8bbe\u5907\u8eab\u4efd\u6807\u8bc6(WHO_AM_I)\n    HAL_I2C_Mem_Read (&amp;hi2c1 ,MPU6050_ADDR,WHO_AM_I_REG,1,&amp;check ,1,1000);\n    if(check == 104)        \/\/\u9a8c\u8bc1\u8bbe\u5907\u5730\u5740\n    {\n        \/\/\u5728\u7535\u6e90\u7ba1\u7406\u5bc4\u5b58\u5668\u4e2d\u5199\u51650\u6765\u4f7f\u80fd\u4f20\u611f\u5668\n        Data = 0;\n        HAL_I2C_Mem_Write (&amp;hi2c1 ,MPU6050_ADDR ,PWR_MGMT_1_REG ,1,&amp;Data ,1,1000);\n        \n        \/\/\u8bbe\u7f6e\u91c7\u6837\u9891\u7387\n        Data = 0x07;\n        HAL_I2C_Mem_Write (&amp;hi2c1 ,MPU6050_ADDR ,SMPRT_DIV_REG ,1 ,&amp;Data,1,1000);\n        \n        \/\/\u8bbe\u7f6e\u52a0\u901f\u5ea6\u91cf\u7a0b\n        Data = FSR1_ACCEL;\n        HAL_I2C_Mem_Write (&amp;hi2c1 ,MPU6050_ADDR, ACCEL_CONFIG_REG, 1, &amp;Data, 1, 1000);\n        \n        \/\/\u8bbe\u7f6e\u9640\u87ba\u4eea\u91cf\u7a0b\n        Data = FSR1_GYRO;\n        HAL_I2C_Mem_Write (&amp;hi2c1 ,MPU6050_ADDR, GYRO_CONFIG_REG, 1, &amp;Data, 1, 1000);\n    }\n}<\/code><\/pre>\n<p>\u8fd9\u91cc\u5bf9\u51e0\u4e2a\u91cd\u8981\u5bc4\u5b58\u5668\u505a\u4e00\u4e9b\u8bf4\u660e\uff1a<\/p>\n<p><strong>1.\u91c7\u6837\u9891\u7387\u5206\u9891\u5668\uff1a<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3034499700.png\" alt=\"1617031200192-1620477659491.png\" title=\"1617031200192-1620477659491.png\"><\/p>\n<p>\u91c7\u6837\u9891\u7387\u7684\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1a<\/p>\n<p>\u200b    <strong>\u91c7\u6837\u9891\u7387=\u9640\u87ba\u4eea\u8f93\u51fa\u9891\u7387\/\uff08 1+SMPLRT_DIV  \uff09<\/strong><\/p>\n<p>\u800c\u9640\u87ba\u4eea\u7684\u8f93\u51fa\u9891\u7387\u662f\u53d7\u5230DLPF\uff08\u6570\u5b57\u4f4e\u901a\u6ee4\u6ce2\u5668\uff09\u7684\u914d\u7f6e\u5f71\u54cd\u7684\uff0c\u5177\u4f53\u5f71\u54cd\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3226054326.png\" alt=\"1617031379242-1620477659492.png\" title=\"1617031379242-1620477659492.png\"><\/p>\n<p>\u800c\u4e0a\u8ff0\u6ee4\u6ce2\u5668\u5728\u914d\u7f6e\u5bc4\u5b58\u5668\u4e2d\u8fdb\u884c\u8bbe\u7f6e\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/2566095557.png\" alt=\"1617031435930-1620477659492.png\" title=\"1617031435930-1620477659492.png\"><\/p>\n<p><strong>2.\u9640\u87ba\u4eea\u914d\u7f6e\u5bc4\u5b58\u5668<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/411344685.png\" alt=\"1617031496511-1620477659492.png\" title=\"1617031496511-1620477659492.png\"><\/p>\n<p>\u4e3b\u8981\u529f\u80fd\u4e3a\u89e6\u53d1\u9640\u87ba\u4eea\u81ea\u68c0\u4ee5\u53ca\u9640\u87ba\u4eea\u6700\u5927\u91cf\u7a0b\u914d\u7f6e\uff0c\u6211\u4eec\u4e3b\u8981\u7528\u5230\u7b2c\u4e8c\u4e2a\u529f\u80fd\u3002<\/p>\n<p>\u81ea\u68c0\u529f\u80fd\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/2184074956.png\" alt=\"1617031878416-1620477659492.png\" title=\"1617031878416-1620477659492.png\"><\/p>\n<p>\u5177\u4f53\u91cf\u7a0b\u914d\u7f6e\u53c2\u8003\u4e0b\u8868\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/949015402.png\" alt=\"1617031692618-1620477659492.png\" title=\"1617031692618-1620477659492.png\"><\/p>\n<p><strong>3.\u52a0\u901f\u5ea6\u914d\u7f6e\u5bc4\u5b58\u5668<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/2194269429.png\" alt=\"1617031935975-1620477659492.png\" title=\"1617031935975-1620477659492.png\"><\/p>\n<p>\u4e3b\u8981\u529f\u80fd\u548c\u9640\u87ba\u4eea\u914d\u7f6e\u5bc4\u5b58\u5668\u4e00\u81f4\uff0c\u6211\u4eec\u8fd8\u662f\u7528\u7b2c\u4e8c\u4e2a\u529f\u80fd\u3002<\/p>\n<p>\u81ea\u68c0\u529f\u80fd\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/2060250693.png\" alt=\"1617032006471-1620477659492.png\" title=\"1617032006471-1620477659492.png\"><\/p>\n<p>\u5177\u4f53\u91cf\u7a0b\u914d\u7f6e\u53c2\u8003\u4e0b\u8868\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3294817775.png\" alt=\"1617032031176-1620477659492.png\" title=\"1617032031176-1620477659492.png\"><\/p>\n<p><strong>4.\u6d4b\u91cf\u503c\u5bc4\u5b58\u5668<\/strong><\/p>\n<p>\u8981\u7528\u5230\u7684\u6d4b\u91cf\u503c\u5bc4\u5b58\u5668\u6709\u4e09\u4e2a\uff1a\u52a0\u901f\u5ea6\u3001\u9640\u87ba\u4eea\u548c\u6e29\u5ea6\u3002<\/p>\n<p>\u9996\u5148\u662f\u52a0\u901f\u5ea6\u8ba1\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3594872860.png\" alt=\"1617032142421-1620477659492.png\" title=\"1617032142421-1620477659492.png\"><\/p>\n<p>\u4e0d\u96be\u770b\u51fa\uff0c\u6570\u636e\u7684\u5b58\u50a8\u65b9\u5f0f\u662f\u7528\u4e86\u516d\u4e2a\u5b57\u8282\u6765\u5b58\u50a8\u4e09\u4e2a\u5750\u6807\u8f74\u7684\u6570\u636e\uff0c\u5176\u4e2d\u76f8\u90bb\u4e24\u4e2a\u6570\u636e\u5206\u522b\u8868\u793a\u540c\u4e00\u5750\u6807\u8f74\u6570\u636e\u7684\u9ad8\u516b\u4f4d\u548c\u4f4e\u516b\u4f4d\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5bf9\u6570\u636e\u5982\u6b64\u5904\u7406\uff1a<\/p>\n<pre><code class=\"lang-C\">\/\/\u5b9a\u4e49\u516d\u4f4d\u6570\u7ec4\u6765\u5b58\u653e\u5bc4\u5b58\u5668\u503c\nint8_t Mesurment[6];\n\/\/\u5c06\u5bc4\u5b58\u5668\u503c\u8bfb\u53d6\u51fa\u6765\u5b58\u5165\u6570\u7ec4\u4e2d\u65b9\u4fbf\u540e\u7eed\u64cd\u4f5c\nHAL_I2C_Mem_Read (&amp;hi2c1 ,MPU6050_ADDR ,ACCEL_XOUT_H_REG ,1,Mesurment ,6,1000);\n\/\/\u4ee5x\u8f74\u6570\u636e\u4e3a\u4f8b\uff0c\u5e94\u505a\u5982\u4e0b\u5904\u7406\uff1a\nAx=(int16_t)(Mesurment[0]&lt;&lt;8)|Mesurment[1];\n\/\/\u5904\u7406\u540e\u7684\u6570\u636e\u9664\u4ee5LSB\uff08\u7075\u654f\u5ea6\u6700\u4f4e\u5206\u8fa8\u7387\uff09\u5373\u53ef\u5f97\u5230\u52a0\u901f\u5ea6\u503c\nAccel=Ax*1.0\/16384;<\/code><\/pre>\n<p>\u6700\u5c0f\u5206\u8fa8\u7387\u53d6\u503c\u53c2\u8003\u4e0b\u8868\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/2030320492.png\" alt=\"1617032758704-1620477659492.png\" title=\"1617032758704-1620477659492.png\"><\/p>\n<p>\u63a5\u4e0b\u6765\u662f\u9640\u87ba\u4eea\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3945802216.png\" alt=\"1617280360231-1620477659492.png\" title=\"1617280360231-1620477659492.png\"><\/p>\n<p>\u5904\u7406\u65b9\u5f0f\u4e0e\u52a0\u901f\u5ea6\u76f8\u540c\uff0c\u6700\u5c0f\u5206\u8fa8\u7387\u53c2\u8003\u4e0b\u8868\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3457184800.png\" alt=\"1617280418367-1620477659493.png\" title=\"1617280418367-1620477659493.png\"><\/p>\n<p>\u6700\u540e\u662f\u6e29\u5ea6\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1710851378.png\" alt=\"1617280458545-1620477659493.png\" title=\"1617280458545-1620477659493.png\"><\/p>\n<p>\u8bfb\u51fa\u6570\u636e\u9700\u8981\u6309\u7167\u4e0b\u8ff0\u516c\u5f0f\u8fdb\u884c\u5904\u7406\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1038575548.png\" alt=\"1617349496815-1620477659493.png\" title=\"1617349496815-1620477659493.png\"><\/p>\n<p><strong>5.\u7535\u6e90\u7ba1\u7406\u5bc4\u5b58\u5668<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/4188583426.png\" alt=\"1617280616125-1620477659493.png\" title=\"1617280616125-1620477659493.png\"><\/p>\n<p>\u5177\u4f53\u5404\u4f4d\u529f\u80fd\u53c2\u8003\u6570\u636e\u624b\u518c\uff0c\u8fd9\u91cc\u6211\u4eec\u60f3\u8ba9\u4ed6\u6b63\u5e38\u5de5\u4f5c\uff0c\u9700\u8981\u5c06\u6240\u6709\u4f4d\u7f6e0.<\/p>\n<p><strong>6.\u8bbe\u5907\u8eab\u4efd\u6807\u8bc6\u5bc4\u5b58\u5668<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/4192638992.png\" alt=\"1617280733301-1620477659493.png\" title=\"1617280733301-1620477659493.png\"><\/p>\n<p>\u8bf4\u660e\u8bbe\u5907\u5730\u5740\u7684\u5bc4\u5b58\u5668\uff0c\u82e5AD0\u63a5\u5730\uff0c\u5219\u6700\u4f4e\u4f4d\u4f4d0\uff0c\u8bbe\u5907\u5730\u5740\u4e3a0x68;<\/p>\n<p>\u82e5AD0\u7f6e\u9ad8\uff0c\u5219\u6700\u4f4e\u4f4d\u4e3a1\uff0c\u8bbe\u5907\u5730\u5740\u4e3a0x69.<\/p>\n<p>\u914d\u7f6e\u5b8c\u6a21\u5757\u540e\uff0c\u53ea\u8981\u81ea\u5df1\u5199\u51fa\u51fd\u6570\u5c06\u6570\u636e\u8bfb\u51fa\u6253\u5370\u51fa\u6765\u5373\u53ef\u3002<\/p>\n<p>\u4ee5\u4e0b\u8bfb\u53d6\u51fd\u6570\u4ec5\u4f5c\u53c2\u8003\uff1a<\/p>\n<pre><code class=\"lang-C\">\/\/\u9640\u87ba\u4eea\u6570\u636e\u8bfb\u53d6\nvoid GYRO_READ(void){\n  uint8_t Mesurment[6];\n\n  HAL_I2C_Mem_Read(&amp;hi2c1,MPU6050_ADDR,GYRO_XOUT_H_REG,1,Mesurment,6,1000);\n      Gxo = (int16_t )(Mesurment [0] &lt;&lt; 8 | Mesurment [1]);\n    Gyo = (int16_t )(Mesurment [2] &lt;&lt; 8 | Mesurment [3]);\n    Gzo = (int16_t )(Mesurment [4] &lt;&lt; 8 | Mesurment [5]);\n\n      Gx = (double)Gxo\/LSB1_GYRO;\n    Gy = (double)Gyo\/LSB1_GYRO;\n    Gz = (double)Gzo\/LSB1_GYRO;\n}\n\/\/\u52a0\u901f\u5ea6\u6570\u636e\u8bfb\u53d6\nvoid ACCEL_READ(void){\n  uint8_t Mesurment[6];\n    \n    HAL_I2C_Mem_Read (&amp;hi2c1 ,MPU6050_ADDR ,ACCEL_XOUT_H_REG ,1,Mesurment ,6,1000);\n    \n    Axo = (int16_t )(Mesurment [0] &lt;&lt;8 | Mesurment [1]);\n    Ayo = (int16_t )(Mesurment [2] &lt;&lt;8 | Mesurment [3]);\n    Azo = (int16_t )(Mesurment [4] &lt;&lt;8 | Mesurment [5]);\n    \n    Ax = (double) Axo \/ LSB1_ACCEL;\n    Ay = (double) Ayo \/ LSB1_ACCEL;\n    Az = (double) Azo \/ LSB1_ACCEL;\n}\n\/\/\u6e29\u5ea6\u6570\u636e\u8bfb\u53d6\nvoid TEMP_READ(void){\n  uint8_t Mesurment[2];\n    \n    HAL_I2C_Mem_Read (&amp;hi2c1 ,MPU6050_ADDR ,TEMP_OUT_H_REG ,1 ,Mesurment  ,2 ,1000);\n    \n    Tempo = (int16_t )(Mesurment [0]&lt;&lt;8)|Mesurment [1];\n    Temp = 36.53 + Tempo * 1.0 \/ 340;\n}\n<\/code><\/pre>\n<p>\u81f3\u6b64\uff0c\u7b2c\u4e00\u90e8\u5206\u7ed3\u675f\u3002<\/p>\n<hr>\n<h3>DMP\u5e93\u79fb\u690d<\/h3>\n<p>\u9996\u5148\u65b0\u5efa\u4e00\u4e2aF401\u5de5\u7a0b\uff0c\u5728\u65b0\u5de5\u7a0b\u91cc\u9762\u5b8c\u6210IIC\u548cUART\u7684\u914d\u7f6e\u3002<\/p>\n<p>\u5176\u4e2dIIC\u9009\u62e9IIC1\uff0c\u4e0b\u62c9\u680f\u9009\u62e9IIC\uff0c\u914d\u7f6e\u9ed8\u8ba4\u5373\u53ef\u3002<\/p>\n<p>\u751f\u6210\u5de5\u7a0b\u5e76\u6253\u5f00\u3002<\/p>\n<p>\u5148\u628a\u6211\u4eec\u8981\u79fb\u690d\u7684\u5e93\u6587\u4ef6\u590d\u5236\u5230\u5de5\u7a0b\u6587\u4ef6\u5939\u4e2d\uff1a<\/p>\n<p>\u4e0b\u8f7d\u5e76\u89e3\u538b\u201cMPU6050\u8d44\u6599\u201d\u8fd9\u4e00\u6587\u4ef6\uff0c\u6587\u4ef6\u5185\u5bb9\u4ee5\u53ca\u5177\u4f53\u6587\u4ef6\u8def\u5f84\u5728README\u4e2d\u6709\u8bf4\u660e\u3002<\/p>\n<p>\u89e3\u538b\u5b98\u65b9\u5e93\u6587\u4ef6\u201cmotion_driver_6.12.7z\u201d<\/p>\n<p>\u590d\u5236\u5e93\u6587\u4ef6\u548c\u5305\u542b\u6587\u4ef6\u6240\u5728\u7684\u4e24\u4e2a\u6587\u4ef6\u5939\uff0c\u7c98\u8d34\u5230\u5de5\u7a0b\u6587\u4ef6\u5939\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1863642533.png\" alt=\"1617352471139-1620477659493.png\" title=\"1617352471139-1620477659493.png\"><\/p>\n<p>\u56de\u5230keil\u4e2d\uff0c\u65b0\u5efa\u6587\u4ef6\u5939\u547d\u540d\u4e3aDMP<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/737635609.png\" alt=\"1617352556822-1620477659493.png\" title=\"1617352556822-1620477659493.png\"><\/p>\n<p>\u53cc\u51fb\u6587\u4ef6\u5939\u4e3a\u5176\u4e2d\u6dfb\u52a0\u5e93\u6587\u4ef6\uff1a<\/p>\n<p>\u8bb0\u5f97\u5c06\u6587\u4ef6\u7c7b\u578b\u7684\u7b5b\u9009\u6539\u6210\u6240\u6709\u6587\u4ef6<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/867805457.png\" alt=\"1617352641220-1620477659493.png\" title=\"1617352641220-1620477659493.png\"><\/p>\n<p>\u5168\u9009eMPL\u4e2d\u76846\u4e2a\u6587\u4ef6\u70b9\u51fb\u6dfb\u52a0\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3205010266.png\" alt=\"1617352677192-1620477659493.png\" title=\"1617352677192-1620477659493.png\"><\/p>\n<p>\u63a5\u4e0b\u6765\u6dfb\u52a0\u6240\u9700\u7684\u5305\u542b\u8def\u5f84\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/2586116039.png\" alt=\"1617352990063-1620477659493.png\" title=\"1617352990063-1620477659493.png\"><\/p>\n<p>\u6dfb\u52a0\u8fd9\u4e24\u4e2a\u6587\u4ef6\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/4266932777.png\" alt=\"1617353030848-1620477659493.png\" title=\"1617353030848-1620477659493.png\"><\/p>\n<p>\u63a5\u4e0b\u6765\u6dfb\u52a0\u6211\u4eec\u8981\u7528\u5230\u7684\u5305\u542b\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"lang-C\">#include &lt;stdio.h&gt;\n#include &lt;math.h&gt;\n#include &quot;inv_mpu.h&quot;\n#include &quot;inv_mpu_dmp_motion_driver.h&quot;<\/code><\/pre>\n<p>\u8fd9\u65f6\u7f16\u8bd1\u4e00\u4e0b<del>\u5e94\u8be5\u662f0 errors<\/del><\/p>\n<p>\u54b3\u54b3  \u5e94\u8be5\u662f<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/584869419.png\" alt=\"1617353398948-1620477659493.png\" title=\"1617353398948-1620477659493.png\"><\/p>\n<p>\u90a3\u4e48\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u4fee\u6539\u5e93\u6587\u4ef6\u3002<\/p>\n<p>\u6253\u5f00inv_mpu.c<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u8fd9\u91cc\u5b98\u65b9\u5df2\u7ecf\u4e3a\u6211\u4eec\u5199\u597d\u4e86F4\u7684\u63a5\u53e3\uff0c\u53ea\u9700\u8981\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u5b8f\u5373\u53ef\u3002\u590d\u5236\u4e00\u4e0b\u5b8f\u7684\u5185\u5bb9\uff0c\u6253\u5f00\u9009\u9879\u754c\u9762\u9009\u62e9C\/C++\uff0c\u5728\u4e0a\u9762\u7684define\u4e2d\u6dfb\u52a0\u9884\u7f16\u8bd1\u7684\u5185\u5bb9\uff0c\u5373\u521a\u521a\u590d\u5236\u7684\u5b8f\uff0c\u987a\u624b\u628a\u4f18\u5316\u6539\u5230\u6700\u4f4e\uff08\u65b9\u4fbf\u540e\u9762\u51fa\u95ee\u9898\u8c03\u8bd5\uff09\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/2001473545.png\" alt=\"1617353709603-1620477659493.png\" title=\"1617353709603-1620477659493.png\"><\/p>\n<p>\u7f16\u8bd1\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/2424260064.png\" alt=\"1617353777911-1620477659493.png\" title=\"1617353777911-1620477659493.png\"><\/p>\n<p>\u6211\u4eec\u6765\u770b\u770b\u8fd9\u4e24\u4e2a\u9519\u8bef\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1753984385.png\" alt=\"1617353828850-1620477659493.png\" title=\"1617353828850-1620477659493.png\"><\/p>\n<p>\u90fd\u662f\"board-st_discovery.h\"\u6ca1\u6709\u627e\u5230\u5bfc\u81f4\u7684\uff0c\u8fd9\u4e2a\u6587\u4ef6\u662f\u5b98\u65b9\u7684\u6d4b\u8bd5\u5de5\u7a0b\u4e2d\u7528\u5230\u7684\u6587\u4ef6\uff0c\u6240\u4ee5\u76f4\u63a5\u5220\u9664\u5bf9\u4e8e\u6211\u4eec\u6ca1\u6709\u5f71\u54cd\u3002<\/p>\n<p>\u53cc\u51fb\u5bf9\u5e94\u7684\u9519\u8bef\u4f20\u9001\u5e26\u5bf9\u5e94\u4f4d\u7f6e\u5220\u9664\u5b8f\u5b9a\u4e49\u4ee3\u7801\uff0c<\/p>\n<p>\u7f16\u8bd1\uff1a<del>0 errors\uff01\uff01\uff01<\/del><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/2154918185.png\" alt=\"1617354000906-1620477659493.png\" title=\"1617354000906-1620477659493.png\"><\/p>\n<p>\u7f13\u7f13\u7684\u6253\u51fa\u4e00\u5806\u95ee\u53f7\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f<\/p>\n<p>\u522b\u6025\uff0c\u6211\u4eec\u6162\u6162\u89e3\u51b3\u3002<\/p>\n<p>\u9996\u5148\u8ba9\u6211\u4eec\u597d\u597d\u8bfb\u4e00\u4e0b\u5b98\u65b9\u7684\u8bf4\u660e\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3415587990.png\" alt=\"1617354101759-1620477659493.png\" title=\"1617354101759-1620477659493.png\"><\/p>\n<p>\u660e\u786e\u7684\u8bf4\u660e\u4e86\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u8fd9\u56db\u4e2a\u51fd\u6570\u6765\u4f7f\u5e93\u6b63\u5e38\u5de5\u4f5c\u3002\u800c\u4e0b\u9762\u7684\u5b8f\u5b9a\u4e49\u5c31\u662f\u7559\u7ed9\u6211\u4eec\u7684\u51fd\u6570\u63a5\u53e3\uff0c\u4e8e\u662f\u6211\u4eec\u5f00\u59cb\u5199\u4e00\u4e0b\u8fd9\u51e0\u4e2a\u51fd\u6570\u3002<\/p>\n<p>\u9996\u5148\u6839\u636e\u7f51\u4e0a\u8d44\u6599\uff0cget_ms\u51fd\u6570\u6ca1\u4ec0\u4e48\u7528\uff0c\u6240\u4ee5\u4e0b\u4e00\u4e2a\u7a7a\u51fd\u6570\u9632\u6b62\u62a5\u9519;<\/p>\n<p>delay_ms\u51fd\u6570\u76f4\u63a5\u8c03\u7528HAL\u5e93\u7684\u5ef6\u65f6\u51fd\u6570\uff1b<\/p>\n<p>\u800ci2c_read\u548ci2c_write\u6211\u4eec\u901a\u8fc7\u8c03\u7528HAL\u5e93\u7684IIC\u51fd\u6570\u6765\u5b9e\u73b0\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662fHAL\u5e93\u51fd\u6570\u4e0e\u9700\u8981\u7684\u51fd\u6570\u53c2\u6570\u4e2a\u6570\u548c\u987a\u5e8f\u90fd\u4e0d\u4e00\u6837\u3002<\/p>\n<p>\u53c2\u8003\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"lang-C\">\/\/\u7a7a\u51fd\u6570\u9632\u6b62\u62a5\u9519\nvoid mget_ms(unsigned long *time){}\n\n\/\/\u8c03\u7528HAL\u5e93\u51fd\u6570\nuint8_t i2c_write(unsigned char slave_addr, unsigned char reg_addr,unsigned char length, unsigned char const *data){\n    int res;\n    res=HAL_I2C_Mem_Write(&amp;hi2c1,slave_addr,reg_addr,1,(uint8_t *)data,length,1000);\n    return res;\n}\nuint8_t i2c_read(unsigned char slave_addr, unsigned char reg_addr,unsigned char length, unsigned char *data){\n    int res;\n    res=HAL_I2C_Mem_Read(&amp;hi2c1,slave_addr,reg_addr,1,(uint8_t *)data,length,1000);\n    return res;\n}<\/code><\/pre>\n<p>\u7531\u4e8e\u4e4b\u524d\u63d0\u5230\u7684HAL\u5e93IIC\u5730\u5740\u504f\u79fb\u7279\u6027\uff0c\u6211\u4eec\u9700\u8981\u628a\u5e93\u91cc\u9762\u7684\u8bbe\u5907\u5730\u5740\u6539\u4e3a0xD0:<\/p>\n<p>\u5728inv_mpu.c\u4e2d\u641c\u7d220x68:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1386874355.png\" alt=\"1617357292231-1620477659493.png\" title=\"1617357292231-1620477659493.png\"><\/p>\n<p>\u6539\u4e3a0xD0:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/406564447.png\" alt=\"1617357328178-1620477659493.png\" title=\"1617357328178-1620477659493.png\"><\/p>\n<p>\u628a\u51fd\u6570\u63a5\u53e3\u6539\u6210\u6211\u4eec\u7684\u51fd\u6570\u540d\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1918904036.png\" alt=\"1617354938152-1620477659493.png\" title=\"1617354938152-1620477659493.png\"><\/p>\n<p>\u8bb0\u5f97inv_mpu_dmp_motion_driver.c\u4e2d\u7684\u63a5\u53e3\u4e5f\u8981\u6539\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3014722246.png\" alt=\"1617355462081-1620477659493.png\" title=\"1617355462081-1620477659493.png\"><\/p>\n<p>\u7f16\u8bd1\uff0c\u4f1a\u770b\u5230\u4e00\u5806\u9519\u8bef\u4e2d\u6709\u8fd9\u6837\u4e00\u4e2a\u753b\u98ce\u6e05\u5947\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/613924934.png\" alt=\"1617355116084-1620477659493.png\" title=\"1617355116084-1620477659493.png\"><\/p>\n<p>\u8fd9\u662f\u5728\u63d0\u9192\u6211\u4eec\u8981\u5b9a\u4e49\u6211\u4eec\u7684\u6a21\u5757\u578b\u53f7\uff0c\u4e8e\u662f\u5728\u9884\u7f16\u8bd1\u4e2d\u6dfb\u52a0MPU6050\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1805130633.png\" alt=\"1617355183949-1620477659493.png\" title=\"1617355183949-1620477659493.png\"><\/p>\n<p>\u7f16\u8bd1\uff1a2 errors<\/p>\n<p>\u6211\u4eec\u6765\u770b\u770b\u662f\u4ec0\u4e48\u9519\u8bef\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/1981790610.png\" alt=\"1617355311309-1620477659493.png\" title=\"1617355311309-1620477659493.png\"><\/p>\n<p>\u5230inv_mpu_dmp_motion_driver.c\u4e2d\u641c\u7d22operation\u770b\u5230<\/p>\n<p>__no_operation();<\/p>\n<p>\u770b\u51fd\u6570\u540d\u5c31\u77e5\u9053\u5565\u90fd\u6ca1\u505a\uff0c\u6ce8\u91ca\u6389\u3002<\/p>\n<p>\u66f4\u6539inv_mpu.c\u4e2dlog\u7684\u5b8f\uff0c\u7528\u7a7a\u8bed\u53e5\u66ff\u6362\uff1a<\/p>\n<pre><code class=\"lang-C\">#define log_i(...)     do {} while (0)\n#define log_e(...)     do {} while (0)<\/code><\/pre>\n<p>\u7f16\u8bd1\uff0c0 errors\uff01\uff01\uff01<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u8c03\u7528\u5e93\u91cc\u9762\u7684\u51fd\u6570\u8fdb\u884c\u6a21\u5757\u7684\u521d\u59cb\u5316\u4ee5\u53ca\u6570\u636e\u7684\u8f93\u51fa\u3002<\/p>\n<p>\u6dfb\u52a0\u6211\u4eec\u9700\u8981\u7684\u5b8f\u5b9a\u4e49\uff1a<\/p>\n<pre><code class=\"lang-C\">\/* USER CODE BEGIN PD *\/\n#define q30  1073741824.0f\n\/* USER CODE END PD *\/<\/code><\/pre>\n<p>\u5b9a\u4e49\u6211\u4eec\u9700\u8981\u7684\u53d8\u91cf\uff1a<\/p>\n<pre><code class=\"lang-C\">\/* USER CODE BEGIN PV *\/\nfloat pitch=0,roll=0,yaw=0;\nstatic signed char gyro_orientation[9] = { 1, 0, 0,\n                                           0, 1, 0,\n                                           0, 0, 1};\n\/* USER CODE END PV *\/<\/code><\/pre>\n<p>\u5b9a\u4e49\u6211\u4eec\u9700\u8981\u7684\u51fd\u6570\uff08\u7f51\u4e0a\u6284\u7684\uff09\uff1a<\/p>\n<pre><code class=\"lang-C\">\/* USER CODE BEGIN PFP *\/\n\/\/\u5f97\u5230dmp\u5904\u7406\u540e\u7684\u6570\u636e(\u6ce8\u610f,\u672c\u51fd\u6570\u9700\u8981\u6bd4\u8f83\u591a\u5806\u6808,\u5c40\u90e8\u53d8\u91cf\u6709\u70b9\u591a)\n\/\/pitch:\u4fef\u4ef0\u89d2 \u7cbe\u5ea6:0.1\u00b0   \u8303\u56f4:-90.0\u00b0 &lt;---&gt; +90.0\u00b0\n\/\/roll:\u6a2a\u6eda\u89d2  \u7cbe\u5ea6:0.1\u00b0   \u8303\u56f4:-180.0\u00b0&lt;---&gt; +180.0\u00b0\n\/\/yaw:\u822a\u5411\u89d2   \u7cbe\u5ea6:0.1\u00b0   \u8303\u56f4:-180.0\u00b0&lt;---&gt; +180.0\u00b0\n\/\/\u8fd4\u56de\u503c:0,\u6b63\u5e38\n\/\/    \u5176\u4ed6,\u5931\u8d25\nuint8_t mpu_dmp_get_data(float *pitch,float *roll,float *yaw)\n{\n    float q0=1.0f,q1=0.0f,q2=0.0f,q3=0.0f;\n    unsigned long sensor_timestamp;\n    short gyro[3], accel[3], sensors;\n    unsigned char more;\n    long quat[4]; \n    if(dmp_read_fifo(gyro, accel, quat, &amp;sensor_timestamp, &amp;sensors,&amp;more))return 1;     \n    \/* Gyro and accel data are written to the FIFO by the DMP in chip frame and hardware units.\n     * This behavior is convenient because it keeps the gyro and accel outputs of dmp_read_fifo and mpu_read_fifo consistent.\n    **\/\n    \/*if (sensors &amp; INV_XYZ_GYRO )\n    send_packet(PACKET_TYPE_GYRO, gyro);\n    if (sensors &amp; INV_XYZ_ACCEL)\n    send_packet(PACKET_TYPE_ACCEL, accel); *\/\n    \/* Unlike gyro and accel, quaternions are written to the FIFO in the body frame, q30.\n     * The orientation is set by the scalar passed to dmp_set_orientation during initialization. \n    **\/\n    if(sensors&amp;INV_WXYZ_QUAT) \n    {\n        q0 = quat[0] \/ q30;    \/\/q30\u683c\u5f0f\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\n        q1 = quat[1] \/ q30;\n        q2 = quat[2] \/ q30;\n        q3 = quat[3] \/ q30; \n        \/\/\u8ba1\u7b97\u5f97\u5230\u4fef\u4ef0\u89d2\/\u6a2a\u6eda\u89d2\/\u822a\u5411\u89d2\n        *pitch = asin(-2 * q1 * q3 + 2 * q0* q2)* 57.3;    \/\/ pitch\n        *roll  = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1)* 57.3;    \/\/ roll\n        *yaw   = atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3) * 57.3;    \/\/yaw\n    }else return 2;\n    return 0;\n}\n\n\nint run_self_test(void)\n{\n    int result;\n    char test_packet[4] = {0};\n    long gyro[3], accel[3]; \n    result = mpu_run_self_test(gyro, accel);\n    if (result == 0x7) \n    {\n        \/* Test passed. We can trust the gyro data here, so let's push it down\n        * to the DMP.\n        *\/\n        float sens;\n        unsigned short accel_sens;\n        mpu_get_gyro_sens(&amp;sens);\n        gyro[0] = (long)(gyro[0] * sens);\n        gyro[1] = (long)(gyro[1] * sens);\n        gyro[2] = (long)(gyro[2] * sens);\n        dmp_set_gyro_bias(gyro);\n        mpu_get_accel_sens(&amp;accel_sens);\n        accel[0] *= accel_sens;\n        accel[1] *= accel_sens;\n        accel[2] *= accel_sens;\n        dmp_set_accel_bias(accel);\n        return 0;\n    }else return 1;\n}\n\n\n\/\/DMP\u521d\u59cb\u5316\u51fd\u6570\nuint8_t mpu_dmp_init(void)\n{\n    uint8_t res=0;\n    struct int_param_s int_param;\/\/\u8fd9\u4e2a\u6ca1\u4ec0\u4e48\u7528\uff0c\u5c31\u662f\u4e3a\u4e86\u80fd\u7ed9\u4ed6\u5b9e\u53c2\u8c03\u7528\u8d77\u6765\n    if(mpu_init(&amp;int_param)==0)    \/\/\u521d\u59cb\u5316MPU6050\n    {     \n        res=mpu_set_sensors(INV_XYZ_GYRO|INV_XYZ_ACCEL);\/\/\u8bbe\u7f6e\u6240\u9700\u8981\u7684\u4f20\u611f\u5668\n        if(res)return 1; \n        res=mpu_configure_fifo(INV_XYZ_GYRO | INV_XYZ_ACCEL);\/\/\u8bbe\u7f6eFIFO\n        if(res)return 2; \n        res=mpu_set_sample_rate(100);    \/\/\u8bbe\u7f6e\u91c7\u6837\u7387\n        if(res)return 3; \n        res=dmp_load_motion_driver_firmware();        \/\/\u52a0\u8f7ddmp\u56fa\u4ef6\n        if(res)return 4; \n        \/\/res=dmp_set_orientation(inv_orientation_matrix_to_scalar(gyro_orientation));\/\/\u8bbe\u7f6e\u9640\u87ba\u4eea\u65b9\u5411\n        if(res)return 5; \n        res=dmp_enable_feature(DMP_FEATURE_6X_LP_QUAT|DMP_FEATURE_TAP|    \/\/\u8bbe\u7f6edmp\u529f\u80fd\n            DMP_FEATURE_ANDROID_ORIENT|DMP_FEATURE_SEND_RAW_ACCEL|DMP_FEATURE_SEND_CAL_GYRO|\n            DMP_FEATURE_GYRO_CAL);\n        if(res)return 6; \n        res=dmp_set_fifo_rate(100);    \/\/\u8bbe\u7f6eDMP\u8f93\u51fa\u901f\u7387(\u6700\u5927\u4e0d\u8d85\u8fc7200Hz)\n        if(res)return 7;   \n        res=run_self_test();        \/\/\u81ea\u68c0\n        if(res)return 8;    \n        res=mpu_set_dmp_state(1);    \/\/\u4f7f\u80fdDMP\n        if(res)return 9;\n    }\n    else return 10;\n    return 0;\n}\n<\/code><\/pre>\n<p>\u5728\u5faa\u73af\u524d\u9762\u8c03\u7528\u521d\u59cb\u5316\u51fd\u6570\uff0c\u5728\u5faa\u73af\u4e2d\u8c03\u7528\u6570\u636e\u5904\u7406\u51fd\u6570\uff0c\u5e76\u6253\u5370\u51fa\u6b27\u62c9\u89d2\u7684\u503c\uff1a<\/p>\n<pre><code class=\"lang-C\">  \/* USER CODE BEGIN WHILE *\/\n    \n    uint8_t res;\n    res = mpu_dmp_init();\n    \n  while (1)\n  {\n        res=mpu_dmp_get_data(&amp;pitch,&amp;roll,&amp;yaw);\n        printf(&quot;%.2f,%.2f,%.2f\\n&quot;,pitch,roll,yaw);\n    \/* USER CODE END WHILE *\/<\/code><\/pre>\n<p>\u4e32\u53e3\u91cd\u5b9a\u5411\uff1a<\/p>\n<pre><code class=\"lang-C\">\/* USER CODE BEGIN 4 *\/\nint fputc(int ch,FILE *f)\n{\n    HAL_UART_Transmit (&amp;huart1 ,(uint8_t *)&amp;ch,1,HAL_MAX_DELAY );\n    return ch;\n}\n\/* USER CODE END 4 *\/<\/code><\/pre>\n<p>\u7f16\u8bd1\u70e7\u5f55\uff0c\u5c31\u53ef\u4ee5\u5728\u4e32\u53e3\u8c03\u8bd5\u52a9\u624b\u4e0a\u770b\u5230\u6b27\u62c9\u89d2\u4e86\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhewana.cn\/wp-content\/uploads\/2022\/02\/3890654043.png\" alt=\"1617357509432-1620477659493.png\" title=\"1617357509432-1620477659493.png\"><\/p>\n<p>\u5982\u679c\u51fa\u73b0\u4e86\u4e09\u4e2a\u89d2\u5ea6\u5168\u4e3a0\u7684\u60c5\u51b5\uff0c\u5fc5\u7136\u662f\u67d0\u4e00\u73af\u51fa\u73b0\u7684\u95ee\u9898\uff0c\u6211\u4f1a\u5c06\u6211\u9047\u5230\u7684\u95ee\u9898\u5728\u4e4b\u540e\u5217\u4e3e\u4e00\u4e0b\uff0c\u53ef\u4ee5\u81ea\u5df1\u4f7f\u7528\u6253\u5370\u5bf9\u5e94\u8fd4\u56de\u503c\u4ee5\u53ca\u5355\u6b65\u8c03\u8bd5\u7684\u65b9\u6cd5\u9010\u6b65\u6392\u67e5\u3002<\/p>\n<h4>\u95ee\u9898\u6c47\u603b<\/h4>\n<p>PS\uff1a\u201c\/\u201d\u8868\u793a\u4e0d\u6613\u51fa\u73b0\u95ee\u9898\uff0c\u5982\u51fa\u73b0\u95ee\u9898\u53ef\u80fd\u662f\u786c\u4ef6\u95ee\u9898\uff0c\u68c0\u67e5\u662f\u5426\u662f\u672a\u4f9b\u7535\u4ee5\u53ca\u4f9b\u7535\u7535\u538b\u662f\u5426\u6b63\u786e\uff0c\u6216\u8005\u53ef\u80fd\u4f60\u7684\u6a21\u5757\u574f\u6389\u4e86\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">\u51fd\u6570\u8fd4\u56de\u503c<\/th>\n<th align=\"center\">mpu_dmp_init\u51fd\u6570<\/th>\n<th align=\"center\">mpu_dmp_get_data\u51fd\u6570<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\">1<\/td>\n<td align=\"center\">\/<\/td>\n<td align=\"center\">dmp_read_fifo\u51fd\u6570\u51fa\u73b0\u95ee\u9898<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">2<\/td>\n<td align=\"center\">\/<\/td>\n<td align=\"center\">\/<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">3<\/td>\n<td align=\"center\">\/<\/td>\n<td align=\"center\">\/<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">4<\/td>\n<td align=\"center\">\/<\/td>\n<td align=\"center\">\/<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">5<\/td>\n<td align=\"center\">\/<\/td>\n<td align=\"center\">\/<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">6<\/td>\n<td align=\"center\">\/<\/td>\n<td align=\"center\">\/<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">7<\/td>\n<td align=\"center\">\/<\/td>\n<td align=\"center\">\/<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">8<\/td>\n<td align=\"center\">\u8bf4\u660erun_self_test\u51fd\u6570\u51fa\u73b0\u95ee\u9898<\/td>\n<td align=\"center\">\/<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">9<\/td>\n<td align=\"center\">\/<\/td>\n<td align=\"center\">\/<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">10<\/td>\n<td align=\"center\">\u8bf4\u660empu_init\u51fd\u6570\u51fa\u73b0\u95ee\u9898<\/td>\n<td align=\"center\">\/<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>run_self_test\u95ee\u9898<\/h5>\n<p>\u8fdb\u5165run_self_test\u51fd\u6570\u5185\u90e8\u6709\u4e00\u4e2a<\/p>\n<p>mpu_run_self_test\u51fd\u6570\uff0c\u5c06\u5b83\u7684result\u6253\u5370\u51fa\u6765\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">result<\/th>\n<th align=\"center\">mpu_run_self_test\u5185\u90e8<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\">0x4<\/td>\n<td align=\"center\">\u52a0\u901f\u5ea6\u8ba1\u548c\u9640\u87ba\u4eea\u81ea\u68c0\u5747\u672a\u901a\u8fc7\uff0c\u8003\u8651\u4e3a\u6a21\u5757\u635f\u574f<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">0x5<\/td>\n<td align=\"center\">\u52a0\u901f\u5ea6\u8ba1\u81ea\u68c0\u672a\u901a\u8fc7\uff0c\u672a\u77e5\u539f\u56e0<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">0x6<\/td>\n<td align=\"center\">\u9640\u87ba\u4eea\u81ea\u68c0\u672a\u901a\u8fc7\uff0c\u672a\u77e5\u539f\u56e0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5982\u679c\u91cd\u65b0\u8fde\u7ebf\u3001\u6539\u53d8\u9632\u6b62\u65b9\u5411\uff08\u82af\u7247\u5e73\u653e\uff09\u65e0\u6cd5\u89e3\u51b3\u4f60\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u8bd5\u8bd5\u5c06\u540e\u9762\u7684\u6761\u4ef6\u5224\u65ad\u4fee\u6539\u4e3a\u4f60\u7684\u503c\uff0c\u770b\u770b\u662f\u5426\u53ef\u4ee5\u51fa\u6570\u636e\uff0c\u4f46\u662f\u5982\u679c\u51fa\u4e86\u6570\u636e\uff0c\u5bf9\u6570\u636e\u7684\u51c6\u786e\u6027\u65e0\u6cd5\u505a\u4ee5\u4fdd\u8bc1\u3002<\/p>\n<h5>mpu_init\u95ee\u9898<\/h5>\n<p>\u8fd9\u91cc\u7684\u95ee\u9898\u4e00\u822c\u662f\u7531\u4e8eIIC\u914d\u7f6e\u9519\u8bef\u5bfc\u81f4\u7684\u3002<\/p>\n<p>\u8fdb\u5165\u51fd\u6570\u5185\u4e0d\u51fa\u610f\u5916\u7684\u8bdd\u7a0b\u5e8f\u4f1a\u5728i2c_write\u8fd4\u56de-1\uff0c\u6b64\u65f6\u8fdb\u5165\u51fd\u6570\u5185\u90e8\u67e5\u770b\u8fd4\u56de\u503c\uff1a<\/p>\n<p><strong>HAL_ERROR:<\/strong>\u8bf7\u68c0\u67e5\u4e4b\u524d\u76840x68\u6539\u4e3a0xD0\u662f\u5426\u6709\u66f4\u6539\u3002\u5982\u679c\u66f4\u6539\u4e86\uff0c\u5219\u53ef\u80fd\u662f\u5176\u4ed6\u7684\u5730\u65b9\u5730\u5740\u51fa\u73b0\u95ee\u9898\u3002\uff08\u68c0\u67e5AD0\u5f15\u811a\u662f\u5426\u88ab\u62c9\u9ad8\uff0c\u82e5\u62c9\u9ad8\u5219\u5730\u5740\u5e94\u4e3a0xD1\uff09\u3002<\/p>\n<p><strong>HAL_BUSY:<\/strong>\u786c\u4ef6IIC\u4f1a\u51fa\u73b0\u7684busy\u9501\u6b7b\u95ee\u9898\uff0c\u8fd9\u662fST\u786c\u4ef6\u4e0a\u7684\u4e00\u70b9\u5c0f\u95ee\u9898\uff0c\u53ef\u80fd\u5df2\u7ecf\u5728\u540e\u7eed\u7684\u4ea7\u54c1\u4e2d\u4fee\u590d\u3002\u4e34\u65f6\u89e3\u51b3\u529e\u6cd5\u662f\u628a\u8bbe\u5907\u5b8c\u5168\u65ad\u7535\uff0c\u5728\u4e0d\u4e0aIIC\u7684\u60c5\u51b5\u4e0b\u4e0a\u7535\uff0c\u6e05\u9664BUSY\u4f4d\u540e\u65ad\u7535\u91cd\u65b0\u63d2\u7ebf\u5373\u53ef\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n<h5>dmp_read_fifo\u95ee\u9898<\/h5>\n<p>\u8fdb\u5165\u51fd\u6570\u5185\u90e8\uff0c\u4e0d\u51fa\u610f\u5916\u662fmpu_read_fifo_stream\u8fd9\u4e2a\u51fd\u6570\u5904\u8fd4\u56de\u4e86-1\uff0c\u8fd9\u8bf4\u660e\u6211\u4eec\u8bfb\u53d6\u901f\u5ea6\u592a\u6162\u4e86\u5bfc\u81f4\u4e86FIFO\u6ea2\u51fa\uff0c\u53ea\u9700\u8981\u5728\u8bfb\u53d6\u8bed\u53e5\u4e4b\u540e\u52a0\u4e0a\u4e00\u884c\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"lang-C\">while(mpu_dmp_get_data(&amp;pitch,&amp;roll,&amp;yaw));<\/code><\/pre>\n<p>\u5728FIFO\u4e0b\u6b21\u6ea2\u51fa\u524d\u518d\u6b21\u8bfb\u53d6\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b66\u4e60\u8fc7\u7a0b\u4e2d\u7528\u5230\u7684\u8d44\u6599\u6574\u7406\u4e86\u4e0b\u5b58\u4e86\u8d77\u6765\uff1a https:\/\/wwe.lanzouv.com\/iROIKnjuo6h [&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":[16,14],"class_list":["post-119","post","type-post","status-publish","format-standard","hentry","category-embedded","tag-mpu6050","tag-14"],"_links":{"self":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts\/119","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=119"}],"version-history":[{"count":0,"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts\/119\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}