Files
MicrochipFor32/Doc/docbook/mpu6050_8cpp_source.xml

108 lines
24 KiB
XML
Raw Normal View History

<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<section xmlns="http://docbook.org/ns/docbook" version="5.0" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="_mpu6050_8cpp_source" xml:lang="zh">
<title>mpu6050.cpp</title>
<indexterm><primary>D:/gitt/MicrochipFor32/bsp_MPU6050/mpu6050.cpp</primary></indexterm>
浏览该文件的文档.<programlisting linenumbering="unnumbered"><anchor xml:id="_mpu6050_8cpp_source_1l00001"/>00001
<anchor xml:id="_mpu6050_8cpp_source_1l00012"/>00012 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00013"/>00013 <emphasis role="comment">//&#32;&#32;头文件</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00014"/>00014 <emphasis role="preprocessor">#include&#32;&quot;bscpp_IIC_STM32.h&quot;</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00015"/>00015 <emphasis role="preprocessor">#include&#32;&quot;<link linkend="_mpu6050_8h">mpu6050.h</link>&quot;</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00016"/><link linkend="_mpu6050_8cpp_1ae7d7fd8356f1a04698bf36a2ff087f7b">00016</link> <emphasis role="preprocessor">#define&#32;delay_ms(var)&#32;HAL_Delay(var)</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00017"/><link linkend="_mpu6050_8cpp_1a0e5583807e7dcaae30835311a2195583">00017</link> bscpp_IIC_STM32&#32;<link linkend="_mpu6050_8cpp_1a0e5583807e7dcaae30835311a2195583">mpu6050IIC</link>(IIC_SCK_GPIO_Port,IIC_SCK_Pin,IIC_SDA_GPIO_Port,IIC_SDA_Pin);
<anchor xml:id="_mpu6050_8cpp_source_1l00019"/>00019 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00020"/>00020 <emphasis role="comment">//&#32;&#32;函数区</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00025"/><link linkend="_mpu6050_8cpp_1ab1f8c6111d59b60a2edb4ee3e8aa3113">00025</link> <emphasis role="comment"></emphasis><link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;<link linkend="_mpu6050_8cpp_1ab1f8c6111d59b60a2edb4ee3e8aa3113">MPU_Init</link>(<emphasis role="keywordtype">void</emphasis>){
<anchor xml:id="_mpu6050_8cpp_source_1l00026"/>00026 &#32;&#32;&#32;&#32;<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;res;
<anchor xml:id="_mpu6050_8cpp_source_1l00027"/>00027 &#32;&#32;&#32;&#32;<emphasis role="comment">//MPU_IIC_Init();//初始化IIC总线</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00028"/>00028 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1abbe7ea135ee03eb0f1296ecb22be7554">MPU_PWR_MGMT1_REG</link>,0X80);&#32;<emphasis role="comment">//复位MPU6050</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00029"/>00029 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1ae7d7fd8356f1a04698bf36a2ff087f7b">delay_ms</link>(100);
<anchor xml:id="_mpu6050_8cpp_source_1l00030"/>00030 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1abbe7ea135ee03eb0f1296ecb22be7554">MPU_PWR_MGMT1_REG</link>,0X00);&#32;<emphasis role="comment">//唤醒MPU6050&#32;</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00031"/>00031 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1aa27cc30326ce4980b289a0e1c3f76b5e">MPU_Set_Gyro_Fsr</link>(3);&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//陀螺仪传感器,±2000dps</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00032"/>00032 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a6c391137bc5880c3b5e15e84c5a3380f">MPU_Set_Accel_Fsr</link>(0);&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//加速度传感器,±2g</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00033"/>00033 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a04e58232ce838e94d54aa2b53287cb41">MPU_Set_Rate</link>(50);&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//设置采样率50Hz</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00034"/>00034 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1afa56d3602a6044562c45cecf6403fb8b">MPU_INT_EN_REG</link>,0X00);&#32;&#32;&#32;&#32;<emphasis role="comment">//关闭所有中断</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00035"/>00035 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1a0146ef35d7ff0b037eafb0a5dac53b0f">MPU_USER_CTRL_REG</link>,0X00);&#32;<emphasis role="comment">//I2C主模式关闭</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00036"/>00036 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1a6ac27367cd834a85810e99df72b97621">MPU_FIFO_EN_REG</link>,0X00);&#32;&#32;&#32;<emphasis role="comment">//关闭FIFO</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00037"/>00037 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1a41676476ba5dbb1b213f8f8e252d17f9">MPU_INTBP_CFG_REG</link>,0X80);&#32;<emphasis role="comment">//INT引脚低电平有效</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00038"/>00038 &#32;&#32;&#32;&#32;res=<link linkend="_mpu6050_8cpp_1a17c11d19a2bb21d61610f08cb2cbe2f7">MPU_Read_Byte</link>(<link linkend="_mpu6050_8h_1a9668e5ccfcfb0aa64da044a381a56f9c">MPU_DEVICE_ID_REG</link>);
<anchor xml:id="_mpu6050_8cpp_source_1l00039"/>00039 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">if</emphasis>(res==<link linkend="_mpu6050_8h_1ac3281ee64415e63422da7d65db161891">MPU_ADDR</link>)<emphasis role="comment">//器件ID正确</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00040"/>00040 &#32;&#32;&#32;&#32;{
<anchor xml:id="_mpu6050_8cpp_source_1l00041"/>00041 &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1abbe7ea135ee03eb0f1296ecb22be7554">MPU_PWR_MGMT1_REG</link>,0X01);&#32;<emphasis role="comment">//设置CLKSEL,PLL&#32;X轴为参考</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00042"/>00042 &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1a3fa9eb0485744e73d0274b198f0ad705">MPU_PWR_MGMT2_REG</link>,0X00);&#32;<emphasis role="comment">//加速度与陀螺仪都工作</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00043"/>00043 &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a04e58232ce838e94d54aa2b53287cb41">MPU_Set_Rate</link>(50);&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;<emphasis role="comment">//设置采样率为50Hz</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00044"/>00044 &#32;&#32;&#32;&#32;}<emphasis role="keywordflow">else</emphasis>&#32;<emphasis role="keywordflow">return</emphasis>&#32;1;
<anchor xml:id="_mpu6050_8cpp_source_1l00045"/>00045 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;0;}
<anchor xml:id="_mpu6050_8cpp_source_1l00046"/>00046 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00055"/><link linkend="_mpu6050_8cpp_1aa27cc30326ce4980b289a0e1c3f76b5e">00055</link> <emphasis role="comment"></emphasis><link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;<link linkend="_mpu6050_8cpp_1aa27cc30326ce4980b289a0e1c3f76b5e">MPU_Set_Gyro_Fsr</link>(<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;fsr){
<anchor xml:id="_mpu6050_8cpp_source_1l00056"/>00056 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1ac8ce2e66126327cf30cfba19c4c38db5">MPU_GYRO_CFG_REG</link>,fsr&lt;&lt;3);<emphasis role="comment">//设置陀螺仪满量程范围&#32;&#32;</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00057"/>00057 &#32;&#32;&#32;&#32;}
<anchor xml:id="_mpu6050_8cpp_source_1l00058"/>00058 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00067"/><link linkend="_mpu6050_8cpp_1a6c391137bc5880c3b5e15e84c5a3380f">00067</link> <emphasis role="comment"></emphasis><link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;<link linkend="_mpu6050_8cpp_1a6c391137bc5880c3b5e15e84c5a3380f">MPU_Set_Accel_Fsr</link>(<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;fsr){
<anchor xml:id="_mpu6050_8cpp_source_1l00068"/>00068 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1a7bc1a37b846a3869f13a29e00072bbc7">MPU_ACCEL_CFG_REG</link>,fsr&lt;&lt;3);<emphasis role="comment">//设置加速度传感器满量程范围&#32;&#32;</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00069"/>00069 &#32;&#32;&#32;&#32;}
<anchor xml:id="_mpu6050_8cpp_source_1l00070"/>00070 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00076"/><link linkend="_mpu6050_8cpp_1a2fb9973c9f5ea5327649d0eef5e96217">00076</link> <emphasis role="comment"></emphasis><link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;<link linkend="_mpu6050_8cpp_1a2fb9973c9f5ea5327649d0eef5e96217">MPU_Set_LPF</link>(<link linkend="_varint_8h_1ace9d960e74685e2cd84b36132dbbf8aa">u16</link>&#32;lpf){
<anchor xml:id="_mpu6050_8cpp_source_1l00077"/>00077 &#32;&#32;&#32;&#32;<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;data=0;
<anchor xml:id="_mpu6050_8cpp_source_1l00078"/>00078 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">if</emphasis>(lpf&gt;=188)data=1;
<anchor xml:id="_mpu6050_8cpp_source_1l00079"/>00079 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">else</emphasis>&#32;<emphasis role="keywordflow">if</emphasis>(lpf&gt;=98)data=2;
<anchor xml:id="_mpu6050_8cpp_source_1l00080"/>00080 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">else</emphasis>&#32;<emphasis role="keywordflow">if</emphasis>(lpf&gt;=42)data=3;
<anchor xml:id="_mpu6050_8cpp_source_1l00081"/>00081 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">else</emphasis>&#32;<emphasis role="keywordflow">if</emphasis>(lpf&gt;=20)data=4;
<anchor xml:id="_mpu6050_8cpp_source_1l00082"/>00082 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">else</emphasis>&#32;<emphasis role="keywordflow">if</emphasis>(lpf&gt;=10)data=5;
<anchor xml:id="_mpu6050_8cpp_source_1l00083"/>00083 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">else</emphasis>&#32;data=6;&#32;
<anchor xml:id="_mpu6050_8cpp_source_1l00084"/>00084 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1a5034e2fc680fc68faa369a48f6955837">MPU_CFG_REG</link>,data);<emphasis role="comment">//设置数字低通滤波器&#32;&#32;</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00085"/>00085 &#32;&#32;&#32;&#32;}
<anchor xml:id="_mpu6050_8cpp_source_1l00086"/>00086 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00092"/><link linkend="_mpu6050_8cpp_1a04e58232ce838e94d54aa2b53287cb41">00092</link> <emphasis role="comment"></emphasis><link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;<link linkend="_mpu6050_8cpp_1a04e58232ce838e94d54aa2b53287cb41">MPU_Set_Rate</link>(<link linkend="_varint_8h_1ace9d960e74685e2cd84b36132dbbf8aa">u16</link>&#32;rate){
<anchor xml:id="_mpu6050_8cpp_source_1l00093"/>00093 &#32;&#32;&#32;&#32;<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;data;
<anchor xml:id="_mpu6050_8cpp_source_1l00094"/>00094 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">if</emphasis>(rate&gt;1000)rate=1000;
<anchor xml:id="_mpu6050_8cpp_source_1l00095"/>00095 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">if</emphasis>(rate&lt;4)rate=4;
<anchor xml:id="_mpu6050_8cpp_source_1l00096"/>00096 &#32;&#32;&#32;&#32;data=1000/rate-1;
<anchor xml:id="_mpu6050_8cpp_source_1l00097"/>00097 &#32;&#32;&#32;&#32;data=<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_mpu6050_8h_1a4b95cfafadb4b30146a17fac36819ca3">MPU_SAMPLE_RATE_REG</link>,data);&#32;&#32;<emphasis role="comment">//设置数字低通滤波器</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00098"/>00098 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;<link linkend="_mpu6050_8cpp_1a2fb9973c9f5ea5327649d0eef5e96217">MPU_Set_LPF</link>(rate/2);&#32;<emphasis role="comment">//自动设置LPF为采样率的一半</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00099"/>00099 &#32;&#32;&#32;&#32;}
<anchor xml:id="_mpu6050_8cpp_source_1l00100"/>00100 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00105"/><link linkend="_mpu6050_8cpp_1a41eaf87c26b1281d9d5fc6a06abcf2a8">00105</link> <emphasis role="comment"></emphasis><emphasis role="keywordtype">short</emphasis>&#32;<link linkend="_mpu6050_8cpp_1a41eaf87c26b1281d9d5fc6a06abcf2a8">MPU_Get_Temperature</link>(<emphasis role="keywordtype">void</emphasis>){
<anchor xml:id="_mpu6050_8cpp_source_1l00106"/>00106 &#32;&#32;&#32;&#32;<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;buf[2];&#32;
<anchor xml:id="_mpu6050_8cpp_source_1l00107"/>00107 &#32;&#32;&#32;&#32;<emphasis role="keywordtype">short</emphasis>&#32;raw;
<anchor xml:id="_mpu6050_8cpp_source_1l00108"/>00108 &#32;&#32;&#32;&#32;<emphasis role="keywordtype">float</emphasis>&#32;temp;
<anchor xml:id="_mpu6050_8cpp_source_1l00109"/>00109 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a63161fa966899e4e7c5791e40ebf2b0a">MPU_Read_Len</link>(<link linkend="_mpu6050_8h_1ac3281ee64415e63422da7d65db161891">MPU_ADDR</link>,<link linkend="_mpu6050_8h_1af2665b26b7f1ce9b3982a9f6418748e9">MPU_TEMP_OUTH_REG</link>,2,buf);&#32;
<anchor xml:id="_mpu6050_8cpp_source_1l00110"/>00110 &#32;&#32;&#32;&#32;raw=((<link linkend="_varint_8h_1ace9d960e74685e2cd84b36132dbbf8aa">u16</link>)buf[0]&lt;&lt;8)|buf[1];&#32;&#32;
<anchor xml:id="_mpu6050_8cpp_source_1l00111"/>00111 &#32;&#32;&#32;&#32;temp=36.53+((double)raw)/340;&#32;&#32;
<anchor xml:id="_mpu6050_8cpp_source_1l00112"/>00112 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;temp*100;}
<anchor xml:id="_mpu6050_8cpp_source_1l00113"/>00113 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00121"/><link linkend="_mpu6050_8cpp_1a8f28105f9dcccc709b78d7d0ce497633">00121</link> <emphasis role="comment"></emphasis><link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;<link linkend="_mpu6050_8cpp_1a8f28105f9dcccc709b78d7d0ce497633">MPU_Get_Gyroscope</link>(<emphasis role="keywordtype">short</emphasis>&#32;*gx,<emphasis role="keywordtype">short</emphasis>&#32;*gy,<emphasis role="keywordtype">short</emphasis>&#32;*gz){
<anchor xml:id="_mpu6050_8cpp_source_1l00122"/>00122 &#32;&#32;&#32;&#32;<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;buf[6],res;&#32;&#32;
<anchor xml:id="_mpu6050_8cpp_source_1l00123"/>00123 &#32;&#32;&#32;&#32;res=<link linkend="_mpu6050_8cpp_1a63161fa966899e4e7c5791e40ebf2b0a">MPU_Read_Len</link>(<link linkend="_mpu6050_8h_1ac3281ee64415e63422da7d65db161891">MPU_ADDR</link>,<link linkend="_mpu6050_8h_1a7e16f1a459d902b070ca67df67be862b">MPU_GYRO_XOUTH_REG</link>,6,buf);
<anchor xml:id="_mpu6050_8cpp_source_1l00124"/>00124 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">if</emphasis>(res==0){
<anchor xml:id="_mpu6050_8cpp_source_1l00125"/>00125 &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;*gx=((<link linkend="_varint_8h_1ace9d960e74685e2cd84b36132dbbf8aa">u16</link>)buf[0]&lt;&lt;8)|buf[1];&#32;&#32;
<anchor xml:id="_mpu6050_8cpp_source_1l00126"/>00126 &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;*gy=((<link linkend="_varint_8h_1ace9d960e74685e2cd84b36132dbbf8aa">u16</link>)buf[2]&lt;&lt;8)|buf[3];&#32;&#32;
<anchor xml:id="_mpu6050_8cpp_source_1l00127"/>00127 &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;*gz=((<link linkend="_varint_8h_1ace9d960e74685e2cd84b36132dbbf8aa">u16</link>)buf[4]&lt;&lt;8)|buf[5];}
<anchor xml:id="_mpu6050_8cpp_source_1l00128"/>00128 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;res;}
<anchor xml:id="_mpu6050_8cpp_source_1l00129"/>00129 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00137"/><link linkend="_mpu6050_8cpp_1a2a0a02f6d7c597828a0cc282c76e99e3">00137</link> <emphasis role="comment"></emphasis><link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;<link linkend="_mpu6050_8cpp_1a2a0a02f6d7c597828a0cc282c76e99e3">MPU_Get_Accelerometer</link>(<emphasis role="keywordtype">short</emphasis>&#32;*ax,<emphasis role="keywordtype">short</emphasis>&#32;*ay,<emphasis role="keywordtype">short</emphasis>&#32;*az){
<anchor xml:id="_mpu6050_8cpp_source_1l00138"/>00138 &#32;&#32;&#32;&#32;<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;buf[6],res;&#32;&#32;
<anchor xml:id="_mpu6050_8cpp_source_1l00139"/>00139 &#32;&#32;&#32;&#32;res=<link linkend="_mpu6050_8cpp_1a63161fa966899e4e7c5791e40ebf2b0a">MPU_Read_Len</link>(<link linkend="_mpu6050_8h_1ac3281ee64415e63422da7d65db161891">MPU_ADDR</link>,<link linkend="_mpu6050_8h_1a571a31cdf2a467b2b1df39fea686ea0d">MPU_ACCEL_XOUTH_REG</link>,6,buf);
<anchor xml:id="_mpu6050_8cpp_source_1l00140"/>00140 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">if</emphasis>(res==0){
<anchor xml:id="_mpu6050_8cpp_source_1l00141"/>00141 &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;*ax=((<link linkend="_varint_8h_1ace9d960e74685e2cd84b36132dbbf8aa">u16</link>)buf[0]&lt;&lt;8)|buf[1];&#32;&#32;
<anchor xml:id="_mpu6050_8cpp_source_1l00142"/>00142 &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;*ay=((<link linkend="_varint_8h_1ace9d960e74685e2cd84b36132dbbf8aa">u16</link>)buf[2]&lt;&lt;8)|buf[3];&#32;&#32;
<anchor xml:id="_mpu6050_8cpp_source_1l00143"/>00143 &#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;*az=((<link linkend="_varint_8h_1ace9d960e74685e2cd84b36132dbbf8aa">u16</link>)buf[4]&lt;&lt;8)|buf[5];}
<anchor xml:id="_mpu6050_8cpp_source_1l00144"/>00144 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;res;}
<anchor xml:id="_mpu6050_8cpp_source_1l00146"/>00146 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00147"/>00147 <emphasis role="comment">//&#32;&#32;适配区</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00156"/><link linkend="_mpu6050_8cpp_1a59b1c26b234be88e97435a1b3c061330">00156</link> <emphasis role="comment"></emphasis><link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;<link linkend="_mpu6050_8cpp_1a59b1c26b234be88e97435a1b3c061330">MPU_Write_Len</link>(<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;addr,<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;reg,<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;len,<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;*buf){
<anchor xml:id="_mpu6050_8cpp_source_1l00157"/>00157 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a0e5583807e7dcaae30835311a2195583">mpu6050IIC</link>.IIC_Write(addr,reg,(<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>*)buf,len);
<anchor xml:id="_mpu6050_8cpp_source_1l00158"/>00158 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;0;}
<anchor xml:id="_mpu6050_8cpp_source_1l00159"/>00159 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00168"/><link linkend="_mpu6050_8cpp_1a63161fa966899e4e7c5791e40ebf2b0a">00168</link> <emphasis role="comment"></emphasis><link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;<link linkend="_mpu6050_8cpp_1a63161fa966899e4e7c5791e40ebf2b0a">MPU_Read_Len</link>(<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;addr,<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;reg,<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;len,<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;*buf){
<anchor xml:id="_mpu6050_8cpp_source_1l00169"/>00169 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a0e5583807e7dcaae30835311a2195583">mpu6050IIC</link>.IIC_Read(addr,reg,(<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>*)buf,len);
<anchor xml:id="_mpu6050_8cpp_source_1l00170"/>00170 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;0;}
<anchor xml:id="_mpu6050_8cpp_source_1l00171"/>00171 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00178"/><link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">00178</link> <emphasis role="comment"></emphasis><link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;<link linkend="_mpu6050_8cpp_1a0be9b422bb8613f8444db4af5234e1a1">MPU_Write_Byte</link>(<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;reg,<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;data){
<anchor xml:id="_mpu6050_8cpp_source_1l00179"/>00179 &#32;&#32;&#32;&#32;<link linkend="_mpu6050_8cpp_1a0e5583807e7dcaae30835311a2195583">mpu6050IIC</link>.IIC_WriteOneByte(<link linkend="_mpu6050_8h_1ac3281ee64415e63422da7d65db161891">MPU_ADDR</link>,reg,data);
<anchor xml:id="_mpu6050_8cpp_source_1l00180"/>00180 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;0;}
<anchor xml:id="_mpu6050_8cpp_source_1l00181"/>00181 <emphasis role="comment">//----------------------------------------------------------------------------------------------------</emphasis>
<anchor xml:id="_mpu6050_8cpp_source_1l00187"/><link linkend="_mpu6050_8cpp_1a17c11d19a2bb21d61610f08cb2cbe2f7">00187</link> <emphasis role="comment"></emphasis><link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;<link linkend="_mpu6050_8cpp_1a17c11d19a2bb21d61610f08cb2cbe2f7">MPU_Read_Byte</link>(<link linkend="_varint_8h_1a92c50087ca0e64fa93fc59402c55f8ca">u8</link>&#32;reg){
<anchor xml:id="_mpu6050_8cpp_source_1l00188"/>00188 &#32;&#32;&#32;&#32;<emphasis role="keywordflow">return</emphasis>&#32;<link linkend="_mpu6050_8cpp_1a0e5583807e7dcaae30835311a2195583">mpu6050IIC</link>.IIC_ReadOneByte(<link linkend="_mpu6050_8h_1ac3281ee64415e63422da7d65db161891">MPU_ADDR</link>,reg);}
<anchor xml:id="_mpu6050_8cpp_source_1l00190"/>00190
</programlisting></section>