{"id":32650,"date":"2025-04-24T20:18:30","date_gmt":"2025-04-24T12:18:30","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/32650.html"},"modified":"2025-04-24T20:18:30","modified_gmt":"2025-04-24T12:18:30","slug":"stm32%e7%89%88i%c2%b2c%e7%9b%b8%e4%ba%b2%e6%8c%87%e5%8d%97%ef%bc%88%e8%bd%af%e4%bb%b6%e7%a1%ac%e4%bb%b6%e5%8f%8c%e4%bf%ae%e7%89%88%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/32650.html","title":{"rendered":"STM32\u7248I\u00b2C\u76f8\u4eb2\u6307\u5357\uff08\u8f6f\u4ef6\u786c\u4ef6\u53cc\u4fee\u7248\uff09"},"content":{"rendered":"<h3>STM32\u7248I\u00b2C\u76f8\u4eb2\u6307\u5357&#xff08;\u8f6f\u4ef6\u786c\u4ef6\u53cc\u4fee\u7248&#xff09;<\/h3>\n<h4>\u4e00\u3001I\u00b2C\u534f\u8bae\u57fa\u7840&#xff1a;\u7535\u5b50\u4e16\u754c\u7684\u9e4a\u6865\u76f8\u4f1a<\/h4>\n<p>I\u00b2C\u662f\u4ec0\u4e48&#xff1f; \u5c31\u50cf\u725b\u90ce\u7ec7\u5973\u9700\u8981\u9e4a\u6865\u76f8\u4f1a&#xff0c;\u7535\u5b50\u5143\u4ef6\u4e5f\u9700\u8981\u901a\u4fe1\u6865\u6881\u3002I\u00b2C&#xff08;Inter-Integrated Circuit&#xff09;\u662f\u98de\u5229\u6d66\u53d1\u660e\u7684\u4e24\u7ebf\u5236\u4e32\u884c\u603b\u7ebf&#xff0c;\u7531&#xff1a;<\/p>\n<ul>\n<li>SCL&#xff08;Serial Clock&#xff09;\u65f6\u949f\u7ebf \u2014\u2014 \u5fc3\u8df3\u8282\u62cd\u5668<\/li>\n<li>SDA&#xff08;Serial Data&#xff09;\u6570\u636e\u7ebf \u2014\u2014 \u7231\u60c5\u4f20\u58f0\u7b52 \u6784\u6210\u3002\u5b83\u5982\u540c\u7535\u5b50\u4e16\u754c\u7684&#034;\u5a5a\u4ecb\u6240&#034;&#xff0c;\u652f\u6301\u591a\u4e3b\u591a\u4ece\u901a\u4fe1&#xff08;\u6700\u591a127\u4e2a\u8bbe\u5907&#xff09;&#xff0c;\u662f\u5d4c\u5165\u5f0f\u7cfb\u7edf\u6700\u5e38\u7528\u7684&#034;\u76f8\u4eb2\u534f\u8bae&#034;\u3002<\/li>\n<\/ul>\n<h4>\u4e8c\u3001I\u00b2C\u5de5\u4f5c\u539f\u7406&#xff1a;\u56db\u6b65\u76f8\u4eb2\u6d41\u7a0b<\/h4>\n<h5>1. \u7f18\u5206\u8d77\u59cb&#xff08;START\u4fe1\u53f7&#xff09;<\/h5>\n<p>\u5982\u540c\u6708\u8001\u629b\u51fa\u7ea2\u7ebf&#xff0c;\u4e3b\u8bbe\u5907\u62c9\u4f4eSDA\u540e\u62c9\u4f4eSCL&#xff0c;\u751f\u6210&#034;\u5fc3\u8df3\u8d77\u640f\u5668&#034;&#xff1a;<\/p>\n<p>        ______<br \/>\nSDA: __|      |______&#8230;<br \/>\nSCL: ____|\u00af\u00af\u00af\u00af|____&#8230;<br \/>\n       \u2191 \u7231\u60c5\u5f00\u59cb<\/p>\n<h5>2. \u81ea\u6211\u4ecb\u7ecd&#xff08;\u5730\u5740\u4f20\u8f93&#xff09;<\/h5>\n<p>\u4e3b\u8bbe\u5907\u53d1\u90017\/10\u4f4d\u8bbe\u5907\u5730\u5740 &#043; 1\u4f4d\u65b9\u5411\u4f4d&#xff08;0\u51991\u8bfb&#xff09;&#xff0c;\u50cf\u9012\u51fa\u7231\u60c5\u7b80\u5386&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u4f8b\u5982MPU6050\u5730\u57400x68&#xff08;\u4e8c\u8fdb\u523601101000&#xff09;<\/span><br \/>\n<span class=\"token number\">0<\/span> <span class=\"token number\">1<\/span> <span class=\"token number\">1<\/span> <span class=\"token number\">0<\/span> <span class=\"token number\">1<\/span> <span class=\"token number\">0<\/span> <span class=\"token number\">0<\/span> <span class=\"token number\">0<\/span> <span class=\"token operator\">|<\/span> <span class=\"token number\">0<\/span> \u2192 \u5199\u6a21\u5f0f<br \/>\n\u2191_____________\u2191   \u2191<br \/>\n \u8bbe\u5907\u8eab\u4efd\u8bc1      \u64cd\u4f5c\u610f\u5411<\/p>\n<h5>3. \u53cc\u5411\u5954\u8d74&#xff08;\u6570\u636e\u4f20\u8f93&#xff09;<\/h5>\n<p>\u4ece\u8bbe\u5907\u901a\u8fc7ACK&#xff08;\u62c9\u4f4eSDA&#xff09;\u56de\u5e94&#xff0c;\u6570\u636e\u50cf\u60c5\u4e66\u822c\u5728\u65f6\u949f\u9ad8\u7535\u5e73\u65f6\u6709\u6548&#xff1a;<\/p>\n<p>     \u6570\u636e\u6709\u6548\u533a<br \/>\n     \u2197&#8212;\u2198<br \/>\nSDA: __|\u00af\u00af|__|\u00af\u00af|__&#8230;<br \/>\nSCL: ____|\u00af\u00af\u00af|____|\u00af\u00af&#8230;<\/p>\n<h5>4. \u7f18\u5206\u6682\u505c\/\u7ed3\u675f&#xff08;STOP\u4fe1\u53f7&#xff09;<\/h5>\n<p>\u5f53SCL\u9ad8\u7535\u5e73\u65f6SDA\u7531\u4f4e\u53d8\u9ad8&#xff0c;\u5982\u540c\u4f18\u96c5\u7684\u544a\u522b&#xff1a;<\/p>\n<p>        __________<br \/>\nSDA: __|          |&#8230;<br \/>\nSCL: ____|\u00af\u00af\u00af\u00af|______&#8230;<br \/>\n       \u2191 \u66f2\u7ec8\u4eba\u6563<\/p>\n<h4>\u4e09\u3001\u786c\u4ef6I\u00b2C vs \u8f6f\u4ef6I\u00b2C<\/h4>\n<table>\n<tr>\u7279\u6027\u786c\u4ef6I\u00b2C\u8f6f\u4ef6I\u00b2C<\/tr>\n<tbody>\n<tr>\n<td>\u5b9e\u73b0\u65b9\u5f0f<\/td>\n<td>\u4e13\u7528\u7535\u8def&#xff08;\u5a5a\u59fb\u767b\u8bb0\u6240&#xff09;<\/td>\n<td>GPIO\u6a21\u62df&#xff08;\u624b\u5199\u60c5\u4e66&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u901f\u5ea6<\/td>\n<td>\u53ef\u8fbe400kHz&#xff08;\u95ea\u5a5a&#xff09;<\/td>\n<td>\u901a\u5e38\u2264100kHz&#xff08;\u6162\u70ed\u578b&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>CPU\u5360\u7528<\/td>\n<td>\u81ea\u52a8\u5b8c\u6210&#xff08;\u5a5a\u5e86\u516c\u53f8\u5168\u5305&#xff09;<\/td>\n<td>\u9700\u6301\u7eed\u63a7\u5236&#xff08;DIY\u5a5a\u793c&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u7075\u6d3b\u6027<\/td>\n<td>\u5f15\u811a\u56fa\u5b9a&#xff08;\u5305\u529e\u5a5a\u59fb&#xff09;<\/td>\n<td>\u4efb\u610fGPIO&#xff08;\u81ea\u7531\u604b\u7231&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5f00\u53d1\u96be\u5ea6<\/td>\n<td>\u9700\u914d\u7f6e\u5bc4\u5b58\u5668&#xff08;\u586b\u5199\u7ed3\u5a5a\u7533\u8bf7\u8868&#xff09;<\/td>\n<td>\u65f6\u5e8f\u9700\u7cbe\u786e\u63a7\u5236&#xff08;\u80cc\u8bf5\u604b\u7231\u5b88\u5219&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u56db\u3001\u8f6f\u4ef6I\u00b2C\u767b\u573a&#xff1a;GPIO\u6708\u8001\u624b\u6413\u7ea2\u7ebf<\/h4>\n<p><span class=\"token comment\">\/* \u50cf\u7f16\u7ec7\u4e2d\u56fd\u7ed3\u4e00\u6837\u64cd\u4f5cGPIO *\/<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">SOFT_SCL_PIN<\/span>  <span class=\"token expression\">GPIO_Pin_8<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">SOFT_SDA_PIN<\/span>  <span class=\"token expression\">GPIO_Pin_9<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">SOFT_I2C_PORT<\/span> <span class=\"token expression\">GPIOB<\/span><\/span><\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">Software_I2C_Init<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    GPIO_InitTypeDef GPIO_InitStruct<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u5f00\u542fGPIOB\u7684\u65f6\u949f\u7279\u6743<\/span><br \/>\n    <span class=\"token function\">RCC_APB2PeriphClockCmd<\/span><span class=\"token punctuation\">(<\/span>RCC_APB2Periph_GPIOB<span class=\"token punctuation\">,<\/span> ENABLE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u914d\u7f6eGPIO\u4e3a\u63a8\u633d\u8f93\u51fa\u6a21\u5f0f&#xff08;\u6708\u8001\u6a21\u5f0f&#xff09;<\/span><br \/>\n    GPIO_InitStruct<span class=\"token punctuation\">.<\/span>GPIO_Pin <span class=\"token operator\">&#061;<\/span> SOFT_SCL_PIN <span class=\"token operator\">|<\/span> SOFT_SDA_PIN<span class=\"token punctuation\">;<\/span><br \/>\n    GPIO_InitStruct<span class=\"token punctuation\">.<\/span>GPIO_Mode <span class=\"token operator\">&#061;<\/span> GPIO_Mode_Out_PP<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u63a8\u633d\u8f93\u51fa&#xff0c;\u624b\u901f\u8981\u5feb<\/span><br \/>\n    GPIO_InitStruct<span class=\"token punctuation\">.<\/span>GPIO_Speed <span class=\"token operator\">&#061;<\/span> GPIO_Speed_50MHz<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u6708\u8001\u624b\u901f50MHz<\/span><br \/>\n    <span class=\"token function\">GPIO_Init<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>GPIO_InitStruct<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u521d\u59cb\u72b6\u6001&#xff1a;\u91ca\u653e\u603b\u7ebf&#xff08;\u9ad8\u7535\u5e73&#xff09;<\/span><br \/>\n    <span class=\"token function\">GPIO_SetBits<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> SOFT_SCL_PIN <span class=\"token operator\">|<\/span> SOFT_SDA_PIN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/* \u8d77\u59cb\u4fe1\u53f7\u8be6\u89e3 &#8211; \u7535\u5b50\u4e16\u754c\u7684\u7709\u76ee\u4f20\u60c5 *\/<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">Software_I2C_Start<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u6b65\u9aa41&#xff1a;SDA\u5148\u4f4e\u5934\u793a\u7231&#xff08;\u4e0b\u964d\u6cbf&#xff09;<\/span><br \/>\n    <span class=\"token function\">GPIO_ResetBits<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> SOFT_SDA_PIN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">Delay_us<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u7b49\u5f85\u5fc3\u52a8\u5468\u671f<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u6b65\u9aa42&#xff1a;SCL\u7d27\u968f\u5176\u540e\u786e\u8ba4&#xff08;\u5f62\u6210\u5fc3\u8df3\u540c\u6b65&#xff09;<\/span><br \/>\n    <span class=\"token function\">GPIO_ResetBits<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> SOFT_SCL_PIN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">Software_I2C_Stop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">GPIO_ResetBits<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> SOFT_SCL_PIN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5148\u6309\u4f4eSCL<\/span><br \/>\n    <span class=\"token function\">Delay_us<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">GPIO_ResetBits<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> SOFT_SDA_PIN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ SDA\u4e3b\u52a8\u793a\u597d<\/span><br \/>\n    <span class=\"token function\">Delay_us<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">GPIO_SetBits<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> SOFT_SCL_PIN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ SCL\u4f18\u96c5\u79bb\u573a<\/span><br \/>\n    <span class=\"token function\">Delay_us<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">GPIO_SetBits<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> SOFT_SDA_PIN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ SDA\u6700\u540e\u653e\u624b<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\">\/* ACK\u68c0\u6d4b &#8211; \u7231\u60c5\u7684\u56de\u58f0\u63a2\u6d4b\u5668 *\/<\/span><br \/>\n<span class=\"token class-name\">uint8_t<\/span> <span class=\"token function\">Software_I2C_WaitAck<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">GPIO_SetBits<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> SOFT_SDA_PIN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u677e\u5f00SDA&#xff08;\u7ed9\u5bf9\u65b9\u56de\u5e94\u7a7a\u95f4&#xff09;<\/span><br \/>\n    <span class=\"token function\">GPIO_SetBits<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> SOFT_SCL_PIN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u62ac\u9ad8SCL&#xff08;\u51c6\u5907\u8046\u542c&#xff09;<\/span><br \/>\n    <span class=\"token function\">Delay_us<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u7b49\u5f85\u5fc3\u7075\u611f\u5e94<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u8bfb\u53d6SDA\u72b6\u6001&#xff1a;0&#061;\u4e24\u60c5\u76f8\u60a6&#xff0c;1&#061;\u4e00\u53a2\u60c5\u613f<\/span><br \/>\n    <span class=\"token class-name\">uint8_t<\/span> ack <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">GPIO_ReadInputDataBit<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> SOFT_SDA_PIN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">GPIO_ResetBits<\/span><span class=\"token punctuation\">(<\/span>SOFT_I2C_PORT<span class=\"token punctuation\">,<\/span> SOFT_SCL_PIN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u7ed3\u675f\u5fc3\u8df3\u68c0\u6d4b<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> ack<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u56db\u3001\u786c\u4ef6IIC&#xff1a;\u6807\u51c6\u5e93\u91cc\u7684\u201c\u5305\u529e\u5a5a\u59fb\u201d<\/h4>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&#034;stm32f10x.h&#034;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">MPU_ADDR<\/span> <span class=\"token expression\"><span class=\"token number\">0xD0<\/span> <\/span><span class=\"token comment\">\/\/ \u9640\u87ba\u4eea\u5de5\u724c\u53f7\u5de6\u79fb\u4e00\u4f4d\u540e\u7684\u5730\u5740<\/span><\/span><\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">I2C_Config<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    GPIO_InitTypeDef GPIO_InitStruct<span class=\"token punctuation\">;<\/span><br \/>\n    I2C_InitTypeDef I2C_InitStruct<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u5f00\u542f\u65f6\u949f\u5927\u4eba\u7684\u52a9\u653b<\/span><br \/>\n    <span class=\"token function\">RCC_APB2PeriphClockCmd<\/span><span class=\"token punctuation\">(<\/span>RCC_APB2Periph_GPIOB<span class=\"token punctuation\">,<\/span> ENABLE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">RCC_APB1PeriphClockCmd<\/span><span class=\"token punctuation\">(<\/span>RCC_APB1Periph_I2C1<span class=\"token punctuation\">,<\/span> ENABLE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u914d\u7f6eSDA\u548cSCL\u4e3a\u590d\u7528\u5f00\u6f0f\u6a21\u5f0f<\/span><br \/>\n    GPIO_InitStruct<span class=\"token punctuation\">.<\/span>GPIO_Pin <span class=\"token operator\">&#061;<\/span> GPIO_Pin_6 <span class=\"token operator\">|<\/span> GPIO_Pin_7<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ PB6:SCL, PB7:SDA<\/span><br \/>\n    GPIO_InitStruct<span class=\"token punctuation\">.<\/span>GPIO_Mode <span class=\"token operator\">&#061;<\/span> GPIO_Mode_AF_OD<span class=\"token punctuation\">;<\/span>        <span class=\"token comment\">\/\/ \u76f8\u4eb2\u4e13\u7528\u901a\u9053<\/span><br \/>\n    GPIO_InitStruct<span class=\"token punctuation\">.<\/span>GPIO_Speed <span class=\"token operator\">&#061;<\/span> GPIO_Speed_50MHz<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">GPIO_Init<\/span><span class=\"token punctuation\">(<\/span>GPIOB<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>GPIO_InitStruct<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u9738\u9053\u603b\u88c1\u7684\u76f8\u4eb2\u53c2\u6570\u8bbe\u7f6e<\/span><br \/>\n    I2C_InitStruct<span class=\"token punctuation\">.<\/span>I2C_Mode <span class=\"token operator\">&#061;<\/span> I2C_Mode_I2C<span class=\"token punctuation\">;<\/span><br \/>\n    I2C_InitStruct<span class=\"token punctuation\">.<\/span>I2C_DutyCycle <span class=\"token operator\">&#061;<\/span> I2C_DutyCycle_2<span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ \u5360\u7a7a\u6bd4\u8bbe\u5b9a<\/span><br \/>\n    I2C_InitStruct<span class=\"token punctuation\">.<\/span>I2C_OwnAddress1 <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0x00<\/span><span class=\"token punctuation\">;<\/span>               <span class=\"token comment\">\/\/ \u603b\u88c1\u81ea\u5df1\u4e0d\u9886\u5de5\u724c<\/span><br \/>\n    I2C_InitStruct<span class=\"token punctuation\">.<\/span>I2C_Ack <span class=\"token operator\">&#061;<\/span> I2C_Ack_Enable<span class=\"token punctuation\">;<\/span>            <span class=\"token comment\">\/\/ \u5f00\u542f\u7231\u7684\u5e94\u7b54<\/span><br \/>\n    I2C_InitStruct<span class=\"token punctuation\">.<\/span>I2C_ClockSpeed <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">100000<\/span><span class=\"token punctuation\">;<\/span>             <span class=\"token comment\">\/\/ \u6162\u901f\u76f8\u4eb2\u8282\u594f100kHz<\/span><br \/>\n    <span class=\"token function\">I2C_Init<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>I2C_InitStruct<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">I2C_Cmd<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> ENABLE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>                              <span class=\"token comment\">\/\/ \u603b\u88c1\u95ea\u4eae\u767b\u573a<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">MPU6050_Write<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">uint8_t<\/span> reg<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">uint8_t<\/span> data<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u53d1\u8d77\u76f8\u4eb2\u9080\u8bf7<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">I2C_GetFlagStatus<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_FLAG_BUSY<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ \u7b49\u5f85\u524d\u4efb\u76f8\u4eb2\u7ed3\u675f<\/span><br \/>\n    <span class=\"token function\">I2C_GenerateSTART<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> ENABLE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>                    <span class=\"token comment\">\/\/ \u603b\u88c1\u6253\u54cd\u6307<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">I2C_CheckEvent<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_EVENT_MASTER_MODE_SELECT<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u70b9\u540d\u9640\u87ba\u4eea<\/span><br \/>\n    <span class=\"token function\">I2C_Send7bitAddress<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> MPU_ADDR<span class=\"token punctuation\">,<\/span> I2C_Direction_Transmitter<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">I2C_CheckEvent<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u53d1\u9001\u60c5\u4e66\u5185\u5bb9<\/span><br \/>\n    <span class=\"token function\">I2C_SendData<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> reg<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>                            <span class=\"token comment\">\/\/ \u6307\u5b9a\u5bc4\u5b58\u5668\u5730\u5740<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">I2C_CheckEvent<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_EVENT_MASTER_BYTE_TRANSMITTING<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">I2C_SendData<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>                           <span class=\"token comment\">\/\/ \u5199\u5165\u6570\u636e<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">I2C_CheckEvent<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_EVENT_MASTER_BYTE_TRANSMITTED<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u4f18\u96c5\u9000\u573a<\/span><br \/>\n    <span class=\"token function\">I2C_GenerateSTOP<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> ENABLE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>                     <span class=\"token comment\">\/\/ \u7529\u62ab\u98ce\u79bb\u5f00<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token class-name\">int16_t<\/span> <span class=\"token function\">MPU6050_Read<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">uint8_t<\/span> reg<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">uint8_t<\/span> H<span class=\"token punctuation\">,<\/span> L<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u7b2c\u4e00\u9636\u6bb5&#xff1a;\u5199\u5bc4\u5b58\u5668\u5730\u5740<\/span><br \/>\n    <span class=\"token function\">I2C_GenerateSTART<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> ENABLE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">I2C_CheckEvent<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_EVENT_MASTER_MODE_SELECT<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token function\">I2C_Send7bitAddress<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> MPU_ADDR<span class=\"token punctuation\">,<\/span> I2C_Direction_Transmitter<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">I2C_CheckEvent<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token function\">I2C_SendData<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> reg<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">I2C_CheckEvent<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_EVENT_MASTER_BYTE_TRANSMITTED<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u7b2c\u4e8c\u9636\u6bb5&#xff1a;\u91cd\u65b0\u542f\u52a8\u8bfb\u53d6<\/span><br \/>\n    <span class=\"token function\">I2C_GenerateSTART<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> ENABLE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">I2C_CheckEvent<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_EVENT_MASTER_MODE_SELECT<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token function\">I2C_Send7bitAddress<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> MPU_ADDR<span class=\"token punctuation\">,<\/span> I2C_Direction_Receiver<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">I2C_CheckEvent<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u63a5\u6536\u6570\u636e&#xff08;\u4ee5\u52a0\u901f\u5ea6X\u8f74\u4e3a\u4f8b&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">I2C_CheckEvent<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_EVENT_MASTER_BYTE_RECEIVED<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    H <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">I2C_ReceiveData<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">I2C_CheckEvent<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> I2C_EVENT_MASTER_BYTE_RECEIVED<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    L <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">I2C_ReceiveData<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token function\">I2C_GenerateSTOP<\/span><span class=\"token punctuation\">(<\/span>I2C1<span class=\"token punctuation\">,<\/span> ENABLE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">int16_t<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">(<\/span>H <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token number\">8<\/span> <span class=\"token operator\">|<\/span> L<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u4ee3\u7801\u89e3\u5bc6&#xff1a;\u6807\u51c6\u5e93\u306e\u4eea\u5f0f\u611f<\/h4>\n<li>\n<p>\u786c\u4ef6\u914d\u7f6e\u5c31\u50cf\u5b9a\u505a\u897f\u88c5&#xff1a;GPIO\u5fc5\u987b\u8bbe\u7f6e\u6210\u590d\u7528\u5f00\u6f0f\u6a21\u5f0f&#xff0c;\u522b\u5fd8\u4e86\u6253\u5f00APB1\u548cAPB2\u65f6\u949f\u7684&#034;\u6c34\u6e90&#034;<\/p>\n<\/li>\n<li>\n<p>\u4e8b\u4ef6\u68c0\u67e5\u662f\u9632\u5446\u8bbe\u8ba1&#xff1a;\u6bcf\u4e2a\u52a8\u4f5c\u90fd\u8981\u7528I2C_CheckEvent\u786e\u8ba4&#xff0c;\u582a\u6bd4\u603b\u88c1\u7684\u8d34\u8eab\u79d8\u4e66\u53cd\u590d\u786e\u8ba4\u884c\u7a0b<\/p>\n<\/li>\n<li>\n<p>\u590d\u5408\u5f0f\u8bfb\u53d6\u73a9\u8f6c\u56de\u9a6c\u67aa&#xff1a;\u5148\u5199\u5bc4\u5b58\u5668\u5730\u5740\u518d\u91cd\u542f\u8bfb\u53d6&#xff0c;\u50cf\u6781\u4e86\u6b32\u64d2\u6545\u7eb5\u7684\u604b\u7231\u5957\u8def<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u62fc\u63a5\u8bb2\u7a76\u95e8\u5f53\u6237\u5bf9&#xff1a;\u9ad8\u4f4e\u5b57\u8282\u7ed3\u5408\u65f6\u8bb0\u5f97\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362&#xff0c;\u907f\u514d\u6570\u636e\u754c\u7684&#034;\u9636\u7ea7\u8de8\u8d8a&#034;<\/p>\n<\/li>\n<h4>\u6765\u81ea\u8001\u6d3e\u7ec5\u58eb\u7684\u5fe0\u544a<\/h4>\n<p>\u867d\u7136\u6807\u51c6\u5e93\u7684\u76f8\u4eb2\u6d41\u7a0b\u7a0d\u663e\u7e41\u7410&#xff08;\u6bd4\u8d77HAL\u5e93&#xff09;&#xff0c;\u4f46\u8fd9\u4efd\u5bc4\u5b58\u5668\u7ea7\u7684\u4eea\u5f0f\u611f\u6b63\u662f\u7535\u5b50\u7f57\u66fc\u53f2\u7684\u918d\u9190\u5473&#xff01;\u5f53\u4f60\u5728while\u5faa\u73af\u91cc\u7b49\u5f85\u4e8b\u4ef6\u6807\u5fd7\u65f6&#xff0c;\u8bf7\u628a\u8fd9\u5f53\u4f5c\u7231\u60c5\u957f\u8dd1\u524d\u7684\u5fc5\u8981\u8003\u9a8c\u2014\u2014\u6bd5\u7adf\u7f8e\u597d\u7684\u5a5a\u59fb&#xff08;\u901a\u4fe1&#xff09;\u503c\u5f97\u7b49\u5f85&#xff01;<\/p>\n<p>&#xff08;\u8c03\u8bd5\u65f6\u82e5\u9047I2C\u6b7b\u9501&#xff0c;\u8bf7\u4f7f\u51fa\u7edd\u62db&#xff1a;\u65ad\u7535\u5927\u6cd5\u597d&#xff01;&#xff09;<\/p>\n<h4>\u516d\u3001I\u00b2C\u8c03\u8bd5\u5fc3\u6cd5&#xff1a;\u793a\u6ce2\u5668\u91cc\u7684\u7231\u60c5\u5fc3\u7535\u56fe<\/h4>\n<li>\n<p>\u6ce2\u5f62\u8bca\u65ad\u4e09\u8981\u7d20&#xff1a;<\/p>\n<ul>\n<li>\u8d77\u59cb\u4fe1\u53f7&#xff1a;\u662f\u5426\u51fa\u73b0\u6807\u51c6\u7684&#034;\u4f4e\u5934-\u540c\u6b65&#034;\u5e8f\u5217<\/li>\n<li>\u65f6\u949f\u9891\u7387&#xff1a;\u662f\u5426\u8d85\u51fa\u8bbe\u5907\u627f\u53d7\u8303\u56f4&#xff08;\u5982\u540c\u604b\u7231\u8282\u594f\u592a\u5feb&#xff09;<\/li>\n<li>\u6570\u636e\u5bf9\u9f50&#xff1a;\u4e0a\u5347\u6cbf\u65f6\u6570\u636e\u662f\u5426\u7a33\u5b9a&#xff08;\u7231\u60c5\u627f\u8bfa\u8981\u575a\u5b9a&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5e38\u89c1\u5931\u604b\u539f\u56e0&#xff1a;<\/p>\n<ul>\n<li>\u5730\u5740\u9519\u4f4d&#xff1a;7\u4f4d\u5730\u5740\u672a\u5de6\u79fb&#xff08;\u4f8b\u59820x68\u5e94\u5199\u4f5c0xD0&#xff09;<\/li>\n<li>\u65f6\u5e8f\u8fc7\u6025&#xff1a;Delay\u4e0d\u8db3\u5bfc\u81f4\u8bbe\u5907\u65e0\u6cd5\u54cd\u5e94<\/li>\n<li>\u603b\u7ebf\u7ade\u4e89&#xff1a;\u591a\u4e2a\u4e3b\u8bbe\u5907\u540c\u65f6\u793a\u7231&#xff08;\u9700\u4ef2\u88c1\u673a\u5236&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u793a\u6ce2\u5668\u6d4b\u91cf\u6280\u5de7&#xff1a;<\/p>\n<p>    #mermaid-svg-X4TAzANSldObQJ7B {font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-X4TAzANSldObQJ7B .error-icon{fill:#552222;}#mermaid-svg-X4TAzANSldObQJ7B .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-X4TAzANSldObQJ7B .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-X4TAzANSldObQJ7B .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-X4TAzANSldObQJ7B .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-X4TAzANSldObQJ7B .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-X4TAzANSldObQJ7B .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-X4TAzANSldObQJ7B .marker{fill:#333333;stroke:#333333;}#mermaid-svg-X4TAzANSldObQJ7B .marker.cross{stroke:#333333;}#mermaid-svg-X4TAzANSldObQJ7B svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-X4TAzANSldObQJ7B .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-X4TAzANSldObQJ7B .cluster-label text{fill:#333;}#mermaid-svg-X4TAzANSldObQJ7B .cluster-label span{color:#333;}#mermaid-svg-X4TAzANSldObQJ7B .label text,#mermaid-svg-X4TAzANSldObQJ7B span{fill:#333;color:#333;}#mermaid-svg-X4TAzANSldObQJ7B .node rect,#mermaid-svg-X4TAzANSldObQJ7B .node circle,#mermaid-svg-X4TAzANSldObQJ7B .node ellipse,#mermaid-svg-X4TAzANSldObQJ7B .node polygon,#mermaid-svg-X4TAzANSldObQJ7B .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-X4TAzANSldObQJ7B .node .label{text-align:center;}#mermaid-svg-X4TAzANSldObQJ7B .node.clickable{cursor:pointer;}#mermaid-svg-X4TAzANSldObQJ7B .arrowheadPath{fill:#333333;}#mermaid-svg-X4TAzANSldObQJ7B .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-X4TAzANSldObQJ7B .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-X4TAzANSldObQJ7B .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-X4TAzANSldObQJ7B .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-X4TAzANSldObQJ7B .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-X4TAzANSldObQJ7B .cluster text{fill:#333;}#mermaid-svg-X4TAzANSldObQJ7B .cluster span{color:#333;}#mermaid-svg-X4TAzANSldObQJ7B div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-X4TAzANSldObQJ7B :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;} <\/p>\n<p>           <span id=\"L-L-A-B\" class=\"edgeLabel L-LS-A&#039; L-LE-B\"><\/span> <\/p>\n<p>           <span id=\"L-L-B-C\" class=\"edgeLabel L-LS-B&#039; L-LE-C\"><\/span> <\/p>\n<p>           <span id=\"L-L-C-D\" class=\"edgeLabel L-LS-C&#039; L-LE-D\"><\/span> <\/p>\n<p>             \u89e6\u53d1\u6a21\u5f0f\u8bbe\u7f6e\u4e3a\u4e0b\u964d\u6cbf <\/p>\n<p>             \u6355\u6349\u8d77\u59cb\u4fe1\u53f7 <\/p>\n<p>             \u5c55\u5f00\u65f6\u5e8f\u67e5\u770b\u5730\u5740\u4f4d <\/p>\n<p>             \u68c0\u67e5ACK\u8109\u51b2\u4f4d\u7f6e <\/p>\n<\/li>\n<p>\u786c\u4ef6I\u00b2C\u5982\u4ea4\u54cd\u4e50\u56e2\u6307\u6325&#xff0c;\u7cbe\u51c6\u628a\u63a7\u6bcf\u4e2a\u8282\u62cd&#xff1b;\u8f6f\u4ef6I\u00b2C\u5982\u6c11\u8c23\u6b4c\u624b&#xff0c;\u81ea\u7531\u8be0\u91ca\u97f3\u4e50\u7075\u9b42\u3002\u7406\u89e3\u534f\u8bae\u672c\u8d28\u540e&#xff0c;\u65e0\u8bba\u662fSTM32\u7684I2C\u5916\u8bbe\u8fd8\u662fGPIO\u6a21\u62df&#xff0c;\u90fd\u80fd\u8ba9\u8bbe\u5907\u95f4\u8c08\u4e00\u573a\u5b8c\u7f8e\u7684&#034;\u7535\u5b50\u604b\u7231&#034;&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb594\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u5927\u5bb6\u597d\uff0c\u6211\u662f\u4f60\u4eec\u7684\u8d5b\u535a\u7ea2\u5a18SDA\uff0c\u65c1\u8fb9\u8fd9\u4f4d\u6251\u514b\u8138\u65f6\u949f\u5148\u751f\u53ebSCL\u3002\u4eca\u5929\u6211\u4eec\u8fd9\u5bf9\u9ec4\u91d1CP\u8981\u7ed9\u5927\u5bb6\u8868\u6f14&quot;\u4e24\u6839\u7ebf\u641e\u5b9a\u5168\u5c4b\u667a\u80fd&quot;\u7684\u7edd\u6d3b\u2014\u2014\u6ca1\u9519\uff0c\u8fd9\u5c31\u662f\u7535\u5b50\u754c\u8457\u540d\u7684\u5305\u529e\u5a5a\u59fb\u534f\u8bae\uff1aI\u00b2C\u901a\u4fe1\uff01\uff08\u81ea\u5e26BGM\uff1a\u5654 \u5654\u5654~ \u5654\u5654~\uff09<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[174,217,270,2655],"topic":[],"class_list":["post-32650","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-stm32","tag-270","tag-2655"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>STM32\u7248I\u00b2C\u76f8\u4eb2\u6307\u5357\uff08\u8f6f\u4ef6\u786c\u4ef6\u53cc\u4fee\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/32650.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"STM32\u7248I\u00b2C\u76f8\u4eb2\u6307\u5357\uff08\u8f6f\u4ef6\u786c\u4ef6\u53cc\u4fee\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb594\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u5927\u5bb6\u597d\uff0c\u6211\u662f\u4f60\u4eec\u7684\u8d5b\u535a\u7ea2\u5a18SDA\uff0c\u65c1\u8fb9\u8fd9\u4f4d\u6251\u514b\u8138\u65f6\u949f\u5148\u751f\u53ebSCL\u3002\u4eca\u5929\u6211\u4eec\u8fd9\u5bf9\u9ec4\u91d1CP\u8981\u7ed9\u5927\u5bb6\u8868\u6f14&quot;\u4e24\u6839\u7ebf\u641e\u5b9a\u5168\u5c4b\u667a\u80fd&quot;\u7684\u7edd\u6d3b\u2014\u2014\u6ca1\u9519\uff0c\u8fd9\u5c31\u662f\u7535\u5b50\u754c\u8457\u540d\u7684\u5305\u529e\u5a5a\u59fb\u534f\u8bae\uff1aI\u00b2C\u901a\u4fe1\uff01\uff08\u81ea\u5e26BGM\uff1a\u5654 \u5654\u5654~ \u5654\u5654~\uff09\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/32650.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-24T12:18:30+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/32650.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/32650.html\",\"name\":\"STM32\u7248I\u00b2C\u76f8\u4eb2\u6307\u5357\uff08\u8f6f\u4ef6\u786c\u4ef6\u53cc\u4fee\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-24T12:18:30+00:00\",\"dateModified\":\"2025-04-24T12:18:30+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/32650.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/32650.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/32650.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"STM32\u7248I\u00b2C\u76f8\u4eb2\u6307\u5357\uff08\u8f6f\u4ef6\u786c\u4ef6\u53cc\u4fee\u7248\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"STM32\u7248I\u00b2C\u76f8\u4eb2\u6307\u5357\uff08\u8f6f\u4ef6\u786c\u4ef6\u53cc\u4fee\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/32650.html","og_locale":"zh_CN","og_type":"article","og_title":"STM32\u7248I\u00b2C\u76f8\u4eb2\u6307\u5357\uff08\u8f6f\u4ef6\u786c\u4ef6\u53cc\u4fee\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb594\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u5927\u5bb6\u597d\uff0c\u6211\u662f\u4f60\u4eec\u7684\u8d5b\u535a\u7ea2\u5a18SDA\uff0c\u65c1\u8fb9\u8fd9\u4f4d\u6251\u514b\u8138\u65f6\u949f\u5148\u751f\u53ebSCL\u3002\u4eca\u5929\u6211\u4eec\u8fd9\u5bf9\u9ec4\u91d1CP\u8981\u7ed9\u5927\u5bb6\u8868\u6f14&quot;\u4e24\u6839\u7ebf\u641e\u5b9a\u5168\u5c4b\u667a\u80fd&quot;\u7684\u7edd\u6d3b\u2014\u2014\u6ca1\u9519\uff0c\u8fd9\u5c31\u662f\u7535\u5b50\u754c\u8457\u540d\u7684\u5305\u529e\u5a5a\u59fb\u534f\u8bae\uff1aI\u00b2C\u901a\u4fe1\uff01\uff08\u81ea\u5e26BGM\uff1a\u5654 \u5654\u5654~ \u5654\u5654~\uff09","og_url":"https:\/\/www.wsisp.com\/helps\/32650.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-24T12:18:30+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/32650.html","url":"https:\/\/www.wsisp.com\/helps\/32650.html","name":"STM32\u7248I\u00b2C\u76f8\u4eb2\u6307\u5357\uff08\u8f6f\u4ef6\u786c\u4ef6\u53cc\u4fee\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-24T12:18:30+00:00","dateModified":"2025-04-24T12:18:30+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/32650.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/32650.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/32650.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"STM32\u7248I\u00b2C\u76f8\u4eb2\u6307\u5357\uff08\u8f6f\u4ef6\u786c\u4ef6\u53cc\u4fee\u7248\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/32650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=32650"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/32650\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=32650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=32650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=32650"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=32650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}