{"id":69134,"date":"2026-01-31T05:57:50","date_gmt":"2026-01-30T21:57:50","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/69134.html"},"modified":"2026-01-31T05:57:50","modified_gmt":"2026-01-30T21:57:50","slug":"stm32%e7%ac%94%e8%ae%b0%e5%bd%92%e7%ba%b34%ef%bc%9ai2c","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/69134.html","title":{"rendered":"STM32\u7b14\u8bb0\u5f52\u7eb34\uff1aI2C"},"content":{"rendered":"<h2 id=\"I2C\">I2C<\/h2>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"I2C-toc\" style=\"margin-left:0px\">I2C<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E5%9F%BA%E6%9C%AC%E7%94%B5%E8%B7%AF%E7%BB%93%E6%9E%84-toc\" style=\"margin-left:40px\">\u4e00\u3001\u57fa\u672c\u7535\u8def\u7ed3\u6784<\/p>\n<p id=\"1.1.%E4%B8%B2%E5%8F%A3%E7%9A%84%E7%BC%BA%E7%82%B9-toc\" style=\"margin-left:80px\">1.1.\u4e32\u53e3\u7684\u7f3a\u70b9<\/p>\n<p id=\"1.2.I2C%E6%80%BB%E7%BA%BF%E7%9A%84%E7%94%B5%E8%B7%AF%E7%BB%93%E6%9E%84-toc\" style=\"margin-left:80px\">1.2.I2C\u603b\u7ebf\u7684\u7535\u8def\u7ed3\u6784<\/p>\n<p id=\"1.3.%E6%95%B0%E6%8D%AE%E7%BA%BF%E5%92%8C%E6%97%B6%E9%92%9F%E7%BA%BF-toc\" style=\"margin-left:80px\">1.3.\u6570\u636e\u7ebf\u548c\u65f6\u949f\u7ebf<\/p>\n<p id=\"1.4.%E9%80%BB%E8%BE%91%E7%BA%BF%E4%B8%8E-toc\" style=\"margin-left:80px\">1.4.\u903b\u8f91\u7ebf\u4e0e<\/p>\n<p id=\"1.4.1.%E9%80%BB%E8%BE%91%E4%B8%8E-toc\" style=\"margin-left:120px\">1.4.1.\u903b\u8f91\u4e0e<\/p>\n<p id=\"1.4.2.%E9%80%BB%E8%BE%91%E7%BA%BF%E4%B8%8E-toc\" style=\"margin-left:120px\">1.4.2.\u903b\u8f91\u7ebf\u4e0e<\/p>\n<p id=\"1.5.%E4%B8%BB%E6%9C%BA%E5%A6%82%E4%BD%95%E5%8F%91%E9%80%81%E6%97%B6%E9%92%9F%E4%BF%A1%E5%8F%B7-toc\" style=\"margin-left:80px\">1.5.\u4e3b\u673a\u5982\u4f55\u53d1\u9001\u65f6\u949f\u4fe1\u53f7<\/p>\n<p id=\"1.6.%E4%B8%BB%E6%9C%BA%E5%A6%82%E4%BD%95%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE-toc\" style=\"margin-left:80px\">1.6.\u4e3b\u673a\u5982\u4f55\u53d1\u9001\u6570\u636e<\/p>\n<p id=\"1.7.%E4%BB%8E%E6%9C%BA%E5%A6%82%E4%BD%95%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE-toc\" style=\"margin-left:80px\">1.7.\u4ece\u673a\u5982\u4f55\u53d1\u9001\u6570\u636e<\/p>\n<p id=\"1.8.%E4%B8%BA%E4%BD%95%E4%B8%8A%E6%8B%89%EF%BC%9F%E4%B8%BA%E4%BD%95%E5%BC%80%E6%BC%8F%EF%BC%9F-toc\" style=\"margin-left:80px\">1.8.\u4e3a\u4f55\u4e0a\u62c9&#xff1f;\u4e3a\u4f55\u5f00\u6f0f&#xff1f;<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-toc\" style=\"margin-left:40px\">\u4e8c\u3001\u901a\u4fe1\u534f\u8bae<\/p>\n<p id=\"2.1.I2C%E9%80%9A%E4%BF%A1%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%B5%81%E7%A8%8B-toc\" style=\"margin-left:80px\">2.1.I2C\u901a\u4fe1\u7684\u57fa\u672c\u6d41\u7a0b<\/p>\n<p id=\"%E2%80%8B%E7%BC%96%E8%BE%91-toc\" style=\"margin-left:80px\">\u200b\u7f16\u8f91<\/p>\n<p id=\"2.2.I2C%E7%9A%84%E6%95%B0%E6%8D%AE%E5%B8%A7%E6%A0%BC%E5%BC%8F-toc\" style=\"margin-left:80px\">2.2.I2C\u7684\u6570\u636e\u5e27\u683c\u5f0f<\/p>\n<p id=\"2.3.%E8%B5%B7%E5%A7%8B%E4%BD%8D%E5%92%8C%E5%81%9C%E6%AD%A2%E4%BD%8D-toc\" style=\"margin-left:80px\">2.3.\u8d77\u59cb\u4f4d\u548c\u505c\u6b62\u4f4d<\/p>\n<p id=\"2.3.1.%E8%B5%B7%E5%A7%8B%E4%BD%8D-toc\" style=\"margin-left:120px\">2.3.1.\u8d77\u59cb\u4f4d<\/p>\n<p id=\"2.3.2.%E5%81%9C%E6%AD%A2%E4%BD%8D-toc\" style=\"margin-left:120px\">2.3.2.\u505c\u6b62\u4f4d<\/p>\n<p id=\"2.4.%E5%AF%BB%E5%9D%80-toc\" style=\"margin-left:80px\">2.4.\u5bfb\u5740<\/p>\n<p id=\"2.5.%E4%BC%A0%E8%BE%93%E6%95%B0%E6%8D%AE-toc\" style=\"margin-left:80px\">2.5.\u4f20\u8f93\u6570\u636e<\/p>\n<p id=\"2.6.%E4%BE%8B%E5%AD%90-toc\" style=\"margin-left:80px\">2.6.\u4f8b\u5b50<\/p>\n<p id=\"2.6.1.%E5%90%91%E4%BB%8E%E6%9C%BA0x78%E5%86%99%E4%B8%A4%E4%B8%AA%E5%AD%97%E8%8A%82%EF%BC%880x5a%EF%BC%8C0x33%EF%BC%89-toc\" style=\"margin-left:120px\">2.6.1.\u5411\u4ece\u673a0x78\u5199\u4e24\u4e2a\u5b57\u8282&#xff08;0x5a&#xff0c;0x33&#xff09;<\/p>\n<p id=\"2.6.2.%E4%BB%8E%E4%BB%8E%E6%9C%BA0x20%E8%AF%BB%E4%B8%80%E4%B8%AA%E5%AD%97%E8%8A%82%EF%BC%88%E5%81%87%E8%AE%BE%E8%AF%BB%E5%88%B0%E7%9A%84%E6%98%AF0x64%EF%BC%89-toc\" style=\"margin-left:120px\">2.6.2.\u4ece\u4ece\u673a0x20\u8bfb\u4e00\u4e2a\u5b57\u8282&#xff08;\u5047\u8bbe\u8bfb\u5230\u7684\u662f0x64&#xff09;<\/p>\n<p id=\"%E4%B8%89%E3%80%81I2C%E6%A8%A1%E5%9D%97%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95-toc\" style=\"margin-left:40px\">\u4e09\u3001I2C\u6a21\u5757\u7684\u4f7f\u7528\u65b9\u6cd5<\/p>\n<p id=\"3.1.I2C%E6%A8%A1%E5%9D%97%E7%AE%80%E4%BB%8B-toc\" style=\"margin-left:80px\">3.1.I2C\u6a21\u5757\u7b80\u4ecb<\/p>\n<p id=\"3.2.IO%E5%BC%95%E8%84%9A%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8C%96-toc\" style=\"margin-left:80px\">3.2.IO\u5f15\u811a\u7684\u521d\u59cb\u5316<\/p>\n<p id=\"3.2.1.%E5%BC%95%E8%84%9A%E5%88%86%E5%B8%83-toc\" style=\"margin-left:120px\">3.2.1.\u5f15\u811a\u5206\u5e03<\/p>\n<p id=\"3.2.2.%E7%BC%96%E7%A0%81%E9%83%A8%E5%88%86-toc\" style=\"margin-left:120px\">3.2.2.\u7f16\u7801\u90e8\u5206<\/p>\n<p id=\"3.3.%E8%BF%9E%E6%8E%A5%E7%94%B5%E8%B7%AF-toc\" style=\"margin-left:80px\">3.3.\u8fde\u63a5\u7535\u8def<\/p>\n<p id=\"%C2%A03.4.I2C%E7%9A%84%E9%80%9F%E5%BA%A6%E6%A8%A1%E5%BC%8F-toc\" style=\"margin-left:80px\">\u00a03.4.I2C\u7684\u901f\u5ea6\u6a21\u5f0f<\/p>\n<p id=\"3.5.%E6%97%B6%E9%92%9F%E4%BF%A1%E5%8F%B7%E7%9A%84%E5%8D%A0%E7%A9%BA%E6%AF%94-toc\" style=\"margin-left:80px\">3.5.\u65f6\u949f\u4fe1\u53f7\u7684\u5360\u7a7a\u6bd4<\/p>\n<p id=\"3.6.I2C%E6%A8%A1%E5%9D%97%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8C%96-toc\" style=\"margin-left:80px\">3.6.I2C\u6a21\u5757\u7684\u521d\u59cb\u5316<\/p>\n<p id=\"3.6.1.%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A3-toc\" style=\"margin-left:120px\">3.6.1.\u7f16\u7a0b\u63a5\u53e3<\/p>\n<p id=\"3.6.2.%E7%BC%96%E7%A0%81%E9%83%A8%E5%88%86-toc\" style=\"margin-left:120px\">3.6.2.\u7f16\u7801\u90e8\u5206<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%E5%86%99%E6%95%B0%E6%8D%AE-toc\" style=\"margin-left:40px\">\u56db\u3001\u5199\u6570\u636e<\/p>\n<p id=\"4.1.I2C%E6%A8%A1%E5%9D%97%E7%9A%84%E5%86%85%E9%83%A8%E7%BB%93%E6%9E%84%E6%A1%86%E5%9B%BE-toc\" style=\"margin-left:80px\">4.1.I2C\u6a21\u5757\u7684\u5185\u90e8\u7ed3\u6784\u6846\u56fe<\/p>\n<p id=\"4.2.%E6%95%B0%E6%8D%AE%E5%8F%91%E9%80%81%E8%BF%87%E7%A8%8B%E7%AE%80%E4%BB%8B-toc\" style=\"margin-left:80px\">4.2.\u6570\u636e\u53d1\u9001\u8fc7\u7a0b\u7b80\u4ecb<\/p>\n<p id=\"4.2.1.%E5%8F%91%E9%80%81%E5%AD%97%E8%8A%82%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:120px\">4.2.1.\u53d1\u9001\u5b57\u8282\u51fd\u6570<\/p>\n<p id=\"4.3.%E7%AD%89%E5%BE%85%E6%80%BB%E7%BA%BF%E7%A9%BA%E9%97%B2-toc\" style=\"margin-left:80px\">4.3.\u7b49\u5f85\u603b\u7ebf\u7a7a\u95f2<\/p>\n<p id=\"4.4.%E5%8F%91%E9%80%81%E8%B5%B7%E5%A7%8B%E4%BD%8D-toc\" style=\"margin-left:80px\">4.4.\u53d1\u9001\u8d77\u59cb\u4f4d<\/p>\n<p id=\"4.5.%E5%8F%91%E9%80%81%E5%9C%B0%E5%9D%80-toc\" style=\"margin-left:80px\">4.5.\u53d1\u9001\u5730\u5740<\/p>\n<p id=\"4.6.%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE-toc\" style=\"margin-left:80px\">4.6.\u53d1\u9001\u6570\u636e<\/p>\n<p id=\"4.7.%E5%8F%91%E9%80%81%E5%81%9C%E6%AD%A2%E4%BD%8D-toc\" style=\"margin-left:80px\">4.7.\u53d1\u9001\u505c\u6b62\u4f4d<\/p>\n<p id=\"4.8.%E5%90%AF%E5%8A%A8OLED-toc\" style=\"margin-left:80px\">4.8.\u542f\u52a8OLED<\/p>\n<p id=\"4.9.%E6%80%BB%E4%BB%A3%E7%A0%81-toc\" style=\"margin-left:80px\">4.9.\u603b\u4ee3\u7801<\/p>\n<p id=\"%E4%BA%94%E3%80%81%E8%AF%BB%E6%95%B0%E6%8D%AE-toc\" style=\"margin-left:40px\">\u4e94\u3001\u8bfb\u6570\u636e<\/p>\n<p id=\"5.1.%E6%8E%A5%E6%94%B6%E5%AD%97%E8%8A%82%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:80px\">5.1.\u63a5\u6536\u5b57\u8282\u51fd\u6570<\/p>\n<p id=\"5.2.%E6%95%B0%E6%8D%AE%E8%AF%BB%E5%8F%96%E7%9A%84%E6%B5%81%E7%A8%8B-toc\" style=\"margin-left:80px\">5.2.\u6570\u636e\u8bfb\u53d6\u7684\u6d41\u7a0b<\/p>\n<p id=\"5.3.%E5%8F%91%E9%80%81%E8%B5%B7%E5%A7%8B%E4%BD%8D%E5%92%8C%E5%9C%B0%E5%9D%80-toc\" style=\"margin-left:80px\">5.3.\u53d1\u9001\u8d77\u59cb\u4f4d\u548c\u5730\u5740<\/p>\n<p id=\"5.3.1.%E5%8F%91%E9%80%81%E8%B5%B7%E5%A7%8B%E4%BD%8D-toc\" style=\"margin-left:120px\">5.3.1.\u53d1\u9001\u8d77\u59cb\u4f4d<\/p>\n<p id=\"5.3.2.%E5%8F%91%E9%80%81%E5%9C%B0%E5%9D%80%2B%E8%AF%BB%E5%86%99%E4%BD%8D-toc\" style=\"margin-left:120px\">5.3.2.\u53d1\u9001\u5730\u5740&#043;\u8bfb\u5199\u4f4d<\/p>\n<p id=\"5.4.%E5%A6%82%E4%BD%95%E5%8F%91%E9%80%81ACK%E5%92%8CNAK-toc\" style=\"margin-left:80px\">5.4.\u5982\u4f55\u53d1\u9001ACK\u548cNAK<\/p>\n<p id=\"5.5.%E5%A6%82%E4%BD%95%E5%8F%91%E9%80%81%E5%81%9C%E6%AD%A2%E4%BD%8D-toc\" style=\"margin-left:80px\">5.5.\u5982\u4f55\u53d1\u9001\u505c\u6b62\u4f4d<\/p>\n<p id=\"5.6.Size%20%3D%201-toc\" style=\"margin-left:80px\">5.6.Size &#061; 1<\/p>\n<p id=\"5.7.Size%20%3D%202-toc\" style=\"margin-left:80px\">5.7.Size &#061; 2<\/p>\n<p id=\"5.8.Size%20%3E%202-toc\" style=\"margin-left:80px\">5.8.Size &gt; 2<\/p>\n<p id=\"5.9.%E8%AF%BB%E5%8F%96OLED-toc\" style=\"margin-left:80px\">5.9.\u8bfb\u53d6OLED<\/p>\n<p id=\"%E5%85%AD%E3%80%81%E8%BD%AFI2C-toc\" style=\"margin-left:40px\">\u516d\u3001\u8f6fI2C<\/p>\n<p id=\"6.1.%E7%A1%ACI2C%20VS%20%E8%BD%AFI2C-toc\" style=\"margin-left:80px\">6.1.\u786cI2C VS \u8f6fI2C<\/p>\n<p id=\"6.2.IO%E5%BC%95%E8%84%9A%E5%88%9D%E5%A7%8B%E5%8C%96-toc\" style=\"margin-left:80px\">6.2.IO\u5f15\u811a\u521d\u59cb\u5316<\/p>\n<p id=\"6.3.IO%E8%AF%BB%E5%86%99%E5%92%8C%E5%BB%B6%E8%BF%9F%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:80px\">6.3.IO\u8bfb\u5199\u548c\u5ef6\u8fdf\u51fd\u6570<\/p>\n<p id=\"6.3.1.%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A31-toc\" style=\"margin-left:120px\">6.3.1.\u7f16\u7a0b\u63a5\u53e31<\/p>\n<p id=\"6.3.2.%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A32-toc\" style=\"margin-left:120px\">6.3.2.\u7f16\u7a0b\u63a5\u53e32<\/p>\n<p id=\"6.3.3.%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A33-toc\" style=\"margin-left:120px\">6.3.3.\u7f16\u7a0b\u63a5\u53e33<\/p>\n<p id=\"6.3.4.%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A34-toc\" style=\"margin-left:120px\">6.3.4.\u7f16\u7a0b\u63a5\u53e34<\/p>\n<p id=\"6.4.%E5%8F%91%E9%80%81%E8%B5%B7%E5%A7%8B%E4%BD%8D%E5%92%8C%E5%81%9C%E6%AD%A2%E4%BD%8D-toc\" style=\"margin-left:80px\">6.4.\u53d1\u9001\u8d77\u59cb\u4f4d\u548c\u505c\u6b62\u4f4d<\/p>\n<p id=\"6.5.%E5%8F%91%E9%80%81%E4%B8%80%E4%B8%AA%E5%AD%97%E8%8A%82-toc\" style=\"margin-left:80px\">6.5.\u53d1\u9001\u4e00\u4e2a\u5b57\u8282<\/p>\n<p id=\"6.6.%E6%8E%A5%E6%94%B6%E4%B8%80%E4%B8%AA%E5%AD%97%E8%8A%82-toc\" style=\"margin-left:80px\">6.6.\u63a5\u6536\u4e00\u4e2a\u5b57\u8282<\/p>\n<p id=\"6.7.%E7%BB%BC%E5%90%88-toc\" style=\"margin-left:80px\">6.7.\u7efc\u5408<\/p>\n<p id=\"6.8.%E6%B5%8B%E8%AF%95-toc\" style=\"margin-left:80px\">6.8.\u6d4b\u8bd5<\/p>\n<p id=\"%E4%B8%83%E3%80%81%E5%B0%81%E8%A3%85%E5%B8%B8%E7%94%A8%E5%8A%9F%E8%83%BD-toc\" style=\"margin-left:40px\">\u4e03\u3001\u5c01\u88c5\u5e38\u7528\u529f\u80fd<\/p>\n<p id=\"7.1.%E6%B5%8B%E8%AF%95%E7%A1%AC%E4%BB%B6I2C-toc\" style=\"margin-left:80px\">7.1.\u6d4b\u8bd5\u786c\u4ef6I2C<\/p>\n<p id=\"7.1.1.%E5%88%9D%E5%A7%8B%E5%8C%96%E7%A1%AC%E4%BB%B6I2C%E4%BB%A3%E7%A0%81-toc\" style=\"margin-left:120px\">7.1.1.\u521d\u59cb\u5316\u786c\u4ef6I2C\u4ee3\u7801<\/p>\n<p id=\"7.1.2.%E7%A1%AC%E4%BB%B6I2C%E6%94%B6%E5%8F%91%E6%95%B0%E6%8D%AE%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:120px\">7.1.2.\u786c\u4ef6I2C\u6536\u53d1\u6570\u636e\u51fd\u6570<\/p>\n<p id=\"7.1.3.%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE-toc\" style=\"margin-left:120px\">7.1.3.\u53d1\u9001\u6570\u636e<\/p>\n<p id=\"7.1.4.%E6%8E%A5%E6%94%B6%E6%95%B0%E6%8D%AE-toc\" style=\"margin-left:120px\">7.1.4.\u63a5\u6536\u6570\u636e<\/p>\n<p id=\"7.2.%E6%B5%8B%E8%AF%95%E8%BD%AF%E4%BB%B6I2C-toc\" style=\"margin-left:80px\">7.2.\u6d4b\u8bd5\u8f6f\u4ef6I2C<\/p>\n<p id=\"7.2.1.%E8%BD%AF%E4%BB%B6I2C%E6%94%B6%E5%8F%91%E6%95%B0%E6%8D%AE%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:120px\">7.2.1.\u8f6f\u4ef6I2C\u6536\u53d1\u6570\u636e\u51fd\u6570<\/p>\n<p id=\"7.2.2.%E6%94%B6%E5%8F%91%E6%95%B0%E6%8D%AE%E4%BB%A3%E7%A0%81-toc\" style=\"margin-left:120px\">7.2.2.\u6536\u53d1\u6570\u636e\u4ee3\u7801<\/p>\n<p id=\"%E5%85%AB%E3%80%81OLED%E6%98%BE%E7%A4%BA%E5%99%A8-toc\" style=\"margin-left:40px\">\u516b\u3001OLED\u663e\u793a\u5668<\/p>\n<p id=\"8.1.OLED%E6%98%BE%E7%A4%BA%E5%99%A8%E7%9A%84%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86-toc\" style=\"margin-left:80px\">8.1.OLED\u663e\u793a\u5668\u7684\u57fa\u672c\u539f\u7406<\/p>\n<p id=\"8.2.%E5%B1%8F%E5%B9%95%E5%88%9D%E5%A7%8B%E5%8C%96-toc\" style=\"margin-left:80px\">8.2.\u5c4f\u5e55\u521d\u59cb\u5316<\/p>\n<p id=\"8.2.1.%E5%88%9D%E5%A7%8B%E5%8C%96%E8%BD%AFI2C-toc\" style=\"margin-left:120px\">8.2.1.\u521d\u59cb\u5316\u8f6fI2C<\/p>\n<p id=\"8.2.2.%E5%B1%8F%E5%B9%95%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BB%A3%E7%A0%81%E7%9A%84%E7%BC%96%E5%86%99-toc\" style=\"margin-left:120px\">8.2.2.\u5c4f\u5e55\u521d\u59cb\u5316\u4ee3\u7801\u7684\u7f16\u5199<\/p>\n<p id=\"8.3.%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5%E5%92%8C%E6%93%8D%E4%BD%9C-toc\" style=\"margin-left:80px\">8.3.\u57fa\u672c\u6982\u5ff5\u548c\u64cd\u4f5c<\/p>\n<p id=\"8.3.1.%E7%94%BB%E7%AC%94%E5%92%8C%E7%94%BB%E5%88%B7-toc\" style=\"margin-left:120px\">8.3.1.\u753b\u7b14\u548c\u753b\u5237<\/p>\n<p id=\"8.3.2.%E5%B1%8F%E5%B9%95%E5%9D%90%E6%A0%87%E7%B3%BB-toc\" style=\"margin-left:120px\">8.3.2.\u5c4f\u5e55\u5750\u6807\u7cfb<\/p>\n<p id=\"8.3.3.%E5%85%89%E6%A0%87-toc\" style=\"margin-left:120px\">8.3.3.\u5149\u6807<\/p>\n<p id=\"8.4.%E6%96%87%E5%AD%97%E7%9B%B8%E5%85%B3%E7%9A%84%E6%93%8D%E4%BD%9C-toc\" style=\"margin-left:80px\">8.4.\u6587\u5b57\u76f8\u5173\u7684\u64cd\u4f5c<\/p>\n<p id=\"8.4.1.%E6%89%93%E5%8D%B0%E5%AD%97%E7%AC%A6%E4%B8%B2-toc\" style=\"margin-left:120px\">8.4.1.\u6253\u5370\u5b57\u7b26\u4e32<\/p>\n<p id=\"8.4.2.%E8%AE%BE%E7%BD%AE%E5%AD%97%E4%BD%93-toc\" style=\"margin-left:120px\">8.4.2.\u8bbe\u7f6e\u5b57\u4f53<\/p>\n<p id=\"8.4.3.%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%89%93%E5%8D%B0%E5%AD%97%E7%AC%A6%E4%B8%B2-toc\" style=\"margin-left:120px\">8.4.3.\u683c\u5f0f\u5316\u6253\u5370\u5b57\u7b26\u4e32<\/p>\n<p id=\"8.4.4.%E8%AE%BE%E7%BD%AE%E6%96%87%E6%9C%AC%E5%8C%BA%E5%9F%9F-toc\" style=\"margin-left:120px\">8.4.4.\u8bbe\u7f6e\u6587\u672c\u533a\u57df<\/p>\n<p id=\"8.5.%E7%BB%98%E5%9B%BE%E7%9B%B8%E5%85%B3%E7%9A%84%E6%93%8D%E4%BD%9C-toc\" style=\"margin-left:80px\">8.5.\u7ed8\u56fe\u76f8\u5173\u7684\u64cd\u4f5c<\/p>\n<p id=\"8.5.1.%E7%94%BB%E7%82%B9-toc\" style=\"margin-left:120px\">8.5.1.\u753b\u70b9<\/p>\n<p id=\"8.5.2.%E7%94%BB%E7%BA%BF-toc\" style=\"margin-left:120px\">8.5.2.\u753b\u7ebf<\/p>\n<p id=\"8.5.3.%E7%94%BB%E7%9F%A9%E5%BD%A2%E5%92%8C%E7%94%BB%E5%9C%86-toc\" style=\"margin-left:120px\">8.5.3.\u753b\u77e9\u5f62\u548c\u753b\u5706<\/p>\n<p id=\"8.5.4.%E7%BB%98%E5%88%B6%E4%BD%8D%E5%9B%BE-toc\" style=\"margin-left:120px\">8.5.4.\u7ed8\u5236\u4f4d\u56fe<\/p>\n<hr id=\"hr-toc\" \/>\n<h3 id=\"%E4%B8%80%E3%80%81%E5%9F%BA%E6%9C%AC%E7%94%B5%E8%B7%AF%E7%BB%93%E6%9E%84\">\u4e00\u3001\u57fa\u672c\u7535\u8def\u7ed3\u6784<\/h3>\n<h4 id=\"1.1.%E4%B8%B2%E5%8F%A3%E7%9A%84%E7%BC%BA%E7%82%B9\">1.1.\u4e32\u53e3\u7684\u7f3a\u70b9<\/h4>\n<p>\u4e00\u4e2a\u4e32\u53e3\u53ea\u80fd\u8fde\u63a5\u4e00\u4e2a\u4e32\u53e3\u8bbe\u5907<\/p>\n<p>\u53ea\u80fd\u5b9e\u73b0\u4e00\u5bf9\u4e00\u7684\u901a\u4fe1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"206\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215747-697d295b1bfb6.png\" width=\"225\" \/><\/p>\n<p>\u800cIIC\u901a\u8fc7\u4e00\u4e2a\u901a\u4fe1\u63a5\u53e3\u5c31\u53ef\u4ee5\u8fde\u63a5\u5f88\u591a\u5916\u8bbe<\/p>\n<h4 id=\"1.2.I2C%E6%80%BB%E7%BA%BF%E7%9A%84%E7%94%B5%E8%B7%AF%E7%BB%93%E6%9E%84\">1.2.I2C\u603b\u7ebf\u7684\u7535\u8def\u7ed3\u6784<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"234\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215747-697d295b47928.png\" width=\"346\" \/><\/p>\n<p>\u7531\u65f6\u949f\u7ebf\u548c\u6570\u636e\u7ebf\u7ec4\u6210&#xff0c;\u4e00\u822c\u7531\u5355\u7247\u673a\u4f5c\u4e3aIIC\u603b\u7ebf\u4e3b\u673a<\/p>\n<p>\u5176\u4ed6\u88ab\u8fde\u63a5\u8bbe\u5907\u4e3a\u4ece\u673a&#xff0c;\u8fd9\u4e9b\u8bbe\u5907\u90fd\u6709SDA\u548cSCL\u5f15\u811a<\/p>\n<p>\u6240\u6709\u8bbe\u5907\u7684SDA\u5f15\u811a\u8fde\u63a5\u5728\u6570\u636e\u7ebf\u4e0a<\/p>\n<p>\u6240\u6709\u8bbe\u5907\u7684SCL\u5f15\u811a\u8fde\u63a5\u5728\u65f6\u949f\u7ebf\u4e0a<\/p>\n<p>\u65f6\u949f\u7ebf\u4e0e\u6570\u636e\u7ebf\u90fd\u9700\u63a5\u4e0a\u62c9\u7535\u963b&#xff0c;\u5e76\u4e14\u90fd\u4e3a\u5f00\u6f0f\u8f93\u51fa&#xff08;\u903b\u8f91\u7ebf\u4e0e&#xff09;<\/p>\n<p>\u6bcf\u4e00\u4e2a\u4ece\u673a\u90fd\u6709\u4e00\u4e2a7\u4f4d\u7684\u4ece\u673a\u5730\u5740<\/p>\n<p>\u4e3b\u673a\u5148\u53d1\u9001\u4ece\u673a\u5730\u5740\u4e0e\u4ece\u673a\u5efa\u7acb\u901a\u4fe1&#xff0c;\u7136\u540e\u4e0e\u4ece\u673a\u8fdb\u884c\u6570\u636e\u4ea4\u4e92<\/p>\n<h4 id=\"1.3.%E6%95%B0%E6%8D%AE%E7%BA%BF%E5%92%8C%E6%97%B6%E9%92%9F%E7%BA%BF\">1.3.\u6570\u636e\u7ebf\u548c\u65f6\u949f\u7ebf<\/h4>\n<p>SDA&#xff1a;\u6570\u636e\u7ebf&#xff0c;\u7528\u6765\u4f20\u8f93\u6570\u636e<\/p>\n<p>\u6570\u636e\u4fe1\u53f7&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"71\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215747-697d295b6411e.png\" width=\"372\" \/><\/p>\n<p>SCL&#xff1a;\u65f6\u949f\u7ebf&#xff0c;\u7528\u6765\u4f20\u8f93\u65f6\u949f<\/p>\n<p>\u65f6\u949f\u4fe1\u53f7&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"72\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215747-697d295b76c35.png\" width=\"417\" \/><\/p>\n<p>\u6ce8&#xff1a;<\/p>\n<p>\u65f6\u949f\u4fe1\u53f7\u603b\u662f\u7531\u4e3b\u673a\u53d1\u9001\u7ed9\u4ece\u673a&#xff08;\u5355\u5411&#xff09;<\/p>\n<p>\u6570\u636e\u4fe1\u53f7\u53ef\u4ee5\u7531\u4e3b\u673a\u53d1\u9001\u7ed9\u4ece\u673a&#xff0c;\u4e5f\u53ef\u4ee5\u7531\u4ece\u673a\u53d1\u9001\u7ed9\u4e3b\u673a&#xff08;\u53cc\u5411&#xff09;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"314\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215747-697d295b87d9d.png\" width=\"455\" \/><\/p>\n<h4 id=\"1.4.%E9%80%BB%E8%BE%91%E7%BA%BF%E4%B8%8E\">1.4.\u903b\u8f91\u7ebf\u4e0e<\/h4>\n<h5 id=\"1.4.1.%E9%80%BB%E8%BE%91%E4%B8%8E\">1.4.1.\u903b\u8f91\u4e0e<\/h5>\n<p>\u4e0e\u8fd0\u7b97&#xff1a;&amp;<\/p>\n<p>Y &#061; X1 &amp; X2 &amp; X3 &#8230; &amp;Xn<\/p>\n<p>\u53ea\u8981 X1~Xn\u91cc\u4efb\u610f\u4e00\u4e2a\u7b49\u4e8e0&#xff0c;\u7ed3\u679c\u4e3a0<\/p>\n<p>\u5f53X1~Xn\u5168\u90e8\u90fd\u7b49\u4e8e1&#xff0c;\u7ed3\u679c\u4e3a1<\/p>\n<h5 id=\"1.4.2.%E9%80%BB%E8%BE%91%E7%BA%BF%E4%B8%8E\">1.4.2.\u903b\u8f91\u7ebf\u4e0e<\/h5>\n<p>\u5c06\u6240\u6709\u8bbe\u5907\u7684SCL\u5f15\u811a\u8bbe\u7f6e\u4e3a\u8f93\u51fa\u5f00\u6f0f\u6a21\u5f0f<\/p>\n<p>\u5411\u6240\u6709\u8bbe\u5907\u7684SCL\u5f15\u811a\u51991&#xff0c;\u5185\u90e8\u7684N-MOS\u7ba1\u65ad\u5f00<\/p>\n<p>\u6b64\u65f6SCL\u5f15\u811a\u5904\u4e8e\u9ad8\u963b\u6297&#xff0c;\u76f8\u5f53\u4e8e\u5f15\u811a\u4ece\u7535\u8def\u65ad\u5f00<\/p>\n<p>\u5982\u679c\u4e0d\u63a5\u4e0a\u62c9\u7535\u963b&#xff0c;\u65f6\u949f\u7ebf\u5c31\u4f1a\u5904\u4e8e\u60ac\u7a7a\u72b6\u6001&#xff0c;\u5bfc\u81f4\u7535\u5e73\u4e0d\u7a33\u5b9a<\/p>\n<p>\u4e0a\u62c9\u7535\u963b\u53ef\u4ee5\u5c06\u60ac\u7a7a\u7684\u65f6\u949f\u7ebf\u62c9\u5230\u7a33\u5b9a\u7684\u9ad8\u7535\u5e73&#xff0c;\u8868\u793a1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"332\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215747-697d295ba2179.png\" width=\"387\" \/><\/p>\n<p>\u5c06\u6240\u6709\u8bbe\u5907\u7684SCL\u5f15\u811a\u8bbe\u7f6e\u4e3a\u8f93\u51fa\u5f00\u6f0f\u6a21\u5f0f<\/p>\n<p>\u5411\u67d0\u4e2a\u8bbe\u5907\u7684SCL\u5f15\u811a\u51990&#xff0c;\u5176\u4f59SCL\u5f15\u811a\u90fd\u51991<\/p>\n<p>\u51991\u7684\u5f15\u811a\u4e3a\u9ad8\u963b\u6297&#xff0c;\u51990\u7684\u5f15\u811a\u8f93\u51fa\u4f4e\u7535\u538b&#xff08;\u76f8\u5f53\u4e8e\u63a5\u5730&#xff09;<\/p>\n<p>\u65f6\u949f\u7ebf\u901a\u8fc7\u51990\u7684SCL\u5f15\u811a\u63a5\u5730\u8f93\u51fa\u4f4e\u7535\u5e73&#xff0c;\u8868\u793a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"306\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215747-697d295bbc64c.png\" width=\"405\" \/><\/p>\n<h4 id=\"1.5.%E4%B8%BB%E6%9C%BA%E5%A6%82%E4%BD%95%E5%8F%91%E9%80%81%E6%97%B6%E9%92%9F%E4%BF%A1%E5%8F%B7\">1.5.\u4e3b\u673a\u5982\u4f55\u53d1\u9001\u65f6\u949f\u4fe1\u53f7<\/h4>\n<p>\u53d1\u9001\u4f4e\u7535\u5e73&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"219\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215747-697d295bd8f8c.png\" width=\"380\" \/><\/p>\n<p>Y &#061; 0 &amp; 1 &amp; 1 &#8230; &amp; 1 &#061; 0&#xff08;\u4f4e\u7535\u5e73&#xff09;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"69\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215748-697d295c004cb.png\" width=\"330\" \/><\/p>\n<p>\u53d1\u9001\u9ad8\u7535\u5e73&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"226\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215748-697d295c128e4.png\" width=\"400\" \/><\/p>\n<p>Y &#061; 1\u00a0&amp; 1 &amp; 1 &#8230; &amp; 1 &#061; 1 &#xff08;\u9ad8\u7535\u5e73&#xff09;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"120\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215748-697d295c2d19d.png\" width=\"440\" \/><\/p>\n<h4 id=\"1.6.%E4%B8%BB%E6%9C%BA%E5%A6%82%E4%BD%95%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE\">1.6.\u4e3b\u673a\u5982\u4f55\u53d1\u9001\u6570\u636e<\/h4>\n<p>\u53d1\u90010&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"229\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215748-697d295c41c04.png\" width=\"355\" \/><\/p>\n<p>Y &#061; 0 &amp; 1 &amp; 1 &#8230; &amp; 1 &#061; 0&#xff08;\u4f4e\u7535\u5e73&#xff09;<\/p>\n<p>\u53d1\u90011&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"222\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215748-697d295c5fad3.png\" width=\"344\" \/><\/p>\n<p>Y &#061; 1\u00a0&amp; 1 &amp; 1 &#8230; &amp; 1 &#061; 1 &#xff08;\u9ad8\u7535\u5e73&#xff09;<\/p>\n<h4 id=\"1.7.%E4%BB%8E%E6%9C%BA%E5%A6%82%E4%BD%95%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE\">1.7.\u4ece\u673a\u5982\u4f55\u53d1\u9001\u6570\u636e<\/h4>\n<p>\u53d1\u90010&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"198\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215748-697d295c7c521.png\" width=\"347\" \/><\/p>\n<p>Y &#061; 1\u00a0&amp; 0\u00a0&amp; 1 &#8230; &amp; 1 &#061; 0&#xff08;\u4f4e\u7535\u5e73&#xff09;<\/p>\n<p>\u53d1\u90011&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"186\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215748-697d295c9a35a.png\" width=\"356\" \/><\/p>\n<p>Y &#061; 1\u00a0&amp; 1 &amp; 1 &#8230; &amp; 1 &#061; 1 &#xff08;\u9ad8\u7535\u5e73&#xff09;<\/p>\n<h4 id=\"1.8.%E4%B8%BA%E4%BD%95%E4%B8%8A%E6%8B%89%EF%BC%9F%E4%B8%BA%E4%BD%95%E5%BC%80%E6%BC%8F%EF%BC%9F\">1.8.\u4e3a\u4f55\u4e0a\u62c9&#xff1f;\u4e3a\u4f55\u5f00\u6f0f&#xff1f;<\/h4>\n<p>\u5411\u8bbe\u5907\u5f15\u811a\u51991&#xff0c;\u5f15\u811a\u5904\u4e8e\u9ad8\u963b\u6001&#xff0c;\u76f8\u5f53\u4e8e\u5f00\u8def&#xff0c;\u603b\u7ebf\u80fd\u591f\u4e0e\u4e0a\u62c9\u7535\u963b\u76f8\u8fde&#xff0c;\u4ea7\u751f\u9ad8\u7535\u5e73<\/p>\n<p>\u5411\u8bbe\u5907\u5f15\u811a\u51990&#xff0c;\u5f15\u811a\u5904\u4e8e\u4f4e\u7535\u538b&#xff0c;\u76f8\u5f53\u4e8e\u63a5\u5730&#xff0c;\u603b\u7ebf\u80fd\u591f\u901a\u8fc7\u5f15\u811a\u7aef\u53e3\u7535\u8def\u63a5\u5730&#xff0c;\u4ea7\u751f\u4f4e\u7535\u5e73<\/p>\n<p>\u5982\u679c\u662f\u63a8\u633d\u6a21\u5f0f&#xff0c;\u4e00\u4e2a\u8bbe\u5907\u51990\u4e3a\u4f4e\u7535\u5e73&#xff0c;\u4e00\u4e2a\u8bbe\u5907\u51991\u4e3a\u9ad8\u7535\u5e73&#xff0c;\u76f4\u63a5\u9020\u6210\u77ed\u8def<\/p>\n<p>\u5982\u679c\u662f\u4e0b\u62c9\u7535\u963b&#xff0c;\u53ea\u80fd\u5c06\u603b\u7ebf\u62c9\u5230\u4f4e\u7535\u5e73&#xff0c;\u65e0\u6cd5\u4e3a\u603b\u7ebf\u63d0\u4f9b\u9ad8\u7535\u5e73<\/p>\n<h3 id=\"%E4%BA%8C%E3%80%81%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE\">\u4e8c\u3001\u901a\u4fe1\u534f\u8bae<\/h3>\n<h4 id=\"2.1.I2C%E9%80%9A%E4%BF%A1%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%B5%81%E7%A8%8B\">2.1.I2C\u901a\u4fe1\u7684\u57fa\u672c\u6d41\u7a0b<\/h4>\n<h4 id=\"%E2%80%8B%E7%BC%96%E8%BE%91\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"203\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215748-697d295cb43e5.png\" width=\"526\" \/><\/h4>\n<ul>\n<li>\u4e3b\u673a\u5411\u603b\u7ebf\u53d1\u9001\u53d1\u9001\u8d77\u59cb\u4f4d<\/li>\n<li>\u4e3b\u673a\u5411\u603b\u7ebf\u53d1\u90017\u4f4d\u4ece\u673a\u5730\u5740&#043;1\u4f4d\u8bfb\u5199\u4f4d<\/li>\n<li>\u4e3b\u673a\u548c\u4ece\u673a\u8fdb\u884c\u6570\u636e\u4f20\u8f93<\/li>\n<li>\u4e3b\u673a\u5411\u603b\u7ebf\u53d1\u9001\u505c\u6b62\u4f4d<\/li>\n<\/ul>\n<h4 id=\"2.2.I2C%E7%9A%84%E6%95%B0%E6%8D%AE%E5%B8%A7%E6%A0%BC%E5%BC%8F\">2.2.I2C\u7684\u6570\u636e\u5e27\u683c\u5f0f<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"155\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215748-697d295cf00da.png\" width=\"532\" \/><\/p>\n<p>\u6ce8&#xff1a;\u4e32\u53e3\u7684\u6570\u636e\u5e27\u6bcf\u6b21\u53ea\u80fd\u4f20\u8f938~9bit&#xff0c;I2C\u7684\u6570\u636e\u5e27\u6bcf\u6b21\u53ef\u4ee5\u4f20\u8f93\u591a\u4e2a\u5b57\u8282<\/p>\n<h4 id=\"2.3.%E8%B5%B7%E5%A7%8B%E4%BD%8D%E5%92%8C%E5%81%9C%E6%AD%A2%E4%BD%8D\">2.3.\u8d77\u59cb\u4f4d\u548c\u505c\u6b62\u4f4d<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"149\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215749-697d295d1eca4.png\" width=\"530\" \/><\/p>\n<h5 id=\"2.3.1.%E8%B5%B7%E5%A7%8B%E4%BD%8D\">2.3.1.\u8d77\u59cb\u4f4d<\/h5>\n<ul>\n<li>SCL &#061; H<\/li>\n<li>SDA \u2193<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"130\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215749-697d295d4e4ca.png\" width=\"237\" \/><\/p>\n<h5 id=\"2.3.2.%E5%81%9C%E6%AD%A2%E4%BD%8D\">2.3.2.\u505c\u6b62\u4f4d<\/h5>\n<ul>\n<li>SCL &#061; H<\/li>\n<li>SDA \u2191<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"129\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215749-697d295d6e317.png\" width=\"275\" \/><\/p>\n<h4 id=\"2.4.%E5%AF%BB%E5%9D%80\">2.4.\u5bfb\u5740<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"253\" src=\"2026-01-31t23whj50xd3.png\" width=\"439\" \/><\/p>\n<p>\u5e94\u7b54&#xff08;Ack&#xff09;&#xff1a;<\/p>\n<p>\u5411\u4e3b\u673aSDA\u5f15\u811a\u51991&#xff0c;\u5f15\u811a\u5904\u4e8e\u9ad8\u963b\u6001&#xff0c;\u76f8\u5f53\u4e8e\u5f00\u8def&#xff0c;\u603b\u7ebf\u80fd\u591f\u4e0e\u4e0a\u62c9\u7535\u963b\u76f8\u8fde&#xff0c;\u4ea7\u751f\u9ad8\u7535\u5e73<\/p>\n<p>\u4f46\u5728\u8fd9\u8fc7\u7a0b\u4e2d&#xff0c;\u82e5\u5411\u4ece\u673aSDA\u5f15\u811a\u51990&#xff0c;\u5f15\u811a\u5904\u4e8e\u4f4e\u7535\u538b&#xff0c;\u76f8\u5f53\u4e8e\u63a5\u5730&#xff0c;\u603b\u7ebf\u80fd\u591f\u901a\u8fc7\u5f15\u811a\u7aef\u53e3\u7535<\/p>\n<p>\u8def\u63a5\u5730&#xff0c;\u4ea7\u751f\u4f4e\u7535\u5e73&#xff0c;\u6b64\u65f6\u4e3b\u673a\u68c0\u6d4b\u5230\u4f4e\u7535\u538b&#xff0c;\u63a5\u6536\u5230\u4ece\u673a\u7684\u5e94\u7b54\u4fe1\u53f7<\/p>\n<p>Y &#061; 1\u00a0&amp; 0\u00a0&amp; 1 &#8230; &amp; 1 &#061; 0&#xff08;\u4f4e\u7535\u5e73&#xff09;<\/p>\n<p>\u6ce8&#xff1a;<\/p>\n<ul>\n<li>\u4e32\u53e3\u662f\u4f4e\u4f4d\u5148\u884c&#xff08;LSB First&#xff09;&#xff0c;\u53d1\u9001\u5b57\u8282\u65f6\u4ece\u6700\u4f4e\u4f4d\u5f00\u59cb<\/li>\n<li>I2C\u662f\u9ad8\u4f4d\u5148\u884c&#xff08;MSB First&#xff09;&#xff0c;\u53d1\u9001\u5b57\u8282\u65f6\u4ece\u6700\u9ad8\u4f4d\u5f00\u59cb<\/li>\n<li>0\u51991\u8bfb<\/li>\n<\/ul>\n<h4 id=\"2.5.%E4%BC%A0%E8%BE%93%E6%95%B0%E6%8D%AE\">2.5.\u4f20\u8f93\u6570\u636e<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"289\" src=\"2026-01-31nnyep3hcl23.png\" width=\"542\" \/><\/p>\n<p>\u6ce8&#xff1a;\u53d1\u9001\u65b9\u91ca\u653eSDA&#xff0c;\u63a5\u6536\u65b9\u62c9\u4f4eSDA\u8868\u793a\u5e94\u7b54<\/p>\n<h4 id=\"2.6.%E4%BE%8B%E5%AD%90\">2.6.\u4f8b\u5b50<\/h4>\n<h5 id=\"2.6.1.%E5%90%91%E4%BB%8E%E6%9C%BA0x78%E5%86%99%E4%B8%A4%E4%B8%AA%E5%AD%97%E8%8A%82%EF%BC%880x5a%EF%BC%8C0x33%EF%BC%89\">2.6.1.\u5411\u4ece\u673a0x78\u5199\u4e24\u4e2a\u5b57\u8282&#xff08;0x5a&#xff0c;0x33&#xff09;<\/h5>\n<p>\u5bfb\u57400x78&#xff08;\u5199&#xff09;&#xff1a;<\/p>\n<p>0x78\u4e8c\u8fdb\u5236&#xff1a;0111 1000<\/p>\n<p>\u5de6\u79fb1\u4f4d&#xff1a;\u00a01111 0000<\/p>\n<p>\u4f4e\u4f4d\u62160\u4e3a\u5199&#xff1a; 1111 000(7\u4f4d\u5730\u5740)0(\u8bfb\u5199\u4f4d)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"105\" src=\"2026-01-31ebva30sbprt.png\" width=\"403\" \/><\/p>\n<p>\u5199\u6570\u636e0x5a&#xff1a;<\/p>\n<p>0x5a\u4e8c\u8fdb\u5236&#xff1a;0101 1010<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"93\" src=\"2026-01-31fefn12yzgbt.png\" width=\"506\" \/><\/p>\n<p>\u5199\u6570\u636e0x33&#xff1a;<\/p>\n<p>0x33\u4e8c\u8fdb\u5236&#xff1a;0011 0011<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"236\" src=\"2026-01-31lx0gldklzb2.png\" width=\"680\" \/><\/p>\n<h5 id=\"2.6.2.%E4%BB%8E%E4%BB%8E%E6%9C%BA0x20%E8%AF%BB%E4%B8%80%E4%B8%AA%E5%AD%97%E8%8A%82%EF%BC%88%E5%81%87%E8%AE%BE%E8%AF%BB%E5%88%B0%E7%9A%84%E6%98%AF0x64%EF%BC%89\">2.6.2.\u4ece\u4ece\u673a0x20\u8bfb\u4e00\u4e2a\u5b57\u8282&#xff08;\u5047\u8bbe\u8bfb\u5230\u7684\u662f0x64&#xff09;<\/h5>\n<p>\u5bfb\u57400x20&#xff08;\u8bfb&#xff09;&#xff1a;<\/p>\n<p>0x20\u4e8c\u8fdb\u5236&#xff1a;0010 0000<\/p>\n<p>\u5de6\u79fb1\u4f4d&#xff1a; 0100 0000<\/p>\n<p>\u4f4e\u4f4d\u62161\u4e3a\u8bfb&#xff1a; 0100\u00a0000(7\u4f4d\u5730\u5740)1(\u8bfb\u5199\u4f4d)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"133\" src=\"2026-01-314zww5qp4jrv.png\" width=\"485\" \/><\/p>\n<p>\u8bfb\u6570\u636e0x64&#xff1a;<\/p>\n<p>0x64\u4e8c\u8fdb\u5236&#xff1a;0101 0100<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"258\" src=\"2026-01-31fukhfyg2jpu.png\" width=\"1272\" \/><\/p>\n<p>I2C\u505c\u6b62\u6761\u4ef6\u89e3\u8bfb&#xff1a;<\/p>\n<p>\u4e3b\u673a\u53d1\u9001Nack&#xff1a;<\/p>\n<ul>\n<li>\u65f6\u673a&#xff1a;\u8bfb\u53d6\u6700\u540e\u4e00\u4e2a\u6570\u636e\u5b57\u8282\u540e&#xff0c;\u8fdb\u5165\u7b2c\u4e5d\u4e2aSCL\u65f6\u949f\u5468\u671f<\/li>\n<li>\u7535\u5e73&#xff1a;\u4e3b\u673a\u4f5c\u4e3a\u63a5\u6536\u65b9&#xff0c;\u4fdd\u6301SDA\u9ad8\u7535\u5e73&#xff0c;\u4e0d\u8fdb\u884c\u62c9\u4f4e\u64cd\u4f5c<\/li>\n<li>\u4f5c\u7528&#xff1a;\u5411\u4ece\u673a\u8868\u660e\u8fd9\u65f6\u6700\u540e\u4e00\u4e2a\u5b57\u8282&#xff0c;\u65e0\u9700\u518d\u53d1\u9001\u6570\u636e<\/li>\n<\/ul>\n<p>\u51c6\u5907\u505c\u6b62\u6761\u4ef6&#xff1a;<\/p>\n<ul>\n<li>\u65f6\u673a&#xff1a;Nack\u5468\u671f\u7ed3\u675f\u540e&#xff0c;SCL\u7ebf\u88ab\u4e3b\u673a\u62c9\u4f4e\u540e<\/li>\n<li>\u7535\u5e73&#xff1a;\u5728SCL\u4e3a\u4f4e\u7535\u5e73\u65f6&#xff0c;\u4e3b\u673a\u5c06SDA\u4ece\u9ad8\u7535\u5e73\u62c9\u5230\u4f4e\u7535\u5e73<\/li>\n<li>\u4f5c\u7528&#xff1a;\u4e3a\u540e\u7eed\u751f\u6210\u505c\u6b62\u6761\u4ef6\u4f5c\u51c6\u5907<\/li>\n<\/ul>\n<p>\u751f\u6210\u505c\u6b62\u6761\u4ef6&#xff1a;<\/p>\n<ul>\n<li>\u65f6\u673a&#xff1a;\u4e3b\u673a\u62c9\u9ad8SCL\u7ebf&#xff0c;\u4f7f\u5176\u5904\u4e8e\u9ad8\u7535\u5e73\u72b6\u6001<\/li>\n<li>\u7535\u5e73&#xff1a;\u5728SCL\u4e3a\u9ad8\u7535\u5e73\u65f6&#xff0c;\u4e3b\u673a\u5c06SDA\u4ece\u4f4e\u7535\u5e73\u62c9\u5230\u9ad8\u7535\u5e73<\/li>\n<li>\u4f5c\u7528&#xff1a;\u6807\u5fd7\u7740\u901a\u4fe1\u7ed3\u675f&#xff0c;\u603b\u7ebf\u90fd\u88ab\u91ca\u653e&#xff0c;\u5904\u4e8e\u7a7a\u95f2\u72b6\u6001<\/li>\n<\/ul>\n<h3 id=\"%E4%B8%89%E3%80%81I2C%E6%A8%A1%E5%9D%97%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95\">\u4e09\u3001I2C\u6a21\u5757\u7684\u4f7f\u7528\u65b9\u6cd5<\/h3>\n<h4 id=\"3.1.I2C%E6%A8%A1%E5%9D%97%E7%AE%80%E4%BB%8B\">3.1.I2C\u6a21\u5757\u7b80\u4ecb<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"234\" src=\"2026-01-31ftusohawow3.png\" width=\"412\" \/><\/p>\n<p>I2C\u6a21\u5757\u662f\u5355\u7247\u673a\u4e0a\u7684\u7247\u4e0a\u5916\u8bbe&#xff0c;\u7ed9\u5355\u7247\u673a\u63d0\u4f9bI2C\u901a\u4fe1\u63a5\u53e3<\/p>\n<h4 id=\"3.2.IO%E5%BC%95%E8%84%9A%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8C%96\">3.2.IO\u5f15\u811a\u7684\u521d\u59cb\u5316<\/h4>\n<h5 id=\"3.2.1.%E5%BC%95%E8%84%9A%E5%88%86%E5%B8%83\">3.2.1.\u5f15\u811a\u5206\u5e03<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"112\" src=\"2026-01-31evaeybzb04r.png\" width=\"424\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"102\" src=\"2026-01-310qtbaoesxdv.png\" width=\"435\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"381\" src=\"2026-01-31excj1fyhdnc.png\" width=\"410\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"100\" src=\"2026-01-313vkkct1ftf4.png\" width=\"451\" \/><\/p>\n<p>\u590d\u7528&#xff1a;CPU\u501f\u52a9I2C\u6a21\u5757\u6765\u63a7\u5236IO\u5f15\u811a<\/p>\n<p>\u5f00\u6f0f&#xff1a;\u5b9e\u73b0\u903b\u8f91\u7ebf\u4e0e<\/p>\n<h5 id=\"3.2.2.%E7%BC%96%E7%A0%81%E9%83%A8%E5%88%86\">3.2.2.\u7f16\u7801\u90e8\u5206<\/h5>\n<p>\/\/#1&#xff1a;\u521d\u59cb\u5316GPIO<\/p>\n<p>\/*\u5f00\u542fAFIO\u6a21\u5757\u7684\u65f6\u949f*\/<br \/>\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);<br \/>\n\/*\u4f7f\u80fdI2C1\u7684\u91cd\u6620\u5c04*\/<br \/>\nGPIO_PinRemapConfig(GPIO_Remap_I2C1,ENABLE);<br \/>\n\/*\u5f00\u542fGPIOB\u6a21\u5757\u7684\u65f6\u949f*\/<br \/>\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);<br \/>\n\/*GPIO\u7ed3\u6784\u7684\u524d\u7f6e\u58f0\u660e*\/<br \/>\nGPIO_InitTypeDef GPIO_InitStruct;<br \/>\n\/*\u9009\u62e9PB8\u548cPB9\u5f15\u811a*\/<br \/>\nGPIO_InitStruct.GPIO_Pin &#061; GPIO_Pin_8 | GPIO_Pin_9;<br \/>\n\/*\u8bbe\u7f6e\u590d\u7528\u8f93\u51fa\u5f00\u6f0f\u6a21\u5f0f*\/<br \/>\nGPIO_InitStruct.GPIO_Mode &#061; GPIO_Mode_AF_OD;<br \/>\n\/*\u6700\u5927\u8f93\u51fa\u901f\u5ea6\u5c3e2MHz*\/<br \/>\nGPIO_InitStruct.GPIO_Speed &#061; GPIO_Speed_2MHz;<br \/>\n\/*\u521d\u59cb\u5316PB8\u548cPB9\u5f15\u811a*\/<br \/>\nGPIO_Init(GPIOB,&amp;GPIO_InitStruct); <\/p>\n<h4 id=\"3.3.%E8%BF%9E%E6%8E%A5%E7%94%B5%E8%B7%AF\">3.3.\u8fde\u63a5\u7535\u8def<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"325\" src=\"2026-01-31jff41mxowhh.png\" width=\"363\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"279\" src=\"2026-01-31s2wgfpqrd2i.png\" width=\"356\" \/><\/p>\n<h4 id=\"%C2%A03.4.I2C%E7%9A%84%E9%80%9F%E5%BA%A6%E6%A8%A1%E5%BC%8F\">\u00a03.4.I2C\u7684\u901f\u5ea6\u6a21\u5f0f<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"84\" src=\"2026-01-31x2pgebovqpd.png\" width=\"360\" \/><\/p>\n<p>\u6ce2\u7279\u7387&#xff1a;\u6bcf\u79d2\u949f\u4f20\u8f93\u7684\u4f4d\u6570<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>\u6807\u51c6\u6a21\u5f0f<\/td>\n<td>Sm<\/td>\n<td>Standard Mode<\/td>\n<td>\u2264100kbps<\/td>\n<\/tr>\n<tr>\n<td>\u5feb\u901f\u6a21\u5f0f<\/td>\n<td>Fm<\/td>\n<td>Fast Mode<\/td>\n<td>\u2264400kbps<\/td>\n<\/tr>\n<tr>\n<td>\u5feb\u901f\u589e\u5f3a\u6a21\u5f0f<\/td>\n<td>Fm&#043;<\/td>\n<td>Fast Mode Plus<\/td>\n<td>\u22641Mbps<\/td>\n<\/tr>\n<tr>\n<td>\u9ad8\u901f\u6a21\u5f0f<\/td>\n<td>HSm<\/td>\n<td>High Speed Mode<\/td>\n<td>\u22643.4Mbps<\/td>\n<\/tr>\n<tr>\n<td>\u8d85\u5feb\u6a21\u5f0f<\/td>\n<td>UFm<\/td>\n<td>Ultra Fast Mode<\/td>\n<td>\u22645Mbps<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8&#xff1a;STM32\u53ea\u652f\u6301\u6807\u51c6\u6a21\u5f0f\u548c\u5feb\u901f\u6a21\u5f0f<\/p>\n<h4 id=\"3.5.%E6%97%B6%E9%92%9F%E4%BF%A1%E5%8F%B7%E7%9A%84%E5%8D%A0%E7%A9%BA%E6%AF%94\">3.5.\u65f6\u949f\u4fe1\u53f7\u7684\u5360\u7a7a\u6bd4<\/h4>\n<p>\u5feb\u901f\u6a21\u5f0f\u4e0b\u53ef\u4ee5\u8bbe\u7f6e\u65f6\u949f\u4fe1\u53f7\u7684\u5360\u7a7a\u6bd4<\/p>\n<p>\u65f6\u949f\u4fe1\u53f7&#xff1a;SCL\u4f20\u8f93\u7684\u4fe1\u53f7&#xff0c;\u63a7\u5236\u901a\u4fe1\u7684\u901f\u7387<\/p>\n<p>\u6ce8&#xff1a;\u591a\u6570\u901a\u4fe1\u534f\u8bae\u4f7f\u7528\u9ad8\u7535\u5e73\u91c7\u6837&#xff0c;\u4f4e\u7535\u5e73\u66f4\u65b0\u7684\u5de5\u4f5c\u65b9\u5f0f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"49\" src=\"2026-01-31llbz41rb5yc.png\" width=\"326\" \/><\/p>\n<p>\u5360\u7a7a\u6bd4&#xff1a;\u5728\u4e00\u4e2a\u5468\u671f\u4e2d\u9ad8\u7535\u538b\u5360\u6574\u4e2a\u5468\u671f\u7684\u6bd4\u4f8b<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"146\" src=\"2026-01-31g0pfaaaaxk3.png\" width=\"360\" \/><\/p>\n<p>\u6ce8&#xff1a;\u4e00\u822c\u60c5\u51b5\u4e0b\u4f7f\u75282&#xff1a;1\u7684\u5360\u7a7a\u6bd4<\/p>\n<h4 id=\"3.6.I2C%E6%A8%A1%E5%9D%97%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8C%96\">3.6.I2C\u6a21\u5757\u7684\u521d\u59cb\u5316<\/h4>\n<h5 id=\"3.6.1.%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A3\">3.6.1.\u7f16\u7a0b\u63a5\u53e3<\/h5>\n<p>void I2C_Init(I2CTypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct); <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<ul>\n<li>\u53c2\u65701&#xff1a;I2C\u540d\u79f0 I2C1,I2C2<\/li>\n<li>\u53c2\u65702&#xff1a;\u521d\u59cb\u5316\u7684\u53c2\u6570\u7ed3\u6784\u4f53\u5730\u5740<\/li>\n<\/ul>\n<p>\u4f5c\u7528&#xff1a;\u521d\u59cb\u5316I2C&#xff0c;\u914d\u7f6eI2C\u7684\u5404\u79cd\u53c2\u6570<\/p>\n<ul>\n<li>I2C\u7684\u6ce2\u7279\u7387<\/li>\n<li>I2C\u7684\u6a21\u5f0f<\/li>\n<li>I2C\u7684\u5360\u7a7a\u6bd4&#xff08;\u5feb\u901f\u6a21\u5f0f&#xff09;<\/li>\n<li>\u4e0e\u4ece\u673a\u6a21\u5f0f\u6709\u5173\u7684\u53c2\u6570<\/li>\n<\/ul>\n<p>\u8865\u5145&#xff1a;I2C_InitTypeDef\u7ed3\u6784&#xff08;I2C\u53c2\u6570\u83dc\u5355&#xff09;<\/p>\n<p>typedef struct I2C_InitTypeDef<br \/>\n{<br \/>\nuint32_t I2C_ClockSpeed;<br \/>\nuint16_t I2C_Mode;<br \/>\nuint16_t I2C_DutyCycle;<br \/>\nuint16_t I2C_Ack;<br \/>\nuint16_t I2C_OwnAddress1;<br \/>\nuint16_t I2C_AcknowledgedAddress;<br \/>\n}; <\/p>\n<p>\u5206\u6790&#xff1a;<\/p>\n<p>1.I2C_ClockSpeed&#xff1a;\u6ce2\u7279\u7387<\/p>\n<ul>\n<li>Sm&#xff1a;&lt;&#061;100\u00a0\u00a0<\/li>\n<li>Fm&#xff1a;&lt;&#061;400\u00a0\u00a0<\/li>\n<\/ul>\n<p>2.I2C_Mode&#xff1a;\u6a21\u5f0f<\/p>\n<ul>\n<li>I2C_Mode_I2C&#xff1a;\u6807\u51c6I2C\u6a21\u5f0f<\/li>\n<li>I2C_Mode_SMBusDevice&#xff1a;\u7cfb\u7edf\u7ba1\u7406\u603b\u7ebf\u8bbe\u5907\u6a21\u5f0f<\/li>\n<li>I2C_Mode_SMBusHost&#xff1a;\u7cfb\u7edf\u7ba1\u7406\u603b\u7ebf\u4e3b\u673a\u6a21\u5f0f<\/li>\n<\/ul>\n<p>3.I2C_DutyCycle&#xff1a;\u5feb\u901f\u6a21\u5f0f\u4e0b\u65f6\u949f\u4fe1\u53f7\u7684\u5360\u7a7a\u6bd4<\/p>\n<ul>\n<li>I2C_DutyCycle_16_9&#xff1a;\u5360\u7a7a\u6bd4\u4e3a16&#xff1a;9<\/li>\n<li>I2C_DutyCycle_2&#xff1a;\u5360\u7a7a\u6bd4\u4e3a2&#xff1a;1<\/li>\n<\/ul>\n<p>4.I2C_Ack&#xff1a;\u4e0e\u4ece\u673a\u6a21\u5f0f\u6709\u5173<\/p>\n<p>5.I2C_OwnAddress1&#xff1a;\u4e0e\u4ece\u673a\u6a21\u5f0f\u6709\u5173<\/p>\n<p>6.I2C_AcknowledgedAddress&#xff1a;\u7528\u4e8e\u9009\u62e910\u4f4d\u4ece\u673a\u5730\u5740\u6a21\u5f0f<\/p>\n<h5 id=\"3.6.2.%E7%BC%96%E7%A0%81%E9%83%A8%E5%88%86\">3.6.2.\u7f16\u7801\u90e8\u5206<\/h5>\n<p>\/\/#2&#xff1a;\u521d\u59cb\u5316I2C1\u6a21\u5757<\/p>\n<p>\/*\u5f00\u542fI2C1\u6a21\u5757\u7684\u65f6\u949f*\/<br \/>\nRCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);<br \/>\n\/*\u65bd\u52a0\u590d\u4f4d\u4fe1\u53f7*\/<br \/>\nRCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1,ENABLE);<br \/>\n\/*\u91ca\u653e\u590d\u4f4d\u4fe1\u53f7*\/<br \/>\nRCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1,DISABLE);<br \/>\n\/*I2C\u7ed3\u6784\u7684\u524d\u7f6e\u58f0\u660e*\/<br \/>\nI2C_InitTypeDef I2C_InitStruct;<br \/>\n\/*\u6ce2\u7279\u7387\u4e3a400k*\/<br \/>\nI2C_InitStruct.I2C_ClockSpeed &#061; 400000;<br \/>\n\/*\u6a21\u5f0f\u4e3a\u6807\u51c6I2C*\/<br \/>\nI2C_InitStruct.I2C_Mode &#061; I2C_Mode_I2C;<br \/>\n\/*\u5360\u7a7a\u6bd4\u4e3a2&#xff1a;1*\/<br \/>\nI2C_InitStruct.I2C_DutyCycle &#061; I2C_DutyCycle_2;<br \/>\n\/*\u521d\u59cb\u5316I2C1*\/<br \/>\nI2C_Init(I2C1,&amp;I2C_InitStruct);<br \/>\n\/*\u95ed\u5408I2C1\u603b\u5f00\u5173*\/<br \/>\nI2C_Cmd(I2C1,ENABLE); <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"272\" src=\"2026-01-31m3thfr5fcem.png\" width=\"453\" \/><\/p>\n<p>\u6ce8&#xff1a;<\/p>\n<ul>\n<li>I2C\u65f6\u949f\u7528\u7684\u662fAPB1&#xff0c;\u800c\u975eAPB2<\/li>\n<li>I2C\u9700\u8981\u65bd\u52a0\u548c\u91ca\u653e\u590d\u4f4d\u4fe1\u53f7<\/li>\n<li>\u6700\u540e\u8981\u50cf\u4e32\u53e3\u4e00\u6837\u95ed\u5408\u603b\u5f00\u5173<\/li>\n<\/ul>\n<h3 id=\"%E5%9B%9B%E3%80%81%E5%86%99%E6%95%B0%E6%8D%AE\">\u56db\u3001\u5199\u6570\u636e<\/h3>\n<h4 id=\"4.1.I2C%E6%A8%A1%E5%9D%97%E7%9A%84%E5%86%85%E9%83%A8%E7%BB%93%E6%9E%84%E6%A1%86%E5%9B%BE\">4.1.I2C\u6a21\u5757\u7684\u5185\u90e8\u7ed3\u6784\u6846\u56fe<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"258\" src=\"2026-01-31c2d4z2rg2zy.png\" width=\"413\" \/><\/p>\n<p>SDA&#xff1a;I2C\u6570\u636e\u5f15\u811a<\/p>\n<p>SCL&#xff1a;I2C\u65f6\u949f\u5f15\u811a<\/p>\n<p>\u53d1\u9001\u6570\u636e&#xff1a;<\/p>\n<p>\u5c06\u53d1\u9001\u6570\u636e\u5199\u5165\u53d1\u9001\u6570\u636e\u5bc4\u5b58\u5668&#xff0c;I2C\u6a21\u5757\u5c06\u6570\u636e\u79fb\u5230\u79fb\u4f4d\u5bc4\u5b58\u5668&#xff0c;\u9010\u4e2abit\u4f4d\u901a\u8fc7SDA\u53d1\u9001<\/p>\n<p>\u63a5\u6536\u6570\u636e&#xff1a;<\/p>\n<p>SDA\u63a5\u6536\u4ece\u673a\u53d1\u9001\u7684\u6ce2\u5f62&#xff0c;I2C\u6a21\u5757\u5c06\u6ce2\u5f62\u89e3\u6790&#xff0c;\u9010\u4e2abit\u4f4d\u79fb\u5230\u79fb\u4f4d\u5bc4\u5b58\u5668&#xff0c;\u653e\u5165\u63a5\u6536\u6570\u636e\u5bc4\u5b58\u5668<\/p>\n<p>SR1&#xff08;Status Register1&#xff09;&#xff1a;\u72b6\u6001\u5bc4\u5b58\u56681&#xff0c;\u5b58\u653eI2C\u6a21\u5757\u8fd0\u884c\u72b6\u6001\u7684\u6807\u5fd7\u4f4d<\/p>\n<p>SR2&#xff08;Status Register2&#xff09;&#xff1a;\u72b6\u6001\u5bc4\u5b58\u56682&#xff0c;\u5b58\u653eI2C\u6a21\u5757\u8fd0\u884c\u72b6\u6001\u7684\u6807\u5fd7\u4f4d<\/p>\n<p>SDA\u63a7\u5236\u7535\u8def&#xff1a;\u63a7\u5236SDA\u5f15\u811a\u5411\u5916\u53d1\u9001\u6ce2\u5f62&#xff0c;\u89e3\u6790SDA\u63a5\u6536\u7684\u6ce2\u5f62<\/p>\n<p>SDA\u63a7\u5236\u5bc4\u5b58\u5668&#xff1a;\u63a7\u5236I2C\u6a21\u5757\u884c\u4e3a<\/p>\n<p>SCL\u63a7\u5236\u7535\u8def&#xff1a;\u63a7\u5236SCL\u5f15\u811a\u5411\u5916\u53d1\u9001\u65f6\u949f\u4fe1\u53f7<\/p>\n<p>SCL\u914d\u7f6e\u5bc4\u5b58\u5668&#xff1a;\u914d\u7f6e\u65f6\u949f\u4fe1\u53f7\u7684\u901f\u5ea6\u6a21\u5f0f&#xff0c;\u5360\u7a7a\u6bd4\u548c\u6ce2\u7279\u7387<\/p>\n<h4 id=\"4.2.%E6%95%B0%E6%8D%AE%E5%8F%91%E9%80%81%E8%BF%87%E7%A8%8B%E7%AE%80%E4%BB%8B\">4.2.\u6570\u636e\u53d1\u9001\u8fc7\u7a0b\u7b80\u4ecb<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"48\" src=\"2026-01-31gjh5m3hznjs.png\" width=\"477\" \/><\/p>\n<ul>\n<li>\u4e3b\u673a\u53d1\u9001\u8d77\u59cb\u4f4d<\/li>\n<li>\u4e3b\u673a\u53d1\u90017\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d<\/li>\n<li>\u7b49\u5f85\u4ece\u673aAck<\/li>\n<li>\u4e3b\u673a\u9010\u4e2a\u5b57\u8282\u53d1\u9001\u6570\u636e<\/li>\n<li>\u6bcf\u6b21\u53d1\u9001\u540e\u7b49\u5f85\u4ece\u673aAck<\/li>\n<li>\u4e3b\u673a\u53d1\u9001\u505c\u6b62\u4f4d<\/li>\n<\/ul>\n<h5 id=\"4.2.1.%E5%8F%91%E9%80%81%E5%AD%97%E8%8A%82%E5%87%BD%E6%95%B0\">4.2.1.\u53d1\u9001\u5b57\u8282\u51fd\u6570<\/h5>\n<p>int My_I2C_SendByte(I2C_TypeDef* I2Cx, uint8_t Addr,uint8_t* pData, uint16_t Size); <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<ul>\n<li>\u53c2\u65701&#xff1a;I2C\u63a5\u53e3\u7684\u540d\u79f0<\/li>\n<li>\u53c2\u65702&#xff1a;\u4ece\u673a\u5730\u5740&#xff0c;\u9760\u5de6<\/li>\n<li>\u53c2\u65703&#xff1a;\u8981\u53d1\u9001\u7684\u6570\u636e<\/li>\n<li>\u53c2\u65704&#xff1a;\u8981\u53d1\u9001\u7684\u6570\u636e\u7684\u6570\u91cf&#xff08;\u5355\u4f4d&#xff1a;\u5b57\u8282&#xff09;<\/li>\n<li>\u8fd4\u56de\u503c&#xff1a;0 &#xff08;\u53d1\u9001\u6210\u529f&#xff09;1&#xff08;\u5bfb\u5740\u5931\u8d25&#xff09;2 &#xff08;\u53d1\u9001\u7684\u6570\u636e\u88ab\u62d2\u7edd&#xff0c;\u4ece\u673a\u672a\u53d1\u9001Ack&#xff09;<\/li>\n<\/ul>\n<p>\u4f5c\u7528&#xff1a;\u901a\u8fc7I2C\u5411\u4ece\u673a\u53d1\u9001\u82e5\u5e72\u4e2a\u5b57\u8282<\/p>\n<h4 id=\"4.3.%E7%AD%89%E5%BE%85%E6%80%BB%E7%BA%BF%E7%A9%BA%E9%97%B2\">4.3.\u7b49\u5f85\u603b\u7ebf\u7a7a\u95f2<\/h4>\n<p>\u603b\u7ebf\u7a7a\u95f2\u65f6&#xff0c;SDA\u548cSCL\u5f15\u811a\u90fd\u4e3a\u9ad8\u7535\u5e73<\/p>\n<p>\u5982\u679c\u4e0d\u662f\u9ad8\u7535\u5e73\u65f6&#xff0c;\u5c31\u9700\u8981\u7b49\u5f85\u603b\u7ebf\u7a7a\u95f2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"180\" src=\"2026-01-310ayypnqyvfd.png\" width=\"293\" \/><\/p>\n<p>SR2\u72b6\u6001\u5bc4\u5b58\u5668\u4e2dBUSY&#xff08;\u603b\u7ebf\u5fd9\u6807\u5fd7\u4f4d&#xff09;<\/p>\n<ul>\n<li>0&#xff08;RESET&#xff09;&#xff1a;\u603b\u7ebf\u7a7a\u95f2<\/li>\n<li>1&#xff08;SET&#xff09;&#xff1a;\u603b\u7ebf\u5fd9<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>\/\/#1&#xff1a;\u7b49\u5f85\u603b\u7ebf\u7a7a\u95f2<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_BUSY) &#061;&#061; SET); <\/p>\n<p>\u6ce8&#xff1a;RESET\u4e3a0&#xff0c;SET\u4e3a1<\/p>\n<h4 id=\"4.4.%E5%8F%91%E9%80%81%E8%B5%B7%E5%A7%8B%E4%BD%8D\">4.4.\u53d1\u9001\u8d77\u59cb\u4f4d<\/h4>\n<p>\u00a0\u5411SDA\u63a7\u5236\u5bc4\u5b58\u5668\u7684START\u4f4d\u51991<\/p>\n<p>\u7b49\u5f85\u8d77\u59cb\u4f4d\u53d1\u9001\u5b8c\u6210<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"186\" src=\"2026-01-31x2f4yifh35d.png\" width=\"296\" \/><\/p>\n<\/p>\n<p>SDA\u914d\u7f6e\u5bc4\u5b58\u5668\u4e2d\u7684START&#xff08;\u53d1\u9001\u8d77\u59cb\u4f4d&#xff09;<\/p>\n<ul>\n<li>ENABLE&#xff1a;\u51991<\/li>\n<li>DISABLE&#xff1a;\u51990<\/li>\n<\/ul>\n<p>SR1\u72b6\u6001\u5bc4\u5b58\u5668\u4e2d\u7684SB&#xff08;\u8d77\u59cb\u4f4d\u53d1\u9001\u5b8c\u6210\u6807\u5fd7\u4f4d&#xff09;<\/p>\n<ul>\n<li>0&#xff08;RESET&#xff09;&#xff1a;\u8d77\u59cb\u4f4d\u672a\u53d1\u9001<\/li>\n<li>1&#xff08;SET&#xff09;&#xff1a;\u8d77\u59cb\u4f4d\u53d1\u9001\u5b8c\u6210<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>\/\/#2&#xff1a;\u53d1\u9001\u8d77\u59cb\u4f4d<br \/>\nI2C_GenerateSTART(I2Cx,ENABLE);<br \/>\n\/\/#3&#xff1a;\u7b49\u5f85\u8d77\u59cb\u4f4d\u53d1\u9001\u5b8c\u6210<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_SB) &#061;&#061; RESET); <\/p>\n<h4 id=\"4.5.%E5%8F%91%E9%80%81%E5%9C%B0%E5%9D%80\">4.5.\u53d1\u9001\u5730\u5740<\/h4>\n<p>\u6e05\u96f6AF\u6807\u5fd7\u4f4d&#xff0c;\u53d1\u90017\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d<\/p>\n<p>\u7b49\u5f85ADDR\u4ece0\u53d8\u62101&#xff0c;\u53d8\u4e3a1\u540e\u5bfb\u5740\u6210\u529f&#xff0c;\u8df3\u51fa\u5faa\u73af<\/p>\n<p>\u5982\u679cAF\u4ece0\u53d8\u62101&#xff0c;\u8bf4\u660e\u672a\u6536\u5230Ack&#xff0c;\u53d1\u9001\u505c\u6b62\u4f4d&#xff0c;\u5bfb\u5740\u5931\u8d25<\/p>\n<p>\u6e05\u96f6ADDR&#xff08;\u5148\u8bfb\u53d6SR1&#xff0c;\u518d\u8bfb\u53d6SR2&#xff0c;\u5c31\u53ef\u4ee5\u81ea\u52a8\u6e05\u96f6&#xff09;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"239\" src=\"2026-01-31q0kjlgmvqey.png\" width=\"384\" \/><\/p>\n<p>SR1\u72b6\u6001\u5bc4\u5b58\u5668\u4e2d\u7684AF&#xff08;Acknowledge Failure \u5e94\u7b54\u5931\u8d25\u6807\u5fd7\u4f4d&#xff09;<\/p>\n<ul>\n<li>0&#xff08;RESET&#xff09;&#xff1a;\u6536\u5230Ack<\/li>\n<li>1&#xff08;SET&#xff09;&#xff1a;\u672a\u6536\u5230Ack<\/li>\n<\/ul>\n<p>SR1\u72b6\u6001\u5bc4\u5b58\u5668\u4e2d\u7684ADDR&#xff08;\u5bfb\u5740\u6807\u5fd7\u4f4d&#xff09;<\/p>\n<ul>\n<li>0&#xff08;RESET&#xff09;&#xff1a;\u5bfb\u5740\u5931\u8d25<\/li>\n<li>1&#xff08;SET&#xff09;&#xff1a;\u5bfb\u5740\u6210\u529f<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>\/\/#3.\u53d1\u9001\u5730\u5740<\/p>\n<p>\/*\u6e05\u9664AF\u6807\u5fd7\u4f4d*\/<br \/>\nI2C_ClearFlag(I2Cx,I2C_FLAG_AF);<br \/>\n\/*\u53d1\u90017\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d*\/<br \/>\nI2C_SendData(I2Cx,Addr &amp; 0xfe);<br \/>\nwhile(1)<br \/>\n{<br \/>\n\/*\u5224\u65ad\u5bfb\u5740\u662f\u5426\u6210\u529f*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_ADDR) &#061;&#061; SET)<br \/>\n{<br \/>\nbreak;<br \/>\n}<br \/>\n\/*\u5982\u679c\u672a\u6536\u5230Ack*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_AF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u5bfb\u5740\u5931\u8d25*\/<br \/>\nreturn -1;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/#4&#xff1a;\u6e05\u9664ADDR\u6807\u5fd7\u4f4d<\/p>\n<p>\/*\u8bfb\u53d6SR1*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR1);<br \/>\n\/*\u8bfb\u53d6SR2*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR2); <\/p>\n<p>\u6ce8&#xff1a;\u4f4e\u4f4d\u4e0e0\u8868\u793a\u5199<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"109\" src=\"2026-01-31chxml2dadal.png\" width=\"424\" \/><\/p>\n<h4 id=\"4.6.%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE\">4.6.\u53d1\u9001\u6570\u636e<\/h4>\n<p>\u5faa\u73af\u53d1\u9001\u6570\u636e<\/p>\n<p>\u901a\u8fc7AF\u6807\u5fd7\u4f4d&#xff0c;\u5224\u65ad\u4e0a\u4e00\u6b21\u53d1\u9001\u7684\u6570\u636e\u662f\u5426\u88ab\u62d2\u6536&#xff0c;\u5982\u679c\u62d2\u6536\u5219\u53d1\u9001\u505c\u6b62\u4f4d<\/p>\n<p>\u901a\u8fc7TxE\u6807\u5fd7\u4f4d&#xff0c;\u5224\u65ad\u53d1\u9001\u6570\u636e\u5bc4\u5b58\u5668\u4e2d\u662f\u5426\u6709\u503c&#xff0c;\u9632\u6b62\u9020\u6210\u6570\u636e\u4e22\u5931&#xff0c;\u5c06\u6570\u636e\u53d1\u51fa<\/p>\n<p>\u7b49\u5f85\u6570\u636e\u53d1\u9001\u5b8c\u6210<\/p>\n<p>\u901a\u8fc7AF\u6807\u5fd7\u4f4d&#xff0c;\u5224\u65ad\u4e0a\u4e00\u6b21\u53d1\u9001\u7684\u6570\u636e\u662f\u5426\u88ab\u62d2\u6536&#xff0c;\u5982\u679c\u62d2\u6536\u5219\u53d1\u9001\u505c\u6b62\u4f4d<\/p>\n<p>\u901a\u8fc7BTF\u6807\u5fd7\u4f4d&#xff0c;\u5224\u65ad\u79fb\u4f4d\u6570\u636e\u5bc4\u5b58\u5668\u548c\u53d1\u9001\u6570\u636e\u5bc4\u5b58\u5668\u662f\u5426\u90fd\u4e3a\u7a7a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"224\" src=\"2026-01-31vacr2wawktz.png\" width=\"372\" \/><\/p>\n<p>SR1\u72b6\u6001\u5bc4\u5b58\u5668\u4e2d\u7684BTF&#xff08;\u6570\u636e\u53d1\u9001\u5b8c\u6210\u6807\u5fd7\u4f4d&#xff09;<\/p>\n<ul>\n<li>0&#xff08;RESET&#xff09;&#xff1a;\u6570\u636e\u53d1\u9001\u672a\u5b8c\u6210<\/li>\n<li>1&#xff08;SET&#xff09;&#xff1a;\u6570\u636e\u53d1\u9001\u5b8c\u6210<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>\/\/#5&#xff1a;\u53d1\u9001\u6570\u636e<\/p>\n<p>\/*\u5faa\u73af\u53d1\u9001\u6570\u636e*\/<br \/>\nfor(uint16_t i &#061; 0;i &lt; Size;i&#043;&#043;)<br \/>\n{<br \/>\nwhile(1)<br \/>\n{<br \/>\n\/*\u5982\u679c\u4e0a\u4e00\u6b21\u672a\u6536\u5230Ack*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_AF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u6570\u636e\u62d2\u6536*\/<br \/>\nreturn -2;<br \/>\n}<br \/>\n\/*\u5982\u679c\u53d1\u9001\u6570\u636e\u5bc4\u5b58\u5668\u4e2d\u6709\u6570\u636e*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_TXE) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u8df3\u51fa\u5faa\u73af*\/<br \/>\nbreak;<br \/>\n}<br \/>\n}<\/p>\n<p>\/*\u6570\u636e\u53d1\u51fa*\/<br \/>\nI2C_SendData(I2Cx,pData[i]);<br \/>\n}<\/p>\n<p>\/*\u7b49\u5f85\u6570\u636e\u53d1\u9001\u5b8c\u6210*\/<br \/>\nwhile(1)<br \/>\n{<br \/>\n    \/*\u5982\u679c\u4e0a\u4e00\u6b21\u672a\u6536\u5230Ac*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_AF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u6570\u636e\u88ab\u62d2\u6536*\/<br \/>\nreturn -2;<br \/>\n}<br \/>\n\/*\u5982\u679c\u6570\u636e\u53d1\u9001\u5b8c\u6210*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_BTF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u8df3\u51fa\u5faa\u73af*\/<br \/>\nbreak;<br \/>\n}<br \/>\n} <\/p>\n<h4 id=\"4.7.%E5%8F%91%E9%80%81%E5%81%9C%E6%AD%A2%E4%BD%8D\">4.7.\u53d1\u9001\u505c\u6b62\u4f4d<\/h4>\n<p>\u53d1\u9001\u505c\u6b62\u4f4d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"218\" src=\"2026-01-31ucniy4dl0yq.png\" width=\"346\" \/><\/p>\n<p>SDA\u914d\u7f6e\u5bc4\u5b58\u5668\u4e2d\u7684STOP&#xff08;\u53d1\u9001\u505c\u6b62\u4f4d&#xff09;<\/p>\n<ul>\n<li>ENABLE&#xff1a;\u51991<\/li>\n<li>DISABLE&#xff1a;\u51990<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>\/\/#5&#xff1a;\u53d1\u9001\u505c\u6b62\u4f4d<\/p>\n<p>\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u53d1\u9001\u6210\u529f*\/<br \/>\nreturn 0; <\/p>\n<h4 id=\"4.8.%E5%90%AF%E5%8A%A8OLED\">4.8.\u542f\u52a8OLED<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"123\" src=\"2026-01-31k34cy5litlk.png\" width=\"123\" \/><\/p>\n<p>OLED\u5730\u5740\u4e3a0x78<\/p>\n<p>uint8_t commands[] &#061; {<br \/>\n0x00,\/\/\u547d\u4ee4\u6d41<br \/>\n0x8d,0x14,\/\/\u4f7f\u80fd\u7535\u8377\u6cf5<br \/>\n0xaf,\/\/\u6253\u5f00\u5c4f\u5e55\u5f00\u5173<br \/>\n0xa5\/\/\u8ba9\u5c4f\u5e55\u5168\u4eae<br \/>\n}; <\/p>\n<h4 id=\"4.9.%E6%80%BB%E4%BB%A3%E7%A0%81\">4.9.\u603b\u4ee3\u7801<\/h4>\n<p>#include &#034;stm32f10x.h&#034;<\/p>\n<p>void My_I2C_Init(void);<\/p>\n<p>int My_I2C_SendByte(I2C_TypeDef* I2Cx, uint8_t Addr,uint8_t* pData, uint16_t Size);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\nMy_I2C_Init();<\/p>\n<p>uint8_t commands[] &#061; {0x00,0x8d,0x14,0xaf,0xa5};<\/p>\n<p>My_I2C_SendByte(I2C1,0x78,commands,5);<\/p>\n<p>while(1)<br \/>\n{<\/p>\n<p>}<br \/>\n}<\/p>\n<p>void My_I2C_Init(void)<br \/>\n{<br \/>\n\/\/#1&#xff1a;\u521d\u59cb\u5316GPIO<\/p>\n<p>\/*\u5f00\u542fAFIO\u6a21\u5757\u7684\u65f6\u949f*\/<br \/>\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);<br \/>\n\/*\u4f7f\u80fdI2C1\u7684\u91cd\u6620\u5c04*\/<br \/>\nGPIO_PinRemapConfig(GPIO_Remap_I2C1,ENABLE);<br \/>\n\/*\u5f00\u542fGPIOB\u6a21\u5757\u7684\u65f6\u949f*\/<br \/>\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);<br \/>\n\/*GPIO\u7ed3\u6784\u7684\u524d\u7f6e\u58f0\u660e*\/<br \/>\nGPIO_InitTypeDef GPIO_InitStruct;<br \/>\n\/*\u9009\u62e9PB8\u548cPB9\u5f15\u811a*\/<br \/>\nGPIO_InitStruct.GPIO_Pin &#061; GPIO_Pin_8 | GPIO_Pin_9;<br \/>\n\/*\u8bbe\u7f6e\u590d\u7528\u8f93\u51fa\u5f00\u6f0f\u6a21\u5f0f*\/<br \/>\nGPIO_InitStruct.GPIO_Mode &#061; GPIO_Mode_AF_OD;<br \/>\n\/*\u6700\u5927\u8f93\u51fa\u901f\u5ea6\u5c3e2MHz*\/<br \/>\nGPIO_InitStruct.GPIO_Speed &#061; GPIO_Speed_2MHz;<br \/>\n\/*\u521d\u59cb\u5316PB8\u548cPB9\u5f15\u811a*\/<br \/>\nGPIO_Init(GPIOB,&amp;GPIO_InitStruct);<\/p>\n<p>\/\/#2&#xff1a;\u521d\u59cb\u5316I2C1\u6a21\u5757<\/p>\n<p>\/*\u5f00\u542fI2C1\u6a21\u5757\u7684\u65f6\u949f*\/<br \/>\nRCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);<br \/>\n\/*\u65bd\u52a0\u590d\u4f4d\u4fe1\u53f7*\/<br \/>\nRCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1,ENABLE);<br \/>\n\/*\u91ca\u653e\u590d\u4f4d\u4fe1\u53f7*\/<br \/>\nRCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1,DISABLE);<br \/>\n\/*I2C\u7ed3\u6784\u7684\u524d\u7f6e\u58f0\u660e*\/<br \/>\nI2C_InitTypeDef I2C_InitStruct;<br \/>\n\/*\u6ce2\u7279\u7387\u4e3a400k*\/<br \/>\nI2C_InitStruct.I2C_ClockSpeed &#061; 400000;<br \/>\n\/*\u6a21\u5f0f\u4e3a\u6807\u51c6I2C*\/<br \/>\nI2C_InitStruct.I2C_Mode &#061; I2C_Mode_I2C;<br \/>\n\/*\u5360\u7a7a\u6bd4\u4e3a2&#xff1a;1*\/<br \/>\nI2C_InitStruct.I2C_DutyCycle &#061; I2C_DutyCycle_2;<br \/>\n\/*\u521d\u59cb\u5316I2C1*\/<br \/>\nI2C_Init(I2C1,&amp;I2C_InitStruct);<br \/>\n\/*\u95ed\u5408I2C1\u603b\u5f00\u5173*\/<br \/>\nI2C_Cmd(I2C1,ENABLE);<br \/>\n}<\/p>\n<p>int My_I2C_SendByte(I2C_TypeDef* I2Cx, uint8_t Addr,uint8_t* pData, uint16_t Size)<br \/>\n{<br \/>\n\/\/#1&#xff1a;\u7b49\u5f85\u603b\u7ebf\u7a7a\u95f2<\/p>\n<p>\/*\u7b49\u5f85\u603b\u7ebf\u7a7a\u95f2*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_BUSY) &#061;&#061; SET);<\/p>\n<p>\/\/#2&#xff1a;\u53d1\u9001\u8d77\u59cb\u4f4d<\/p>\n<p>\/*\u53d1\u9001\u8d77\u59cb\u4f4d*\/<br \/>\nI2C_GenerateSTART(I2Cx,ENABLE);<br \/>\n\/*\u7b49\u5f85\u8d77\u59cb\u4f4d\u53d1\u9001\u5b8c\u6210*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_SB) &#061;&#061; RESET);<\/p>\n<p>\/\/#3.\u53d1\u9001\u5730\u5740<\/p>\n<p>\/*\u6e05\u9664AF\u6807\u5fd7\u4f4d*\/<br \/>\nI2C_ClearFlag(I2Cx,I2C_FLAG_AF);<br \/>\n\/*\u53d1\u90017\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d*\/<br \/>\nI2C_SendData(I2Cx,Addr &amp; 0xfe);<br \/>\nwhile(1)<br \/>\n{<br \/>\n\/*\u5224\u65ad\u5bfb\u5740\u662f\u5426\u6210\u529f*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_ADDR) &#061;&#061; SET)<br \/>\n{<br \/>\nbreak;<br \/>\n}<br \/>\n\/*\u5982\u679c\u672a\u6536\u5230Ack*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_AF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u5bfb\u5740\u5931\u8d25*\/<br \/>\nreturn -1;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/#4&#xff1a;\u6e05\u9664ADDR\u6807\u5fd7\u4f4d<\/p>\n<p>\/*\u8bfb\u53d6SR1*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR1);<br \/>\n\/*\u8bfb\u53d6SR2*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR2);<\/p>\n<p>\/\/#5&#xff1a;\u53d1\u9001\u6570\u636e<\/p>\n<p>\/*\u5faa\u73af\u53d1\u9001\u6570\u636e*\/<br \/>\nfor(uint16_t i &#061; 0;i &lt; Size;i&#043;&#043;)<br \/>\n{<br \/>\nwhile(1)<br \/>\n{<br \/>\n\/*\u5982\u679c\u4e0a\u4e00\u6b21\u672a\u6536\u5230Ack*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_AF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u6570\u636e\u62d2\u6536*\/<br \/>\nreturn -2;<br \/>\n}<br \/>\n\/*\u5982\u679c\u53d1\u9001\u6570\u636e\u5bc4\u5b58\u5668\u4e2d\u6709\u6570\u636e*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_TXE) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u8df3\u51fa\u5faa\u73af*\/<br \/>\nbreak;<br \/>\n}<br \/>\n}<\/p>\n<p>\/*\u6570\u636e\u53d1\u51fa*\/<br \/>\nI2C_SendData(I2Cx,pData[i]);<br \/>\n}<\/p>\n<p>\/*\u7b49\u5f85\u6570\u636e\u53d1\u9001\u5b8c\u6210*\/<br \/>\nwhile(1)<br \/>\n{<br \/>\n\/*\u5982\u679c\u4e0a\u4e00\u6b21\u672a\u6536\u5230Ac*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_AF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u6570\u636e\u88ab\u62d2\u6536*\/<br \/>\nreturn -2;<br \/>\n}<br \/>\n\/*\u5982\u679c\u6570\u636e\u53d1\u9001\u5b8c\u6210*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_BTF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u8df3\u51fa\u5faa\u73af*\/<br \/>\nbreak;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/#5&#xff1a;\u53d1\u9001\u505c\u6b62\u4f4d<\/p>\n<p>\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u53d1\u9001\u6210\u529f*\/<br \/>\nreturn 0;<br \/>\n} <\/p>\n<h3 id=\"%E4%BA%94%E3%80%81%E8%AF%BB%E6%95%B0%E6%8D%AE\">\u4e94\u3001\u8bfb\u6570\u636e<\/h3>\n<h4 id=\"5.1.%E6%8E%A5%E6%94%B6%E5%AD%97%E8%8A%82%E5%87%BD%E6%95%B0\">5.1.\u63a5\u6536\u5b57\u8282\u51fd\u6570<\/h4>\n<p>int My_I2C_ReceiveBytes(I2C_TypeDef* I2Cx,uint8_t Addr,uint8_t* pBuffer,uint16_t Size); <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<ul>\n<li>\u53c2\u65701&#xff1a;I2C\u63a5\u53e3\u540d\u79f0<\/li>\n<li>\u53c2\u65702&#xff1a;\u4ece\u673a\u5730\u5740&#xff0c;\u9760\u5de6<\/li>\n<li>\u53c2\u65703&#xff1a;\u63a5\u6536\u7f13\u51b2\u533a<\/li>\n<li>\u53c2\u65704&#xff1a;\u8981\u53d1\u9001\u7684\u6570\u636e\u7684\u6570\u91cf&#xff08;\u5355\u4f4d&#xff1a;\u5b57\u8282&#xff09;<\/li>\n<li>\u8fd4\u56de\u503c&#xff1a;0&#xff08;\u8bfb\u53d6\u6210\u529f&#xff09;-1&#xff08;\u5bfb\u5740\u5931\u8d25&#xff09;<\/li>\n<\/ul>\n<p>\u4f5c\u7528&#xff1a;\u901a\u8fc7I2C\u4ece\u4ece\u673a\u8bfb\u53d6\u82e5\u5e72\u4e2a\u5b57\u8282<\/p>\n<h4 id=\"5.2.%E6%95%B0%E6%8D%AE%E8%AF%BB%E5%8F%96%E7%9A%84%E6%B5%81%E7%A8%8B\">5.2.\u6570\u636e\u8bfb\u53d6\u7684\u6d41\u7a0b<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"66\" src=\"2026-01-31hrxeahhhccs.png\" width=\"601\" \/><\/p>\n<ul>\n<li>\u4e3b\u673a\u53d1\u9001\u8d77\u59cb\u4f4d<\/li>\n<li>\u4e3b\u673a\u53d1\u90017\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d<\/li>\n<li>\u7b49\u5f85\u4ece\u673aAck<\/li>\n<li>\u4e3b\u673a\u9010\u4e2a\u5b57\u8282\u63a5\u6536\u6570\u636e<\/li>\n<li>\u6bcf\u6b21\u63a5\u6536\u540e\u7b49\u5f85\u4e3b\u673aAck<\/li>\n<li>\u6700\u540e\u4e00\u4e2a\u5b57\u8282\u4e3b\u673aNak<\/li>\n<li>\u4e3b\u673a\u53d1\u9001\u505c\u6b62\u4f4d<\/li>\n<\/ul>\n<h4 id=\"5.3.%E5%8F%91%E9%80%81%E8%B5%B7%E5%A7%8B%E4%BD%8D%E5%92%8C%E5%9C%B0%E5%9D%80\">5.3.\u53d1\u9001\u8d77\u59cb\u4f4d\u548c\u5730\u5740<\/h4>\n<h5 id=\"5.3.1.%E5%8F%91%E9%80%81%E8%B5%B7%E5%A7%8B%E4%BD%8D\">5.3.1.\u53d1\u9001\u8d77\u59cb\u4f4d<\/h5>\n<p>\u5411SDA\u63a7\u5236\u5bc4\u5b58\u5668\u7684START\u4f4d\u51991<\/p>\n<p>\u7b49\u5f85\u8d77\u59cb\u4f4d\u53d1\u9001\u5b8c\u6210<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"180\" src=\"2026-01-31yxapdj0q2jc.png\" width=\"282\" \/><\/p>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>\/\/#1&#xff1a;\u53d1\u9001\u8d77\u59cb\u4f4d<\/p>\n<p>\/*\u53d1\u9001\u8d77\u59cb\u4f4d*\/<br \/>\nI2C_GenerateSTART(I2Cx,ENABLE);<br \/>\n\/*\u7b49\u5f85\u8d77\u59cb\u4f4d\u53d1\u9001\u5b8c\u6210*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_SB) &#061;&#061; RESET); <\/p>\n<h5 id=\"5.3.2.%E5%8F%91%E9%80%81%E5%9C%B0%E5%9D%80%2B%E8%AF%BB%E5%86%99%E4%BD%8D\">5.3.2.\u53d1\u9001\u5730\u5740&#043;\u8bfb\u5199\u4f4d<\/h5>\n<p>\u6e05\u96f6AF\u6807\u5fd7\u4f4d&#xff0c;\u53d1\u90017\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d<\/p>\n<p>\u7b49\u5f85ADDR\u4ece0\u53d8\u62101&#xff0c;\u53d8\u4e3a1\u540e\u5bfb\u5740\u6210\u529f&#xff0c;\u8df3\u51fa\u5faa\u73af<\/p>\n<p>\u5982\u679cAF\u4ece0\u53d8\u62101&#xff0c;\u8bf4\u660e\u672a\u6536\u5230Ack&#xff0c;\u53d1\u9001\u505c\u6b62\u4f4d&#xff0c;\u5bfb\u5740\u5931\u8d25<\/p>\n<p>\u6e05\u96f6ADDR&#xff08;\u5148\u8bfb\u53d6SR1&#xff0c;\u518d\u8bfb\u53d6SR2&#xff0c;\u5c31\u53ef\u4ee5\u81ea\u52a8\u6e05\u96f6&#xff09;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"243\" src=\"2026-01-31jxba0xaa2mj.png\" width=\"398\" \/><\/p>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>\/\/#2&#xff1a;\u53d1\u9001\u5730\u5740<\/p>\n<p>\/*\u6e05\u9664AF\u6807\u5fd7\u4f4d*\/<br \/>\nI2C_ClearFlag(I2Cx,I2C_FLAG_AF);<br \/>\n\/*\u53d1\u90017\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d*\/<br \/>\nI2C_SendData(I2Cx,Addr | 0x01);<br \/>\nwhile(1)<br \/>\n{<br \/>\n\/*\u5224\u65ad\u5bfb\u5740\u662f\u5426\u6210\u529f*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_ADDR) &#061;&#061; SET)<br \/>\n{<br \/>\nbreak;<br \/>\n}<br \/>\n\/*\u5982\u679c\u672a\u6536\u5230Ack*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_AF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u5bfb\u5740\u5931\u8d25*\/<br \/>\nreturn -1;<br \/>\n}<br \/>\n} <\/p>\n<p>\u6ce8&#xff1a;\u4f4e\u4f4d\u62161\u8868\u793a\u8bfb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"101\" src=\"2026-01-31jyicspc4gsr.png\" width=\"420\" \/><\/p>\n<h4 id=\"5.4.%E5%A6%82%E4%BD%95%E5%8F%91%E9%80%81ACK%E5%92%8CNAK\">5.4.\u5982\u4f55\u53d1\u9001ACK\u548cNAK<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"174\" src=\"2026-01-31ypb12r54nzm.png\" width=\"281\" \/><\/p>\n<p>SDA\u914d\u7f6e\u5bc4\u5b58\u5668\u4e2d\u7684ACK&#xff08;\u53d1\u9001\u5e94\u7b54\u4f4d&#xff09;<\/p>\n<ul>\n<li>\u53d1\u9001NAK&#xff1a;\u51990<\/li>\n<li>\u53d1\u9001ACK&#xff1a;\u51991<\/li>\n<\/ul>\n<p>\u6ce8&#xff1a;\u53ea\u4f5c\u7528\u4e8e\u6b63\u5728\u88ab\u63a5\u6536\u7684\u5b57\u8282<\/p>\n<h4 id=\"5.5.%E5%A6%82%E4%BD%95%E5%8F%91%E9%80%81%E5%81%9C%E6%AD%A2%E4%BD%8D\">5.5.\u5982\u4f55\u53d1\u9001\u505c\u6b62\u4f4d<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"207\" src=\"2026-01-313dqvykusjwu.png\" width=\"314\" \/><\/p>\n<p>\u5411SDA\u914d\u7f6e\u5bc4\u5b58\u5668\u4e2d\u7684STOP\u4f4d\u51991<\/p>\n<p>\u6ce8&#xff1a;\u4f5c\u7528\u4e8e\u5f53\u524d\u5b57\u8282\u63a5\u6536\u5b8c\u6210\u4e4b\u540e<\/p>\n<h4 id=\"5.6.Size%20%3D%201\">5.6.Size &#061; 1<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"62\" src=\"2026-01-311h5r1pbjsh5.png\" width=\"343\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"226\" src=\"2026-01-31ngmkraowdw2.png\" width=\"340\" \/><\/p>\n<p>\u4e3b\u673a\u53d1\u9001\u8d77\u59cb\u4f4d&#xff0c;7\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d&#xff0c;\u4ece\u673aAck<\/p>\n<p>\u6e05\u9664ADDR\u6807\u5fd7\u4f4d&#xff0c;\u5f00\u59cb\u63a5\u6536\u7b2c\u4e00\u4e2a\u5b57\u8282\u6570\u636e<\/p>\n<p>\u5728\u7b2c\u4e00\u4e2a\u5b57\u8282\u63a5\u6536\u5b8c\u6210\u524d\u5199\u4e3b\u673aNAK\u548c\u505c\u6b62\u4f4d<\/p>\n<p>\u7b49\u5f85\u7b2c\u4e00\u4e2a\u5b57\u8282\u6570\u636e\u5b58\u50a8\u63a5\u6536\u6570\u636e\u5bc4\u5b58\u5668&#xff08;RxNE\u6807\u5fd7\u4f4d\u4e3a1\u65f6\u6536\u5230\u6570\u636e&#xff09;&#xff0c;\u8bfb\u53d6\u6570\u636e<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"192\" src=\"2026-01-31ocuwubikey5.png\" width=\"151\" \/><\/p>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>\/\/#3&#xff1a;\u63a5\u6536\u6570\u636e<br \/>\nif(Size &#061;&#061; 1)<br \/>\n{<br \/>\n\/*\u6e05\u9664ADDR\u6807\u5fd7\u4f4d*\/<br \/>\n\/*\u8bfb\u53d6SR1*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR1);<br \/>\n\/*\u8bfb\u53d6SR2*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR2);<br \/>\n\/*ACK &#061; 0,STOP &#061; 1*\/<br \/>\nI2C_AcknowledgeConfig(I2Cx,DISABLE);<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u7b49\u5f85RxNE\u4e3a1*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_RXNE) &#061;&#061; RESET);<br \/>\n\/*\u8bfb\u53d6\u6570\u636e*\/<br \/>\npBuffer[0] &#061; I2C_ReceiveData(I2Cx);<br \/>\n} <\/p>\n<h4 id=\"5.7.Size%20%3D%202\">5.7.Size &#061; 2<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"47\" src=\"2026-01-31xj4jalrgpoh.png\" width=\"390\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"200\" src=\"2026-01-31zmc5n5jh4gp.png\" width=\"312\" \/><\/p>\n<p>\u4e3b\u673a\u53d1\u9001\u8d77\u59cb\u4f4d&#xff0c;7\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d&#xff0c;\u4ece\u673aAck<\/p>\n<p>\u6e05\u9664ADDR\u6807\u5fd7\u4f4d&#xff0c;\u5f00\u59cb\u63a5\u6536\u7b2c\u4e00\u4e2a\u5b57\u8282\u6570\u636e<\/p>\n<p>\u5728\u7b2c\u4e00\u4e2a\u5b57\u8282\u63a5\u6536\u5b8c\u6210\u524d\u5199\u4ece\u673aAck<\/p>\n<p>\u7b49\u5f85\u7b2c\u4e00\u4e2a\u5b57\u8282\u6570\u636e\u5b58\u50a8\u63a5\u6536\u6570\u636e\u5bc4\u5b58\u5668&#xff08;RxNE\u6807\u5fd7\u4f4d\u4e3a1\u65f6\u6536\u5230\u6570\u636e&#xff09;&#xff0c;\u8bfb\u53d6\u6570\u636e<\/p>\n<p>\u5728\u7b2c\u4e8c\u4e2a\u5b57\u8282\u63a5\u6536\u5b8c\u6210\u524d\u5199\u4e3b\u673aNAK\u548c\u505c\u6b62\u4f4d<\/p>\n<p>\u7b49\u5f85\u7b2c\u4e8c\u4e2a\u5b57\u8282\u6570\u636e\u5b58\u50a8\u63a5\u6536\u6570\u636e\u5bc4\u5b58\u5668&#xff08;RxNE\u6807\u5fd7\u4f4d\u4e3a1\u65f6\u6536\u5230\u6570\u636e&#xff09;&#xff0c;\u8bfb\u53d6\u6570\u636e<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"274\" src=\"2026-01-3133ki0zkx2n3.png\" width=\"166\" \/><\/p>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>else if(Size &#061;&#061; 2)<br \/>\n{<br \/>\n\/*\u6e05\u9664ADDR\u6807\u5fd7\u4f4d*\/<\/p>\n<p>\/*\u8bfb\u53d6SR1*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR1);<br \/>\n\/*\u8bfb\u53d6SR2*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR2);<br \/>\n\/*ACK &#061; 1*\/<br \/>\nI2C_AcknowledgeConfig(I2Cx,ENABLE);<br \/>\n\/*\u7b49\u5f85RxNE\u4e3a1*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_RXNE) &#061;&#061; RESET);<br \/>\n\/*\u8bfb\u53d6\u7b2c\u4e00\u4e2a\u5b57\u8282*\/<br \/>\npBuffer[0] &#061; I2C_ReceiveData(I2Cx);<br \/>\n\/*ACK &#061; 0,STOP &#061; 1*\/<br \/>\nI2C_AcknowledgeConfig(I2Cx,DISABLE);<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n    \/*\u7b49\u5f85RxNE\u4e3a1*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_RXNE) &#061;&#061; RESET);<br \/>\n\/*\u8bfb\u53d6\u7b2c\u4e8c\u4e2a\u5b57\u8282*\/<br \/>\npBuffer[1] &#061; I2C_ReceiveData(I2Cx);<br \/>\n}<\/p>\n<h4 id=\"5.8.Size%20%3E%202\">5.8.Size &gt; 2<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"46\" src=\"2026-01-31zch4mouqt0g.png\" width=\"496\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"257\" src=\"2026-01-31f3z5clbw420.png\" width=\"435\" \/><\/p>\n<p>\u4e3b\u673a\u53d1\u9001\u8d77\u59cb\u4f4d&#xff0c;7\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d&#xff0c;\u4ece\u673aAck<\/p>\n<p>\u6e05\u9664ADDR\u6807\u5fd7\u4f4d&#xff0c;\u5f00\u59cb\u63a5\u6536\u7b2c\u4e00\u4e2a\u5b57\u8282\u6570\u636e<\/p>\n<p>\u5728\u7b2c\u4e00\u4e2a\u5b57\u8282\u63a5\u6536\u5b8c\u6210\u524d\u5199\u4ece\u673aAck<\/p>\n<p>\u7b49\u5f85\u7b2c\u4e00\u4e2a\u5b57\u8282\u6570\u636e\u5b58\u50a8\u63a5\u6536\u6570\u636e\u5bc4\u5b58\u5668&#xff08;RxNE\u6807\u5fd7\u4f4d\u4e3a1\u65f6\u6536\u5230\u6570\u636e&#xff09;&#xff0c;\u8bfb\u53d6\u6570\u636e<\/p>\n<p>&#8230;&#8230;&#xff08;\u91cd\u590dN &#8211; 1\u6b21&#xff09;<\/p>\n<p>\u5728\u7b2cN\u4e2a\u5b57\u8282\u63a5\u6536\u5b8c\u6210\u524d\u5199\u4e3b\u673aNAK\u548c\u505c\u6b62\u4f4d<\/p>\n<p>\u7b49\u5f85\u7b2cN\u4e2a\u5b57\u8282\u6570\u636e\u5b58\u50a8\u63a5\u6536\u6570\u636e\u5bc4\u5b58\u5668&#xff08;RxNE\u6807\u5fd7\u4f4d\u4e3a1\u65f6\u6536\u5230\u6570\u636e&#xff09;&#xff0c;\u8bfb\u53d6\u6570\u636e<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"248\" src=\"2026-01-314rpxk1voiy5.png\" width=\"238\" \/><\/p>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>else<br \/>\n{<br \/>\n\/*\u6e05\u9664ADDR\u6807\u5fd7\u4f4d*\/<\/p>\n<p>\/*\u8bfb\u53d6SR1*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR1);<br \/>\n\/*\u8bfb\u53d6SR2*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR2);<br \/>\n\/*ACK &#061; 1*\/<br \/>\nI2C_AcknowledgeConfig(I2Cx,ENABLE);<\/p>\n<p>\/*\u8bfb\u53d6\u7b2cN\u4e2a\u5b57\u8282\u524d\u7684\u6570\u636e*\/<\/p>\n<p>for(uint16_t i &#061; 0;i &lt; Size &#8211; 1;i&#043;&#043;)<br \/>\n{<br \/>\n\/*\u7b49\u5f85RxNE\u4e3a1*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_RXNE) &#061;&#061; RESET);<br \/>\n\/*\u8bfb\u53d6\u6570\u636e*\/<br \/>\npBuffer[i] &#061; I2C_ReceiveData(I2Cx);<br \/>\n}<\/p>\n<p>\/*\u8bfb\u53d6\u7b2cN\u4e2a\u5b57\u8282\u7684\u6570\u636e*\/<\/p>\n<p>\/*ACK &#061; 0,STOP &#061; 1*\/<br \/>\nI2C_AcknowledgeConfig(I2Cx,DISABLE);<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u7b49\u5f85RxNE\u4e3a1*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_RXNE) &#061;&#061; RESET);<br \/>\n\/*\u8bfb\u53d6\u7b2cN\u4e2a\u5b57\u8282*\/<br \/>\npBuffer[Size &#8211; 1] &#061; I2C_ReceiveData(I2Cx);<br \/>\n}<\/p>\n<p>\/*\u63a5\u6536\u6210\u529f*\/<br \/>\nreturn 0 <\/p>\n<h4 id=\"5.9.%E8%AF%BB%E5%8F%96OLED\">5.9.\u8bfb\u53d6OLED<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"137\" src=\"2026-01-31xxywllasrrg.png\" width=\"127\" \/><\/p>\n<p>\u4eceOLED\u4e2d\u8bfb\u4e00\u4e2a\u5b57\u8282&#xff0c;\u4f1a\u8bfb\u51fa8\u4e2abit\u4f4d\u6570\u636e<\/p>\n<p>\u5176\u4e2d\u53ea\u6709D6\u4f4d\u6709\u6709\u6548\u6570\u636e&#xff0c;\u8868\u793a\u5c4f\u5e55\u7684\u5f00\u5173<\/p>\n<ul>\n<li>D6 &#061; 0&#xff1a;\u8868\u793a\u5c4f\u5e55\u5f00\u542f<\/li>\n<li>D6 &#061; 1&#xff1a;\u8868\u793a\u5c4f\u5e55\u5173\u95ed<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"153\" src=\"2026-01-312qt4tfc3lyh.png\" width=\"530\" \/><\/p>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>uint8_t rcvd;<\/p>\n<p>My_I2C_ReceiveBytes(I2C1,0x78,&amp;rcvd,1);<\/p>\n<p>\/*\u68c0\u6d4b\u5230\u5c4f\u5e55\u4eae*\/<br \/>\nif((rcvd &amp; (0x01&lt;&lt;6)) &#061;&#061; 0)<br \/>\n{<br \/>\nGPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_RESET);\/\/\u4eae\u706f<br \/>\n}<br \/>\nelse\/*\u68c0\u6d4b\u5230\u5c4f\u5e55\u706d*\/<br \/>\n{<br \/>\nGPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_SET);\/\/\u706d\u706f<br \/>\n} <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<p>\u5c06\u8bfb\u53d6\u5230\u7684\u503c\u5b58\u653e\u5728rcvd\u53d8\u91cf&#xff0c;\u5c06rcvd\u7684\u7b2c\u516d\u4f4d\u4e0e1&#xff0c;\u5224\u65ad\u662f0\u8fd8\u662f1<\/p>\n<ul>\n<li>\u5982\u679c\u662f0&#xff1a;Led\u4eae&#xff08;\u5c4f\u5e55\u5f00\u542f&#xff09;<\/li>\n<li>\u5982\u679c\u662f1&#xff1a;Led\u706d&#xff08;\u5c4f\u5e55\u5173\u95ed&#xff09;<\/li>\n<\/ul>\n<p>\u603b\u4ee3\u7801&#xff1a;<\/p>\n<p>#include &#034;stm32f10x.h&#034;<\/p>\n<p>void My_I2C_Init(void);<\/p>\n<p>int My_I2C_SendByte(I2C_TypeDef* I2Cx, uint8_t Addr,uint8_t* pData, uint16_t Size);<\/p>\n<p>int My_I2C_ReceiveBytes(I2C_TypeDef* I2Cx,uint8_t Addr,uint8_t* pBuffer,uint16_t Size);<\/p>\n<p>void My_OnBoardLED_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\nMy_I2C_Init();<\/p>\n<p>uint8_t commands[] &#061; {0x00,0x8d,0x14,0xaf,0xa5};<\/p>\n<p>My_I2C_SendByte(I2C1,0x78,commands,5);<\/p>\n<p>My_OnBoardLED_Init();<\/p>\n<p>uint8_t rcvd;<\/p>\n<p>My_I2C_ReceiveBytes(I2C1,0x78,&amp;rcvd,1);<\/p>\n<p>\/*\u68c0\u6d4b\u5230\u5c4f\u5e55\u4eae*\/<br \/>\nif((rcvd &amp; (0x01&lt;&lt;6)) &#061;&#061; 0)<br \/>\n{<br \/>\nGPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_RESET);\/\/\u4eae\u706f<br \/>\n}<br \/>\nelse\/*\u68c0\u6d4b\u5230\u5c4f\u5e55\u706d*\/<br \/>\n{<br \/>\nGPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_SET);\/\/\u706d\u706f<br \/>\n}<\/p>\n<p>while(1)<br \/>\n{<\/p>\n<p>}<br \/>\n}<\/p>\n<p>void My_I2C_Init(void)<br \/>\n{<br \/>\n\/\/#1&#xff1a;\u521d\u59cb\u5316GPIO<\/p>\n<p>\/*\u5f00\u542fAFIO\u6a21\u5757\u7684\u65f6\u949f*\/<br \/>\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);<br \/>\n\/*\u4f7f\u80fdI2C1\u7684\u91cd\u6620\u5c04*\/<br \/>\nGPIO_PinRemapConfig(GPIO_Remap_I2C1,ENABLE);<br \/>\n\/*\u5f00\u542fGPIOB\u6a21\u5757\u7684\u65f6\u949f*\/<br \/>\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);<br \/>\n\/*GPIO\u7ed3\u6784\u7684\u524d\u7f6e\u58f0\u660e*\/<br \/>\nGPIO_InitTypeDef GPIO_InitStruct;<br \/>\n\/*\u9009\u62e9PB8\u548cPB9\u5f15\u811a*\/<br \/>\nGPIO_InitStruct.GPIO_Pin &#061; GPIO_Pin_8 | GPIO_Pin_9;<br \/>\n\/*\u8bbe\u7f6e\u590d\u7528\u8f93\u51fa\u5f00\u6f0f\u6a21\u5f0f*\/<br \/>\nGPIO_InitStruct.GPIO_Mode &#061; GPIO_Mode_AF_OD;<br \/>\n\/*\u6700\u5927\u8f93\u51fa\u901f\u5ea6\u5c3e2MHz*\/<br \/>\nGPIO_InitStruct.GPIO_Speed &#061; GPIO_Speed_2MHz;<br \/>\n\/*\u521d\u59cb\u5316PB8\u548cPB9\u5f15\u811a*\/<br \/>\nGPIO_Init(GPIOB,&amp;GPIO_InitStruct);<\/p>\n<p>\/\/#2&#xff1a;\u521d\u59cb\u5316I2C1\u6a21\u5757<\/p>\n<p>\/*\u5f00\u542fI2C1\u6a21\u5757\u7684\u65f6\u949f*\/<br \/>\nRCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);<br \/>\n\/*\u65bd\u52a0\u590d\u4f4d\u4fe1\u53f7*\/<br \/>\nRCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1,ENABLE);<br \/>\n\/*\u91ca\u653e\u590d\u4f4d\u4fe1\u53f7*\/<br \/>\nRCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1,DISABLE);<br \/>\n\/*I2C\u7ed3\u6784\u7684\u524d\u7f6e\u58f0\u660e*\/<br \/>\nI2C_InitTypeDef I2C_InitStruct;<br \/>\n\/*\u6ce2\u7279\u7387\u4e3a400k*\/<br \/>\nI2C_InitStruct.I2C_ClockSpeed &#061; 400000;<br \/>\n\/*\u6a21\u5f0f\u4e3a\u6807\u51c6I2C*\/<br \/>\nI2C_InitStruct.I2C_Mode &#061; I2C_Mode_I2C;<br \/>\n\/*\u5360\u7a7a\u6bd4\u4e3a2&#xff1a;1*\/<br \/>\nI2C_InitStruct.I2C_DutyCycle &#061; I2C_DutyCycle_2;<br \/>\n\/*\u521d\u59cb\u5316I2C1*\/<br \/>\nI2C_Init(I2C1,&amp;I2C_InitStruct);<br \/>\n\/*\u95ed\u5408I2C1\u603b\u5f00\u5173*\/<br \/>\nI2C_Cmd(I2C1,ENABLE);<br \/>\n}<\/p>\n<p>int My_I2C_SendByte(I2C_TypeDef* I2Cx, uint8_t Addr,uint8_t* pData, uint16_t Size)<br \/>\n{<br \/>\n\/\/#1&#xff1a;\u7b49\u5f85\u603b\u7ebf\u7a7a\u95f2<\/p>\n<p>\/*\u7b49\u5f85\u603b\u7ebf\u7a7a\u95f2*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_BUSY) &#061;&#061; SET);<\/p>\n<p>\/\/#2&#xff1a;\u53d1\u9001\u8d77\u59cb\u4f4d<\/p>\n<p>\/*\u53d1\u9001\u8d77\u59cb\u4f4d*\/<br \/>\nI2C_GenerateSTART(I2Cx,ENABLE);<br \/>\n\/*\u7b49\u5f85\u8d77\u59cb\u4f4d\u53d1\u9001\u5b8c\u6210*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_SB) &#061;&#061; RESET);<\/p>\n<p>\/\/#3&#xff1a;\u53d1\u9001\u5730\u5740<\/p>\n<p>\/*\u6e05\u9664AF\u6807\u5fd7\u4f4d*\/<br \/>\nI2C_ClearFlag(I2Cx,I2C_FLAG_AF);<br \/>\n\/*\u53d1\u90017\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d*\/<br \/>\nI2C_SendData(I2Cx,Addr &amp; 0xfe);<br \/>\nwhile(1)<br \/>\n{<br \/>\n\/*\u5224\u65ad\u5bfb\u5740\u662f\u5426\u6210\u529f*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_ADDR) &#061;&#061; SET)<br \/>\n{<br \/>\nbreak;<br \/>\n}<br \/>\n\/*\u5982\u679c\u672a\u6536\u5230Ack*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_AF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u5bfb\u5740\u5931\u8d25*\/<br \/>\nreturn -1;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/#4&#xff1a;\u6e05\u9664ADDR\u6807\u5fd7\u4f4d<\/p>\n<p>\/*\u8bfb\u53d6SR1*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR1);<br \/>\n\/*\u8bfb\u53d6SR2*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR2);<\/p>\n<p>\/\/#5&#xff1a;\u53d1\u9001\u6570\u636e<\/p>\n<p>\/*\u5faa\u73af\u53d1\u9001\u6570\u636e*\/<br \/>\nfor(uint16_t i &#061; 0;i &lt; Size;i&#043;&#043;)<br \/>\n{<br \/>\nwhile(1)<br \/>\n{<br \/>\n\/*\u5982\u679c\u4e0a\u4e00\u6b21\u672a\u6536\u5230Ack*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_AF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u6570\u636e\u62d2\u6536*\/<br \/>\nreturn -2;<br \/>\n}<br \/>\n\/*\u5982\u679c\u53d1\u9001\u6570\u636e\u5bc4\u5b58\u5668\u4e2d\u6709\u6570\u636e*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_TXE) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u8df3\u51fa\u5faa\u73af*\/<br \/>\nbreak;<br \/>\n}<br \/>\n}<\/p>\n<p>\/*\u6570\u636e\u53d1\u51fa*\/<br \/>\nI2C_SendData(I2Cx,pData[i]);<br \/>\n}<\/p>\n<p>\/*\u7b49\u5f85\u6570\u636e\u53d1\u9001\u5b8c\u6210*\/<br \/>\nwhile(1)<br \/>\n{<br \/>\n\/*\u5982\u679c\u4e0a\u4e00\u6b21\u672a\u6536\u5230Ac*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_AF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u6570\u636e\u88ab\u62d2\u6536*\/<br \/>\nreturn -2;<br \/>\n}<br \/>\n\/*\u5982\u679c\u6570\u636e\u53d1\u9001\u5b8c\u6210*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_BTF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u8df3\u51fa\u5faa\u73af*\/<br \/>\nbreak;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/#5&#xff1a;\u53d1\u9001\u505c\u6b62\u4f4d<\/p>\n<p>\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u53d1\u9001\u6210\u529f*\/<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>int My_I2C_ReceiveBytes(I2C_TypeDef* I2Cx,uint8_t Addr,uint8_t* pBuffer,uint16_t Size)<br \/>\n{<br \/>\n\/\/#1&#xff1a;\u53d1\u9001\u8d77\u59cb\u4f4d<\/p>\n<p>\/*\u53d1\u9001\u8d77\u59cb\u4f4d*\/<br \/>\nI2C_GenerateSTART(I2Cx,ENABLE);<br \/>\n\/*\u7b49\u5f85\u8d77\u59cb\u4f4d\u53d1\u9001\u5b8c\u6210*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_SB) &#061;&#061; RESET);<\/p>\n<p>\/\/#2&#xff1a;\u53d1\u9001\u5730\u5740<\/p>\n<p>\/*\u6e05\u9664AF\u6807\u5fd7\u4f4d*\/<br \/>\nI2C_ClearFlag(I2Cx,I2C_FLAG_AF);<br \/>\n\/*\u53d1\u90017\u4f4d\u5730\u5740&#043;\u8bfb\u5199\u4f4d*\/<br \/>\nI2C_SendData(I2Cx,Addr | 0x01);<br \/>\nwhile(1)<br \/>\n{<br \/>\n\/*\u5224\u65ad\u5bfb\u5740\u662f\u5426\u6210\u529f*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_ADDR) &#061;&#061; SET)<br \/>\n{<br \/>\nbreak;<br \/>\n}<br \/>\n\/*\u5982\u679c\u672a\u6536\u5230Ack*\/<br \/>\nif(I2C_GetFlagStatus(I2Cx,I2C_FLAG_AF) &#061;&#061; SET)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u5bfb\u5740\u5931\u8d25*\/<br \/>\nreturn -1;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/#3&#xff1a;\u63a5\u6536\u6570\u636e<br \/>\nif(Size &#061;&#061; 1)<br \/>\n{<br \/>\n\/*\u6e05\u9664ADDR\u6807\u5fd7\u4f4d*\/<\/p>\n<p>\/*\u8bfb\u53d6SR1*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR1);<br \/>\n\/*\u8bfb\u53d6SR2*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR2);<br \/>\n\/*ACK &#061; 0,STOP &#061; 1*\/<br \/>\nI2C_AcknowledgeConfig(I2Cx,DISABLE);<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u7b49\u5f85RxNE\u4e3a1*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_RXNE) &#061;&#061; RESET);<br \/>\n\/*\u8bfb\u53d6\u6570\u636e*\/<br \/>\npBuffer[0] &#061; I2C_ReceiveData(I2Cx);<br \/>\n}<br \/>\nelse if(Size &#061;&#061; 2)<br \/>\n{<br \/>\n\/*\u6e05\u9664ADDR\u6807\u5fd7\u4f4d*\/<\/p>\n<p>\/*\u8bfb\u53d6SR1*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR1);<br \/>\n\/*\u8bfb\u53d6SR2*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR2);<br \/>\n\/*ACK &#061; 1*\/<br \/>\nI2C_AcknowledgeConfig(I2Cx,ENABLE);<br \/>\n\/*\u7b49\u5f85RxNE\u4e3a1*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_RXNE) &#061;&#061; RESET);<br \/>\n\/*\u8bfb\u53d6\u7b2c\u4e00\u4e2a\u5b57\u8282*\/<br \/>\npBuffer[0] &#061; I2C_ReceiveData(I2Cx);<br \/>\n\/*ACK &#061; 0,STOP &#061; 1*\/<br \/>\nI2C_AcknowledgeConfig(I2Cx,DISABLE);<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u7b49\u5f85RxNE\u4e3a1*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_RXNE) &#061;&#061; RESET);<br \/>\n\/*\u8bfb\u53d6\u7b2c\u4e8c\u4e2a\u5b57\u8282*\/<br \/>\npBuffer[1] &#061; I2C_ReceiveData(I2Cx);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n\/*\u6e05\u9664ADDR\u6807\u5fd7\u4f4d*\/<\/p>\n<p>\/*\u8bfb\u53d6SR1*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR1);<br \/>\n\/*\u8bfb\u53d6SR2*\/<br \/>\nI2C_ReadRegister(I2Cx,I2C_Register_SR2);<br \/>\n\/*ACK &#061; 1*\/<br \/>\nI2C_AcknowledgeConfig(I2Cx,ENABLE);<\/p>\n<p>\/*\u8bfb\u53d6\u7b2cN\u4e2a\u5b57\u8282\u524d\u7684\u6570\u636e*\/<\/p>\n<p>for(uint16_t i &#061; 0;i &lt; Size &#8211; 1;i&#043;&#043;)<br \/>\n{<br \/>\n\/*\u7b49\u5f85RxNE\u4e3a1*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_RXNE) &#061;&#061; RESET);<br \/>\n\/*\u8bfb\u53d6\u6570\u636e*\/<br \/>\npBuffer[i] &#061; I2C_ReceiveData(I2Cx);<br \/>\n}<\/p>\n<p>\/*\u8bfb\u53d6\u7b2cN\u4e2a\u5b57\u8282\u7684\u6570\u636e*\/<\/p>\n<p>\/*ACK &#061; 0,STOP &#061; 1*\/<br \/>\nI2C_AcknowledgeConfig(I2Cx,DISABLE);<br \/>\nI2C_GenerateSTOP(I2Cx,ENABLE);<br \/>\n\/*\u7b49\u5f85RxNE\u4e3a1*\/<br \/>\nwhile(I2C_GetFlagStatus(I2Cx,I2C_FLAG_RXNE) &#061;&#061; RESET);<br \/>\n\/*\u8bfb\u53d6\u7b2cN\u4e2a\u5b57\u8282*\/<br \/>\npBuffer[Size &#8211; 1] &#061; I2C_ReceiveData(I2Cx);<br \/>\n}<\/p>\n<p>\/*\u63a5\u6536\u6210\u529f*\/<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>void My_OnBoardLED_Init(void)<br \/>\n{<br \/>\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);<\/p>\n<p>GPIO_InitTypeDef GPIO_InitStruct;<\/p>\n<p>GPIO_InitStruct.GPIO_Pin &#061; GPIO_Pin_13;<br \/>\nGPIO_InitStruct.GPIO_Mode &#061; GPIO_Mode_Out_OD;<br \/>\nGPIO_InitStruct.GPIO_Speed &#061; GPIO_Speed_2MHz;<\/p>\n<p>GPIO_Init(GPIOC,&amp;GPIO_InitStruct);<br \/>\n}<\/p>\n<h3 id=\"%E5%85%AD%E3%80%81%E8%BD%AFI2C\">\u516d\u3001\u8f6fI2C<\/h3>\n<h4 id=\"6.1.%E7%A1%ACI2C%20VS%20%E8%BD%AFI2C\">6.1.\u786cI2C VS \u8f6fI2C<\/h4>\n<p>\u786c\u4ef6I2C&#xff08;\u786c\u4ef6\u6a21\u62df&#xff09;&#xff1a;\u9760\u5355\u7247\u673a\u5185\u90e8\u7684\u4e13\u7528\u7535\u8def\u81ea\u52a8\u4ea7\u751f\u6ce2\u5f62<\/p>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u89e3\u653eCPU&#xff1a;\u786c\u4ef6\u7535\u8def\u81ea\u52a8\u5904\u7406\u65f6\u5e8f&#xff0c;CPU\u53ef\u4ee5\u5904\u7406\u5176\u4ed6\u4efb\u52a1<\/li>\n<li>\u901f\u5ea6\u5feb\u4e14\u7a33\u5b9a&#xff1a;\u6676\u632f\u9a71\u52a8\u786c\u4ef6\u7535\u8def&#xff0c;\u65f6\u5e8f\u7cbe\u51c6&#xff0c;\u9002\u5408\u9ad8\u901f\u4f20\u8f93<\/li>\n<li>\u4ee3\u7801\u7b80\u6d01&#xff1a;\u4e0d\u9700\u8981\u5199\u590d\u6742\u7684\u5ef6\u65f6\u548c\u64cd\u4f5c\u4ee3\u7801&#xff0c;\u53ea\u9700\u914d\u7f6e\u597d\u5bc4\u5b58\u5668<\/li>\n<\/ul>\n<p>\u7f3a\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u5f15\u811a\u56fa\u5b9a&#xff0c;\u79fb\u690d\u6027\u5dee<\/li>\n<li>\u4ece\u673a\u6ca1\u6709Ack&#xff0c;\u4e3b\u673a\u4f1a\u5361\u6b7b<\/li>\n<li>\u9700\u5728\u5916\u90e8\u63a5\u4e0a\u62c9\u7535\u963b<\/li>\n<\/ul>\n<p>\u8f6f\u4ef6I2C&#xff08;\u8f6f\u4ef6\u6a21\u62df&#xff09;&#xff1a;\u9760CPU\u6267\u884c\u4ee3\u7801\u63a7\u5236GPIO\u5f15\u811a\u9ad8\u4f4e\u7535\u5e73\u753b\u51fa\u6ce2\u5f62<\/p>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u5f15\u811a\u968f\u610f&#xff1a;\u5982\u679cI2C\u7684\u5f15\u811a\u88ab\u5360\u7528&#xff0c;\u53ef\u4ee5\u7528\u4efb\u610fGPIO\u5f15\u811a<\/li>\n<li>\u517c\u5bb9\u6027\u597d&#xff1a;\u4e0d\u540c\u4f20\u611f\u5668\u7684I2C\u65f6\u5e8f\u6709\u5dee\u5f02&#xff0c;\u8f6fI2C\u53ef\u4ee5\u8fdb\u884c\u4fee\u6539<\/li>\n<li>\u8c03\u8bd5\u65b9\u4fbf&#xff1a;\u53ef\u4ee5\u6e05\u695a\u770b\u89c1\u6bcf\u4e2a\u7535\u5e73\u53d8\u5316<\/li>\n<\/ul>\n<p>\u7f3a\u70b9&#xff1a;<\/p>\n<ul>\n<li>CPU\u5360\u7528\u9ad8<\/li>\n<li>\u65f6\u5e8f\u7cbe\u5ea6\u4e00\u822c<\/li>\n<\/ul>\n<h4 id=\"6.2.IO%E5%BC%95%E8%84%9A%E5%88%9D%E5%A7%8B%E5%8C%96\">6.2.IO\u5f15\u811a\u521d\u59cb\u5316<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"223\" src=\"2026-01-312vfv3f5ss5i.png\" width=\"216\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"298\" src=\"2026-01-31vnv2m3n0yhr.png\" width=\"366\" \/><\/p>\n<p>\u8f6fI2C\u7684GPIO\u5f15\u811a\u7531CPU\u76f4\u63a5\u63a7\u5236&#xff0c;\u540c\u65f6\u4e3a\u4e86\u5b9e\u73b0\u786cI2C\u7684\u903b\u8f91\u7ebf\u4e0e<\/p>\n<p>\u9700\u8981\u7528\u5f00\u6f0f\u6a21\u5f0f&#xff0c;\u6240\u4ee5\u8bbe\u7f6e\u4e3a\u901a\u7528\u8f93\u51fa\u5f00\u6f0f&#xff0c;\u4e14\u521d\u59cb\u7535\u538b\u9ad8&#xff08;\u7a7a\u95f2&#xff09;<\/p>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>void My_SI2C_Init(void)<br \/>\n{<br \/>\n    \/*\u5f00\u542fGPIOA\u7684\u65f6\u949f*\/<br \/>\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);<\/p>\n<p>    \/*\u58f0\u660eGPIO\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nGPIO_InitTypeDef GPIO_InitStruct;<\/p>\n<p>    \/*\u9009\u62e9PA0\u548cPA1\u5f15\u811a*\/<br \/>\nGPIO_InitStruct.GPIO_Pin &#061; GPIO_Pin_0 | GPIO_Pin_1;<br \/>\n    \/*\u901a\u7528\u8f93\u51fa\u5f00\u6f0f\u6a21\u5f0f*\/<br \/>\nGPIO_InitStruct.GPIO_Mode &#061; GPIO_Mode_Out_OD;<br \/>\n    \/*\u6700\u5927\u8f93\u51fa\u901f\u7387\u4e3a2MHz*\/<br \/>\nGPIO_InitStruct.GPIO_Speed &#061; GPIO_Speed_2MHz;<br \/>\n    \/*\u521d\u59cb\u5316PA0\u548cPA1\u5f15\u811a*\/<br \/>\n    GPIO_Init(GPIOA,&amp;GPIO_InitStruct);<br \/>\n    \/*\u5c06\u5f15\u811a\u8bbe\u7f6e\u4f4d\u9ad8\u7535\u5e73*\/<br \/>\n    GPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_SET);<br \/>\nGPIO_WriteBit(GPIOA,GPIO_Pin_1,Bit_SET);<br \/>\n} <\/p>\n<h4 id=\"6.3.IO%E8%AF%BB%E5%86%99%E5%92%8C%E5%BB%B6%E8%BF%9F%E5%87%BD%E6%95%B0\">6.3.IO\u8bfb\u5199\u548c\u5ef6\u8fdf\u51fd\u6570<\/h4>\n<h5 id=\"6.3.1.%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A31\">6.3.1.\u7f16\u7a0b\u63a5\u53e31<\/h5>\n<p>void scl_write(uint8_t level); <\/p>\n<p>\u4f5c\u7528&#xff1a;\u5411SCL\u51990\u6216\u51991<\/p>\n<ul>\n<li>\u51990&#xff1a;\u8f93\u51fa\u4f4e\u7535\u5e73<\/li>\n<li>\u51991&#xff1a;\u8f93\u51fa\u9ad8\u7535\u5e73<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>void scl_write(uint8_t level)<br \/>\n{<br \/>\n\/*\u5411PA0\u5f15\u811a\u51990*\/<br \/>\nif(level &#061;&#061; 0)<br \/>\n{<br \/>\n\/*\u8f93\u51fa\u4f4e\u7535\u5e73&#xff0c;\u603b\u7ebf\u4e3a\u4f4e\u7535\u5e73*\/<br \/>\nGPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_RESET);<br \/>\n}<br \/>\nelse\/*\u5411PA0\u5f15\u811a\u51991*\/<br \/>\n{<br \/>\n\/*\u8f93\u51fa\u9ad8\u963b\u6001 \u603b\u7ebf\u4e3a\u9ad8\u7535\u5e73*\/<br \/>\nGPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_SET);<br \/>\n}<br \/>\n} <\/p>\n<h5 id=\"6.3.2.%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A32\">6.3.2.\u7f16\u7a0b\u63a5\u53e32<\/h5>\n<p>void sda_write(uint8_t level); <\/p>\n<p>\u4f5c\u7528&#xff1a;\u5411SDA\u51990\u6216\u51991<\/p>\n<ul>\n<li>\u51990&#xff1a;\u8f93\u51fa\u4f4e\u7535\u5e73<\/li>\n<li>\u51991&#xff1a;\u8f93\u51fa\u9ad8\u7535\u5e73<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>void sda_write(uint8_t level)<br \/>\n{<br \/>\n\/*\u5411PA1\u5f15\u811a\u51990*\/<br \/>\nif(level &#061;&#061; 0)<br \/>\n{<br \/>\n\/*\u8f93\u51fa\u4f4e\u7535\u5e73&#xff0c;\u603b\u7ebf\u4e3a\u4f4e\u7535\u5e73*\/<br \/>\nGPIO_WriteBit(GPIOA,GPIO_Pin_1,Bit_RESET);<br \/>\n}<br \/>\nelse\/*\u5411PA1\u5f15\u811a\u51991*\/<br \/>\n{<br \/>\n\/*\u8f93\u51fa\u9ad8\u963b\u6001 \u603b\u7ebf\u4e3a\u9ad8\u7535\u5e73*\/<br \/>\nGPIO_WriteBit(GPIOA,GPIO_Pin_1,Bit_SET);<br \/>\n}<br \/>\n} <\/p>\n<h5 id=\"6.3.3.%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A33\">6.3.3.\u7f16\u7a0b\u63a5\u53e33<\/h5>\n<p>uint8_t sda_read(void); <\/p>\n<p>\u4f5c\u7528&#xff1a;\u8bfb\u53d6SDA\u7684\u503c<\/p>\n<ul>\n<li>\u8fd4\u56de\u503c\u4e3a0&#xff1a;\u4f4e\u7535\u5e73<\/li>\n<li>\u8fd4\u56de\u503c\u4e3a1&#xff1a;\u9ad8\u7535\u5e73<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>uint8_t sda_read(void)<br \/>\n{<br \/>\n\/*\u5982\u679c\u8bfb\u5230PA1\u4e3a\u9ad8\u7535\u5e73*\/<br \/>\nif(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1) &#061;&#061; Bit_SET)<br \/>\n{<br \/>\n\/*\u8fd4\u56de1*\/<br \/>\nreturn 1;<br \/>\n}<br \/>\nelse\/*\u5982\u679c\u8bfb\u5230PA1\u4e3a\u4f4e\u7535\u5e73*\/<br \/>\n{<br \/>\n\/*\u8fd4\u56de0*\/<br \/>\nreturn 0;<br \/>\n}<br \/>\n} <\/p>\n<h5 id=\"6.3.4.%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A34\">6.3.4.\u7f16\u7a0b\u63a5\u53e34<\/h5>\n<p>void delay_us(uint32_t us)<br \/>\n{<br \/>\n    uint32_t n &#061; us * 8;<\/p>\n<p>    for(uint32_t i &#061; 0;i &lt; n;i&#043;&#043;);<br \/>\n} <\/p>\n<p>\u4f5c\u7528&#xff1a;\u5b9e\u73b0\u5fae\u79d2\u7ea7\u5ef6\u8fdf<\/p>\n<p>\u6ce8&#xff1a;\u6bcf\u6267\u884c\u4e00\u6b21for\u5faa\u73af\u9700\u8981\u516b\u5206\u4e4b\u4e00\u5fae\u79d2<\/p>\n<h4 id=\"6.4.%E5%8F%91%E9%80%81%E8%B5%B7%E5%A7%8B%E4%BD%8D%E5%92%8C%E5%81%9C%E6%AD%A2%E4%BD%8D\">6.4.\u53d1\u9001\u8d77\u59cb\u4f4d\u548c\u505c\u6b62\u4f4d<\/h4>\n<p>\u8d77\u59cb\u4f4d&#xff1a;\u5f53SCL\u4e3a\u9ad8\u7535\u5e73\u65f6&#xff0c;SDA\u4ea7\u751f\u4e0b\u964d\u6cbf<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"162\" src=\"2026-01-31ghuvranxbah.png\" width=\"193\" \/><\/p>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>void SendStart(void)<br \/>\n{<br \/>\nsda_write(0);<br \/>\ndelay_us(1);<br \/>\n} <\/p>\n<p>\u505c\u6b62\u4f4d&#xff1a;\u5f53SCL\u4e3a\u9ad8\u7535\u5e73\u65f6&#xff0c;SDA\u4ea7\u751f\u4e0a\u5347\u6cbf<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"135\" src=\"2026-01-31pl5zgi4daqp.png\" width=\"227\" \/><\/p>\n<p>\u6ce8&#xff1a;<\/p>\n<p>\u7531\u4e8e\u505c\u6b62\u4f4d\u524d\u7684SDA\u7535\u5e73\u9ad8\u4f4e\u4e0d\u786e\u5b9a&#xff0c;\u6b64\u65f6\u82e5SDA\u4e3a\u9ad8\u7535\u5e73\u5c31\u65e0\u6cd5\u5728\u505c\u6b62\u4f4d\u4ea7\u751f\u4e0a\u5347\u6cbf<\/p>\n<p>\u6240\u4ee5\u9700\u63d0\u524d\u62c9\u4f4eSDA&#xff0c;\u4f46\u4e3a\u4e86\u907f\u514d\u65f6\u949f\u7ebf\u8bef\u8ba4\u4e3a\u662f\u6570\u636e\u91c7\u6837&#xff0c;\u8fd8\u9700\u8981\u5728\u8fd9\u4e4b\u524d\u62c9\u4f4eSCL<\/p>\n<p>\u6240\u4ee5\u6574\u4e2a\u6d41\u7a0b\u4e3a&#xff1a;<\/p>\n<ul>\n<li>\u62c9\u4f4eSCL&#xff0c;\u62c9\u4f4eSDA&#xff0c;\u5ef6\u8fdf1us\u7ef4\u6301\u7535\u5e73\u7a33\u5b9a<\/li>\n<li>\u62c9\u9ad8SCL&#xff0c;\u51c6\u5907\u63a5\u6536SDA&#xff0c;\u5ef6\u8fdf1us\u7ef4\u6301\u7535\u5e73\u7a33\u5b9a<\/li>\n<li>\u62c9\u9ad8SDA&#xff0c;\u53d1\u9001\u505c\u6b62\u4f4d&#xff0c;\u5ef6\u8fdf1us\u7ef4\u6301\u7535\u5e73\u7a33\u5b9a<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>void SendStop(void)<br \/>\n{<br \/>\nscl_write(0);<br \/>\nsda_write(0);<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1);<br \/>\nsda_write(1);<br \/>\ndelay_us(1);<br \/>\n} <\/p>\n<h4 id=\"6.5.%E5%8F%91%E9%80%81%E4%B8%80%E4%B8%AA%E5%AD%97%E8%8A%82\">6.5.\u53d1\u9001\u4e00\u4e2a\u5b57\u8282<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"150\" src=\"2026-01-31rkwzlzi0cma.png\" width=\"246\" \/><\/p>\n<p>\u53d1\u9001\u4e00\u4e2abit\u4f4d&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"138\" src=\"2026-01-31vhqhk4k5qbq.png\" width=\"309\" \/><\/p>\n<p>\u62c9\u4f4eSCL&#xff0c;\u8ba9SDA\u51c6\u5907\u6570\u636e0\u6216\u80051<\/p>\n<p>\u5ef6\u8fdf1us\u540e&#xff0c;\u518d\u62c9\u9ad8SCL\u63a5\u6536\u6570\u636e<\/p>\n<p>\u6700\u540e\u518d\u5ef6\u8fdf1us&#xff0c;\u7ef4\u6301\u7535\u5e73\u7a33\u5b9a<\/p>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>scl_write(0);<br \/>\nsda_write(x);<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1); <\/p>\n<p>\u53d1\u9001\u5b57\u8282\u51fd\u6570&#xff1a;<\/p>\n<p>uint8_t sendByte(uint8_t byte); <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<ul>\n<li>\u53c2\u65701&#xff1a;\u8981\u53d1\u9001\u7684\u5b57\u8282<\/li>\n<li>\u8fd4\u56de\u503c&#xff1a;\u63a5\u6536\u65b9\u56de\u590d&#xff0c;0&#xff08;ACK&#xff09;1&#xff08;NAK&#xff09;<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>uint8_t sendByte(uint8_t Byte)<br \/>\n{<br \/>\nfor(int8_t i &#061; 7;i &gt;&#061; 0;i&#8211;)<br \/>\n{<br \/>\nscl_write(0);<br \/>\nif((Byte &amp; (0x01 &lt;&lt; i)) !&#061; 0)<br \/>\n{<br \/>\nsda_write(1);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nsda_write(0);<br \/>\n}<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1);<br \/>\n}<\/p>\n<p>\/\/\u8bfb\u53d6ACK\u548cNAK<br \/>\nscl_write(0);<br \/>\nsda_write(1);<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1);<br \/>\nreturn sda_read();<br \/>\n} <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<p>\u8ba1\u7b97x\u7684\u503c\u662f0\u8fd8\u662f1&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"110\" src=\"2026-01-31qgwpmj3zpkx.png\" width=\"517\" \/><\/p>\n<p>\u4eceByte\u6570\u636e\u7684\u9ad8\u4f4d\u5f00\u59cb\u9010\u4f4d\u4e0e1<\/p>\n<p>\u5982\u679c\u4e0e1\u540e\u7684\u7ed3\u679c\u662f0&#xff0c;\u8bf4\u660e\u8be5bit\u4f4d\u6570\u636e\u4e3a0&#xff0c;\u8f93\u5165\u4f4e\u7535\u5e73<\/p>\n<p>\u5982\u679c\u4e0e1\u540e\u7684\u7ed3\u679c\u4e0d\u662f0&#xff0c;\u8bf4\u660e\u8be5bit\u4e3a\u6570\u636e\u4e3a1&#xff0c;\u8f93\u5165\u9ad8\u7535\u5e73<\/p>\n<p>\u68c0\u6d4bACK\u6216NAK&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"201\" src=\"2026-01-311bhv2qcap4b.png\" width=\"246\" \/><\/p>\n<p>\u62c9\u4f4eSCL&#xff0c;\u62c9\u9ad8SDA&#xff0c;\u91ca\u653eSDA\u603b\u7ebf&#xff0c;\u5ef6\u8fdf1us\u7a33\u5b9a\u7535\u5e73<\/p>\n<p>\u5982\u679c\u662f\u63a5\u6536\u65b9ACK&#xff0c;\u63a5\u6536\u65b9\u7684\u786c\u4ef6\u7535\u8def\u81ea\u52a8\u62c9\u4f4eSDA\u5f15\u811a\u7535\u5e73<\/p>\n<p>\u5982\u679c\u662f\u63a5\u6536\u65b9NAK&#xff0c;\u63a5\u6536\u65b9\u5219\u4e0d\u4f5c\u8c03\u6574&#xff0c;\u4fdd\u6301SDA\u9ad8\u7535\u5e73<\/p>\n<p>\u6b64\u65f6\u518d\u62c9\u9ad8SCL&#xff0c;\u5ef6\u8fdf1us&#xff0c;\u8bfb\u53d6\u4f4e\u7535\u5e730&#xff08;ACK&#xff09;&#xff0c;\u8bfb\u53d6\u9ad8\u7535\u5e731&#xff08;NAK&#xff09;<\/p>\n<h4 id=\"6.6.%E6%8E%A5%E6%94%B6%E4%B8%80%E4%B8%AA%E5%AD%97%E8%8A%82\">6.6.\u63a5\u6536\u4e00\u4e2a\u5b57\u8282<\/h4>\n<p>\u63a5\u65361\u4e2abit\u4f4d&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"196\" src=\"2026-01-31z1m50wzsh3r.png\" width=\"389\" \/><\/p>\n<p>\u62c9\u4f4eSCL&#xff0c;\u62c9\u9ad8SDA&#xff0c;\u91ca\u653eSDA\u603b\u7ebf&#xff0c;\u5ef6\u8fdf1us\u7a33\u5b9a\u7535\u5e73<\/p>\n<p>\u5982\u679c\u53d1\u9001\u65b9\u53d1\u9001\u9ad8\u7535\u5e73&#xff0c;\u53d1\u9001\u65b9\u7684\u786c\u4ef6\u7535\u8def\u81ea\u52a8\u62c9\u4f4eSDA\u5f15\u811a\u7535\u5e73<\/p>\n<p>\u5982\u679c\u53d1\u9001\u65b9\u53d1\u9001\u4f4e\u7535\u5e73&#xff0c;\u53d1\u9001\u65b9\u5219\u4e0d\u4f5c\u8c03\u6574&#xff0c;\u4fdd\u6301SDA\u9ad8\u7535\u5e73<\/p>\n<p>\u6b64\u65f6\u518d\u62c9\u9ad8SCL&#xff0c;\u5ef6\u8fdf1us&#xff0c;\u8bfb\u53d6\u4f4e\u7535\u5e730&#xff0c;\u8bfb\u53d6\u9ad8\u7535\u5e731<\/p>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>scl_write(0);<br \/>\nsda_write(1);<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1);<br \/>\nbit &#061; sda_read(); <\/p>\n<p>\u63a5\u6536\u5b57\u8282\u51fd\u6570&#xff1a;<\/p>\n<p>uint8_t receiveByte(uint8_t Ack); <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<ul>\n<li>\u53c2\u65701&#xff1a;Ack\u4e3a0\u65f6\u56de\u590dNak&#xff0c;Ack\u4e3a1\u65f6\u56de\u590dAck<\/li>\n<li>\u8fd4\u56de\u503c&#xff1a;\u8bfb\u5230\u5b57\u8282\u7684\u6570\u636e<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>uint8_t receiveByte(uint8_t Ack)<br \/>\n{<br \/>\nuint8_t byte &#061; 0;<br \/>\nfor(int8_t i &#061; 7;i &gt;&#061; 0;i&#8211;)<br \/>\n{<br \/>\nscl_write(0);<br \/>\nsda_write(1);<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1);<br \/>\nif(sda_read() !&#061; 0)<br \/>\n{<br \/>\nbyte |&#061; 0x01 &lt;&lt; i;<br \/>\n}<br \/>\n    }<\/p>\n<p>\/\/\u56de\u590dACK\u6216NAK<br \/>\nscl_write(0);<br \/>\nsda_write(!Ack);<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1);<br \/>\nreturn byte;<br \/>\n} <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<p>\u8bfb\u51fabyte\u6570\u636e&#xff1a;<\/p>\n<p>\u4ecebyte\u7684\u9ad8\u4f4d\u5f00\u59cb\u9010\u4f4d\u62161<\/p>\n<ul>\n<li>\u5982\u679c\u8bfb\u53d6\u5230\u9ad8\u7535\u5e73\u5c31\u62161<\/li>\n<li>\u5982\u679c\u8bfb\u5230\u4f4e\u7535\u5e73\u5c31\u8df3\u8fc7<\/li>\n<\/ul>\n<p>\u56de\u590dACK\u6216NAK&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"189\" src=\"2026-01-31qtokjs20rsn.png\" width=\"272\" \/><\/p>\n<p>\u62c9\u4f4eSCL&#xff0c;\u63a7\u5236\u4e3b\u673a\u56de\u590d\u5e94\u7b54\u4fe1\u53f7<\/p>\n<p>\u4f20\u53c2\u4e3a1\u4ee3\u8868ACK&#xff0c;\u4f20\u53c2\u4e3a0\u4ee3\u8868NAK<\/p>\n<p>\u4f46\u5b9e\u9645\u4e0a&#xff1a;<\/p>\n<p>\u5411sda_write()\u4f201\u65f6&#xff0c;\u4e3a\u9ad8\u7535\u5e73\u4ee3\u8868NAK<\/p>\n<p>\u5411sda_write()\u4f200\u65f6&#xff0c;\u4e3a\u4f4e\u7535\u5e73\u4ee3\u8868ACK<\/p>\n<p>\u8981\u5bf9\u53c2\u6570ACK\u53d6\u53cd&#xff0c;\u624d\u80fd\u4fdd\u8bc1\u903b\u8f91\u6b63\u786e<\/p>\n<p>\u51c6\u5907\u597dSDA\u6570\u636e\u540e&#xff0c;\u5ef6\u8fdf1us\u7a33\u5b9a\u7535\u5e73<\/p>\n<p>\u6b64\u65f6\u518d\u62c9\u9ad8SCL&#xff0c;\u5ef6\u8fdf1us&#xff0c;\u8bfb\u53d6\u4f4e\u7535\u5e73ACK&#xff0c;\u8bfb\u53d6\u9ad8\u7535\u5e73NAK<\/p>\n<p>\u6ce8&#xff1a;<\/p>\n<p>\u4e0e\u4e3b\u673a\u56de\u590d\u5e94\u7b54\u4fe1\u53f7\u4e0d\u540c\u7684\u662f<\/p>\n<p>\u4ece\u673a\u56de\u590dACK\u6216NAK\u662f\u901a\u8fc7\u91ca\u653eSDA<\/p>\n<p>\u8ba9\u4ece\u673a\u7684\u786c\u4ef6\u7535\u8def\u63a7\u5236\u9009\u62e9ACK\u6216NAK<\/p>\n<p>\u800c\u4e3b\u673a\u56de\u590d\u5e94\u7b54\u4fe1\u53f7\u9700\u8981CPU\u4e3b\u52a8\u63a7\u5236&#xff08;\u51fd\u6570\u4f20\u53c2&#xff09;<\/p>\n<h4 id=\"6.7.%E7%BB%BC%E5%90%88\">6.7.\u7efc\u5408<\/h4>\n<p>\u8f6fI2C\u5199<\/p>\n<p>int My_SI2C_SendBytes(uint8_t Addr,uint8_t* pData,uint16_t Size); <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<ul>\n<li>\u53c2\u65701&#xff1a;\u4ece\u673a\u5730\u5740&#xff0c;\u9760\u5de6<\/li>\n<li>\u53c2\u65702&#xff1a;\u8981\u53d1\u9001\u7684\u6570\u636e<\/li>\n<li>\u53c2\u65703&#xff1a;\u8981\u53d1\u9001\u7684\u6570\u636e\u7684\u6570\u91cf&#xff08;\u5355\u4f4d&#xff1a;\u5b57\u8282&#xff09;<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>int My_SI2C_SendBytes(uint8_t Addr,uint8_t* pData,uint16_t Size)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u8d77\u59cb\u4f4d*\/<br \/>\nSendStart();<\/p>\n<p>\/*\u53d1\u9001\u5730\u5740&#043;\u8bfb\u5199\u4f4d*\/<\/p>\n<p>\/*\u5982\u679c\u6ca1\u6709\u63a5\u6536\u5230ACK*\/<br \/>\nif(sendByte(Addr &amp; 0xfe) !&#061; 0)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nSendStop();<br \/>\n\/*\u5bfb\u5740\u5931\u8d25*\/<br \/>\nreturn -1;<br \/>\n}<\/p>\n<p>for(uint32_t i &#061; 0;i &lt; Size;i&#043;&#043;)<br \/>\n{<br \/>\n\/*\u5982\u679c\u63a5\u6536\u65b9\u56de\u590dNAK*\/<br \/>\nif(sendByte(pData[i]) !&#061; 0)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nSendStop();<br \/>\n\/*\u6570\u636e\u88ab\u62d2\u6536*\/<br \/>\nreturn -2;<br \/>\n}<br \/>\n}<\/p>\n<p>    \/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\n    SendStop();<br \/>\n\/*\u6570\u636e\u53d1\u9001\u6210\u529f*\/<br \/>\nreturn 0;<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"69\" src=\"2026-01-31y3qluzpnmkr.png\" width=\"714\" \/><\/p>\n<p>\u8f6fI2C\u8bfb<\/p>\n<p>int My_SI2C_ReceiveBytes(uint8_t Addr,uint8_t* pBuffer,uint16_t Size); <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<ul>\n<li>\u53c2\u65701&#xff1a;\u4ece\u673a\u5730\u5740&#xff0c;\u9760\u5de6<\/li>\n<li>\u53c2\u65702&#xff1a;\u63a5\u6536\u7f13\u51b2\u533a<\/li>\n<li>\u53c2\u65703&#xff1a;\u8981\u63a5\u6536\u7684\u6570\u636e\u7684\u6570\u91cf&#xff08;\u5355\u4f4d&#xff1a;\u5b57\u8282&#xff09;<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>int My_SI2C_ReceiveBytes(uint8_t Addr,uint8_t* pBuffer,uint16_t Size)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u8d77\u59cb\u4f4d*\/<br \/>\nSendStart();<\/p>\n<p>\/*\u53d1\u9001\u5730\u5740&#043;\u8bfb\u5199\u4f4d*\/<\/p>\n<p>\/*\u5982\u679c\u6ca1\u6709\u63a5\u6536\u5230ACK*\/<br \/>\nif(sendByte(Addr | 0x01) !&#061; 0)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nSendStop();<br \/>\n\/*\u5bfb\u5740\u5931\u8d25*\/<br \/>\nreturn -1;<br \/>\n}<\/p>\n<p>\/*\u63a5\u6536\u6570\u636e*\/<br \/>\nfor(uint32_t i &#061; 0;i &lt; Size &#8211; 1;i&#043;&#043;)<br \/>\n{<br \/>\npBuffer[i] &#061; receiveByte(1);<br \/>\n}<\/p>\n<p>pBuffer[Size &#8211; 1] &#061; receiveByte(0);<\/p>\n<p>\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\n    SendStop();<br \/>\n    \/*\u6570\u636e\u63a5\u6536\u6210\u529f*\/<br \/>\nreturn 0;<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"72\" src=\"2026-01-31cchcapjkbl1.png\" width=\"729\" \/><\/p>\n<h4 id=\"6.8.%E6%B5%8B%E8%AF%95\">6.8.\u6d4b\u8bd5<\/h4>\n<p>\u603b\u4ee3\u7801\u7f16\u5199&#xff1a;<\/p>\n<p>#include &#034;stm32f10x.h&#034;<\/p>\n<p>void My_SI2C_Init(void);<br \/>\nvoid scl_write(uint8_t level);<br \/>\nvoid sda_write(uint8_t level);<br \/>\nuint8_t sda_read(void);<br \/>\nvoid delay_us(uint32_t us);<br \/>\nvoid SendStart(void);<br \/>\nvoid SendStop(void);<br \/>\nuint8_t sendByte(uint8_t Byte);<br \/>\nuint8_t receiveByte(uint8_t Ack);<br \/>\nint My_SI2C_SendBytes(uint8_t Addr,uint8_t* pData,uint16_t Size);<br \/>\nint My_SI2C_ReceiveBytes(uint8_t Addr,uint8_t* pBuffer,uint16_t Size);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\nMy_SI2C_Init();<\/p>\n<p>uint8_t commands[] &#061; {<br \/>\n0x00,\/\/\u547d\u4ee4\u6d41<br \/>\n0x8d,0x14,\/\/\u4f7f\u80fd\u7535\u8377\u6cf5<br \/>\n0xaf,\/\/\u6253\u5f00\u5c4f\u5e55\u5f00\u5173<br \/>\n0xa5,\/\/\u8ba9\u5c4f\u5e55\u5168\u4eae<br \/>\n};<\/p>\n<p>My_SI2C_SendBytes(0x78,commands,5);<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n}<\/p>\n<p>void My_SI2C_Init(void)<br \/>\n{<br \/>\n\/*\u5f00\u542fGPIOA\u7684\u65f6\u949f*\/<br \/>\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);<br \/>\n\/*\u58f0\u660eGPIO\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nGPIO_InitTypeDef GPIO_InitStruct;<br \/>\n\/*\u9009\u62e9PA0\u548cPA1\u5f15\u811a*\/<br \/>\nGPIO_InitStruct.GPIO_Pin &#061; GPIO_Pin_0 | GPIO_Pin_1;<br \/>\n\/*\u901a\u7528\u8f93\u51fa\u5f00\u6f0f\u6a21\u5f0f*\/<br \/>\nGPIO_InitStruct.GPIO_Mode &#061; GPIO_Mode_Out_OD;<br \/>\n\/*\u6700\u5927\u8f93\u51fa\u901f\u7387\u4e3a2MHz*\/<br \/>\nGPIO_InitStruct.GPIO_Speed &#061; GPIO_Speed_2MHz;<br \/>\n\/*\u521d\u59cb\u5316PA0\u548cPA1\u5f15\u811a*\/<br \/>\n  GPIO_Init(GPIOA,&amp;GPIO_InitStruct);<br \/>\n  \/*\u5c06\u5f15\u811a\u8bbe\u7f6e\u4f4d\u9ad8\u7535\u5e73*\/<br \/>\nGPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_SET);<br \/>\nGPIO_WriteBit(GPIOA,GPIO_Pin_1,Bit_SET);<br \/>\n}<\/p>\n<p>void scl_write(uint8_t level)<br \/>\n{<br \/>\n\/*\u5411PA0\u5f15\u811a\u51990*\/<br \/>\nif(level &#061;&#061; 0)<br \/>\n{<br \/>\n\/*\u8f93\u51fa\u4f4e\u7535\u5e73&#xff0c;\u603b\u7ebf\u4e3a\u4f4e\u7535\u5e73*\/<br \/>\nGPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_RESET);<br \/>\n}<br \/>\nelse\/*\u5411PA0\u5f15\u811a\u51991*\/<br \/>\n{<br \/>\n\/*\u8f93\u51fa\u9ad8\u963b\u6001 \u603b\u7ebf\u4e3a\u9ad8\u7535\u5e73*\/<br \/>\nGPIO_WriteBit(GPIOA,GPIO_Pin_0,Bit_SET);<br \/>\n}<br \/>\n}<\/p>\n<p>void sda_write(uint8_t level)<br \/>\n{<br \/>\n\/*\u5411PA1\u5f15\u811a\u51990*\/<br \/>\nif(level &#061;&#061; 0)<br \/>\n{<br \/>\n\/*\u8f93\u51fa\u4f4e\u7535\u5e73&#xff0c;\u603b\u7ebf\u4e3a\u4f4e\u7535\u5e73*\/<br \/>\nGPIO_WriteBit(GPIOA,GPIO_Pin_1,Bit_RESET);<br \/>\n}<br \/>\nelse\/*\u5411PA1\u5f15\u811a\u51991*\/<br \/>\n{<br \/>\n\/*\u8f93\u51fa\u9ad8\u963b\u6001 \u603b\u7ebf\u4e3a\u9ad8\u7535\u5e73*\/<br \/>\nGPIO_WriteBit(GPIOA,GPIO_Pin_1,Bit_SET);<br \/>\n}<br \/>\n}<\/p>\n<p>uint8_t sda_read(void)<br \/>\n{<br \/>\n\/*\u5982\u679c\u8bfb\u5230PA1\u4e3a\u9ad8\u7535\u5e73*\/<br \/>\nif(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1) &#061;&#061; Bit_SET)<br \/>\n{<br \/>\n\/*\u8fd4\u56de1*\/<br \/>\nreturn 1;<br \/>\n}<br \/>\nelse\/*\u5982\u679c\u8bfb\u5230PA1\u4e3a\u4f4e\u7535\u5e73*\/<br \/>\n{<br \/>\n\/*\u8fd4\u56de0*\/<br \/>\nreturn 0;<br \/>\n}<br \/>\n}<\/p>\n<p>void delay_us(uint32_t us)<br \/>\n{<br \/>\n    uint32_t n &#061; us * 8;<\/p>\n<p>    for(uint32_t i &#061; 0;i &lt; n;i&#043;&#043;);<br \/>\n}<\/p>\n<p>void SendStart(void)<br \/>\n{<br \/>\nsda_write(0);<br \/>\ndelay_us(1);<br \/>\n}<\/p>\n<p>void SendStop(void)<br \/>\n{<br \/>\nscl_write(0);<br \/>\nsda_write(0);<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1);<br \/>\nsda_write(1);<br \/>\ndelay_us(1);<br \/>\n}<\/p>\n<p>uint8_t sendByte(uint8_t Byte)<br \/>\n{<br \/>\nfor(int8_t i &#061; 7;i &gt;&#061; 0;i&#8211;)<br \/>\n{<br \/>\nscl_write(0);<br \/>\nif((Byte &amp; (0x01 &lt;&lt; i)) !&#061; 0)<br \/>\n{<br \/>\nsda_write(1);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nsda_write(0);<br \/>\n}<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1);<br \/>\n}<\/p>\n<p>\/\/\u8bfb\u53d6ACK\u548cNAK<br \/>\nscl_write(0);<br \/>\nsda_write(1);<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1);<br \/>\nreturn sda_read();<br \/>\n}<\/p>\n<p>uint8_t receiveByte(uint8_t Ack)<br \/>\n{<br \/>\nuint8_t byte &#061; 0;<br \/>\nfor(int8_t i &#061; 7;i &gt;&#061; 0;i&#8211;)<br \/>\n{<br \/>\nscl_write(0);<br \/>\nsda_write(1);<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1);<br \/>\nif(sda_read() !&#061; 0)<br \/>\n{<br \/>\nbyte |&#061; 0x01 &lt;&lt; i;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/\u56de\u590dACK\u6216NAK<br \/>\nscl_write(0);<br \/>\nsda_write(!Ack);<br \/>\ndelay_us(1);<br \/>\nscl_write(1);<br \/>\ndelay_us(1);<br \/>\nreturn byte;<br \/>\n}<\/p>\n<p>int My_SI2C_SendBytes(uint8_t Addr,uint8_t* pData,uint16_t Size)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u8d77\u59cb\u4f4d*\/<br \/>\nSendStart();<\/p>\n<p>\/*\u53d1\u9001\u5730\u5740&#043;\u8bfb\u5199\u4f4d*\/<\/p>\n<p>\/*\u5982\u679c\u6ca1\u6709\u63a5\u6536\u5230ACK*\/<br \/>\nif(sendByte(Addr &amp; 0xfe) !&#061; 0)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nSendStop();<br \/>\n\/*\u5bfb\u5740\u5931\u8d25*\/<br \/>\nreturn -1;<br \/>\n}<\/p>\n<p>\/*\u53d1\u9001\u6570\u636e*\/<\/p>\n<p>for(uint32_t i &#061; 0;i &lt; Size;i&#043;&#043;)<br \/>\n{<br \/>\n\/*\u5982\u679c\u63a5\u6536\u65b9\u56de\u590dNAK*\/<br \/>\nif(sendByte(pData[i]) !&#061; 0)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nSendStop();<br \/>\n\/*\u6570\u636e\u88ab\u62d2\u6536*\/<br \/>\nreturn -2;<br \/>\n}<br \/>\n}<\/p>\n<p>\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\n    SendStop();<br \/>\n\/*\u6570\u636e\u53d1\u9001\u6210\u529f*\/<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>int My_SI2C_ReceiveBytes(uint8_t Addr,uint8_t* pBuffer,uint16_t Size)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u8d77\u59cb\u4f4d*\/<br \/>\nSendStart();<\/p>\n<p>\/*\u53d1\u9001\u5730\u5740&#043;\u8bfb\u5199\u4f4d*\/<\/p>\n<p>\/*\u5982\u679c\u6ca1\u6709\u63a5\u6536\u5230ACK*\/<br \/>\nif(sendByte(Addr | 0x01) !&#061; 0)<br \/>\n{<br \/>\n\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\nSendStop();<br \/>\n\/*\u5bfb\u5740\u5931\u8d25*\/<br \/>\nreturn -1;<br \/>\n}<\/p>\n<p>\/*\u63a5\u6536\u6570\u636e*\/<br \/>\nfor(uint32_t i &#061; 0;i &lt; Size &#8211; 1;i&#043;&#043;)<br \/>\n{<br \/>\npBuffer[i] &#061; receiveByte(1);<br \/>\n}<\/p>\n<p>pBuffer[Size &#8211; 1] &#061; receiveByte(0);<\/p>\n<p>\/*\u53d1\u9001\u505c\u6b62\u4f4d*\/<br \/>\n    SendStop();<br \/>\n\/*\u6570\u636e\u63a5\u6536\u6210\u529f*\/<br \/>\nreturn 0;<br \/>\n} <\/p>\n<h3 id=\"%E4%B8%83%E3%80%81%E5%B0%81%E8%A3%85%E5%B8%B8%E7%94%A8%E5%8A%9F%E8%83%BD\">\u4e03\u3001\u5c01\u88c5\u5e38\u7528\u529f\u80fd<\/h3>\n<h4 id=\"7.1.%E6%B5%8B%E8%AF%95%E7%A1%AC%E4%BB%B6I2C\">7.1.\u6d4b\u8bd5\u786c\u4ef6I2C<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"224\" src=\"2026-01-310d15btwqp2g.png\" width=\"400\" \/><\/p>\n<h5 id=\"7.1.1.%E5%88%9D%E5%A7%8B%E5%8C%96%E7%A1%AC%E4%BB%B6I2C%E4%BB%A3%E7%A0%81\">7.1.1.\u521d\u59cb\u5316\u786c\u4ef6I2C\u4ee3\u7801<\/h5>\n<p>#include &#034;stm32f10x.h&#034;<\/p>\n<p>void My_I2C1_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<\/p>\n<p>My_I2C1_Init();<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n}<\/p>\n<p>void My_I2C1_Init(void)<br \/>\n{<br \/>\n\/\/#1&#xff1a;\u5bf9PB6\u548cPB7\u8fdb\u884c\u521d\u59cb\u5316<\/p>\n<p>\/*\u5f00\u542fGPIOB\u7684\u65f6\u949f*\/<br \/>\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);<br \/>\n\/*\u58f0\u660eGPIO\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nGPIO_InitTypeDef GPIO_InitStruct;<br \/>\n\/*\u9009\u62e9PB6\u548cPB7\u5f15\u811a*\/<br \/>\nGPIO_InitStruct.GPIO_Pin &#061; GPIO_Pin_6 | GPIO_Pin_7;<br \/>\n\/*\u590d\u7528\u8f93\u51fa\u5f00\u6f0f\u6a21\u5f0f*\/<br \/>\nGPIO_InitStruct.GPIO_Mode &#061; GPIO_Mode_AF_OD;<br \/>\n\/*\u6700\u5927\u8f93\u51fa\u901f\u7387\u4e3a2MHz*\/<br \/>\nGPIO_InitStruct.GPIO_Speed &#061; GPIO_Speed_2MHz;<br \/>\n\/*\u521d\u59cb\u5316PB6\u548cPB7\u5f15\u811a*\/<br \/>\nGPIO_Init(GPIOB,&amp;GPIO_InitStruct);<\/p>\n<p>\/\/#2&#xff1a;\u5bf9I2C1\u8fdb\u884c\u521d\u59cb\u5316<\/p>\n<p>\/*\u5f00\u542fI2C1\u7684\u65f6\u949f*\/<br \/>\nRCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);<br \/>\n\/*\u590d\u4f4dI2C1*\/<br \/>\nRCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1,ENABLE);<br \/>\nRCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1,DISABLE);<br \/>\n\/*\u58f0\u660eI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\n  I2C_InitTypeDef I2C_InitStruct;<br \/>\n\/*\u6ce2\u7279\u7387\u4e3a400k*\/<br \/>\nI2C_InitStruct.I2C_ClockSpeed &#061; 400000;<br \/>\n\/*\u6807\u51c6I2C\u6a21\u5f0f*\/<br \/>\nI2C_InitStruct.I2C_Mode &#061; I2C_Mode_I2C;<br \/>\n\/*\u5360\u7a7a\u6bd4\u4e3a2&#xff1a;1*\/<br \/>\nI2C_InitStruct.I2C_DutyCycle &#061; I2C_DutyCycle_2;<br \/>\n\/*\u521d\u59cb\u5316I2C1*\/<br \/>\nI2C_Init(I2C1,&amp;I2C_InitStruct);<br \/>\n\/*\u95ed\u5408\u603b\u5f00\u5173*\/<br \/>\nI2C_Cmd(I2C1,ENABLE);<br \/>\n} <\/p>\n<h5 id=\"7.1.2.%E7%A1%AC%E4%BB%B6I2C%E6%94%B6%E5%8F%91%E6%95%B0%E6%8D%AE%E5%87%BD%E6%95%B0\">7.1.2.\u786c\u4ef6I2C\u6536\u53d1\u6570\u636e\u51fd\u6570<\/h5>\n<p>int My_I2C_SendBytes(&#8230;)\/\/\u53d1\u9001\u5b57\u8282<br \/>\nint My_I2C_ReceiveBytes(&#8230;)\/\/\u63a5\u6536\u5b57\u8282 <\/p>\n<h5 id=\"7.1.3.%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE\">7.1.3.\u53d1\u9001\u6570\u636e<\/h5>\n<p>#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;i2c.h&#034;<\/p>\n<p>void My_I2C1_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<\/p>\n<p>My_I2C1_Init();<\/p>\n<p>uint8_t commands[] &#061; {0x00,0x8d,0x14,0xaf,0xa5};<\/p>\n<p>My_I2C_SendBytes(I2C1,0x78,commands,5);<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n} <\/p>\n<h5 id=\"7.1.4.%E6%8E%A5%E6%94%B6%E6%95%B0%E6%8D%AE\">7.1.4.\u63a5\u6536\u6570\u636e<\/h5>\n<p>\u521d\u59cb\u5316\u677f\u8f7dLED<\/p>\n<p>void My_OnBoardLED_Init(void)<br \/>\n{<br \/>\n\/*\u5f00\u542fGPIOC\u7684\u65f6\u949f*\/<br \/>\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);<br \/>\n\/*\u58f0\u660eGPIO\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nGPIO_InitTypeDef GPIO_InitStruct;<br \/>\n\/*\u9009\u62e9PC13\u5f15\u811a*\/<br \/>\nGPIO_InitStruct.GPIO_Pin &#061; GPIO_Pin_13;<br \/>\n\/*\u901a\u7528\u8f93\u51fa\u5f00\u6f0f\u6a21\u5f0f*\/<br \/>\nGPIO_InitStruct.GPIO_Mode &#061; GPIO_Mode_Out_OD;<br \/>\n\/*\u6700\u5927\u8f93\u51fa\u901f\u7387\u4e3a2MHz*\/<br \/>\nGPIO_InitStruct.GPIO_Speed &#061; GPIO_Speed_2MHz;<br \/>\n\/*\u521d\u59cb\u5316PC13\u5f15\u811a*\/<br \/>\nGPIO_Init(GPIOC,&amp;GPIO_InitStruct);<br \/>\n\/*\u9ed8\u8ba4\u7184\u706d*\/<br \/>\nGPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_SET);<br \/>\n} <\/p>\n<p>\u63a5\u6536\u6570\u636e<\/p>\n<p>#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;i2c.h&#034;<\/p>\n<p>void My_I2C1_Init(void);<\/p>\n<p>void My_OnBoardLED_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<\/p>\n<p>My_I2C1_Init();<\/p>\n<p>My_OnBoardLED_Init();<\/p>\n<p>uint8_t commands[] &#061; {0x00,0x8d,0x14,0xaf,0xa5};<\/p>\n<p>My_I2C_SendBytes(I2C1,0x78,commands,5);<\/p>\n<p>uint8_t rcvd;<\/p>\n<p>My_I2C_ReceiveBytes(I2C1,0x78,&amp;rcvd,1);<\/p>\n<p>if((rcvd &amp; (0x00 &lt;&lt; 6)) &#061;&#061; 0)<br \/>\n{<br \/>\nGPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_RESET);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nGPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_SET);<br \/>\n}<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n} <\/p>\n<h4 id=\"7.2.%E6%B5%8B%E8%AF%95%E8%BD%AF%E4%BB%B6I2C\">7.2.\u6d4b\u8bd5\u8f6f\u4ef6I2C<\/h4>\n<h5 id=\"7.2.1.%E8%BD%AF%E4%BB%B6I2C%E6%94%B6%E5%8F%91%E6%95%B0%E6%8D%AE%E5%87%BD%E6%95%B0\">7.2.1.\u8f6f\u4ef6I2C\u6536\u53d1\u6570\u636e\u51fd\u6570<\/h5>\n<p>void My_SI2C_Init(&#8230;);\/\/\u521d\u59cb\u5316\u8f6fI2C<br \/>\nint My_SI2C_SendBytes(&#8230;);\/\/\u53d1\u9001\u5b57\u8282<br \/>\nint My_SI2C_ReceiveBytes(&#8230;);\/\/\u63a5\u6536\u5b57\u8282<\/p>\n<h5 id=\"7.2.2.%E6%94%B6%E5%8F%91%E6%95%B0%E6%8D%AE%E4%BB%A3%E7%A0%81\">7.2.2.\u6536\u53d1\u6570\u636e\u4ee3\u7801<\/h5>\n<p>#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;si2c.h&#034;<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nSI2C_TypeDef si2c;<\/p>\n<p>void My_OnBoardLED_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n\/*\u914d\u7f6eSCL\u548cSDA\u5f15\u811a*\/<br \/>\nsi2c.SCL_GPIOx &#061; GPIOB;<br \/>\nsi2c.SCL_GPIO_Pin &#061; GPIO_Pin_6;<br \/>\nsi2c.SDA_GPIOx &#061; GPIOB;<br \/>\nsi2c.SDA_GPIO_Pin &#061; GPIO_Pin_7;<\/p>\n<p>\/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SI2C_Init(&amp;si2c);<\/p>\n<p>My_OnBoardLED_Init();<\/p>\n<p>uint8_t commands[] &#061; {0x00,0x8d,0x14,0xaf,0xa5};<\/p>\n<p>My_SI2C_SendBytes(&amp;si2c,0x78,commands,5);<\/p>\n<p>uint8_t rcvd;<\/p>\n<p>My_SI2C_ReceiveBytes(&amp;si2c,0x78,&amp;rcvd,1);<\/p>\n<p>if((rcvd &amp; (0x00 &lt;&lt; 6)) &#061;&#061; 0)<br \/>\n{<br \/>\nGPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_RESET);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nGPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_SET);<br \/>\n}<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n} <\/p>\n<h3 id=\"%E5%85%AB%E3%80%81OLED%E6%98%BE%E7%A4%BA%E5%99%A8\">\u516b\u3001OLED\u663e\u793a\u5668<\/h3>\n<h4 id=\"8.1.OLED%E6%98%BE%E7%A4%BA%E5%99%A8%E7%9A%84%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86\">8.1.OLED\u663e\u793a\u5668\u7684\u57fa\u672c\u539f\u7406<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"119\" src=\"2026-01-31nalo34rtsqa.png\" width=\"327\" \/><\/p>\n<p>\u901a\u8fc7I2C\u603b\u7ebf&#xff0c;\u5bf9OLED\u4e2d\u7684\u5185\u5b58\u8fdb\u884c\u8bfb\u5199<\/p>\n<p>\u5185\u5b58\u4e2d\u7684\u6bcf\u4e00\u4e2abit\u4f4d\u90fd\u4ee3\u8868\u5c4f\u5e55\u4e0a\u7684\u4e00\u4e2a\u50cf\u7d20<\/p>\n<ul>\n<li>\u51991\u70b9\u4eae<\/li>\n<li>\u51990\u7184\u706d<\/li>\n<\/ul>\n<p>\u5411\u5185\u5b58\u5199\u5165\u6570\u636e&#xff0c;\u8c03\u6574\u5185\u5b58\u5185\u5bb9&#xff0c;\u663e\u793a\u5bf9\u5e94\u56fe\u50cf<\/p>\n<h4 id=\"8.2.%E5%B1%8F%E5%B9%95%E5%88%9D%E5%A7%8B%E5%8C%96\">8.2.\u5c4f\u5e55\u521d\u59cb\u5316<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"217\" src=\"2026-01-31cu0x4cdxk2u.png\" width=\"276\" \/><\/p>\n<h5 id=\"8.2.1.%E5%88%9D%E5%A7%8B%E5%8C%96%E8%BD%AFI2C\">8.2.1.\u521d\u59cb\u5316\u8f6fI2C<\/h5>\n<p>#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;si2c.h&#034;\/\/\u5f15\u7528\u8f6fI2C\u7684\u5934\u6587\u4ef6<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nSI2C_TypeDef si2c;<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_SoftwareI2C_Init(void)<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n    \/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SoftwareI2C_Init();<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n}<\/p>\n<p>void My_SoftwareI2C_Init(void)<br \/>\n{<br \/>\n    \/*\u914d\u7f6eSCL\u548cSDA\u5f15\u811a*\/<\/p>\n<p>\/*\u6307\u5b9aSCL\u7684\u4f4d\u7f6e*\/<br \/>\nsi2c.SCL_GPIOx &#061; GPIOB;<br \/>\nsi2c.SCL_GPIO_Pin &#061; GPIO_Pin_6;<br \/>\n\/*\u6307\u5b9aSDA\u7684\u4f4d\u7f6e*\/<br \/>\nsi2c.SDA_GPIOx &#061; GPIOB;<br \/>\nsi2c.SDA_GPIO_Pin &#061; GPIO_Pin_7;<\/p>\n<p>\/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SI2C_Init(&amp;si2c);<br \/>\n} <\/p>\n<h5 id=\"8.2.2.%E5%B1%8F%E5%B9%95%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BB%A3%E7%A0%81%E7%9A%84%E7%BC%96%E5%86%99\">8.2.2.\u5c4f\u5e55\u521d\u59cb\u5316\u4ee3\u7801\u7684\u7f16\u5199<\/h5>\n<p>int OLED_Init(OLED_TypeDef* OLED,OLED_InitTypeDef* OLED_InitStruct); <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<ul>\n<li>\u53c2\u65701&#xff1a;\u6240\u4f7f\u7528\u7684OLED\u7684\u540d\u79f0<\/li>\n<li>\u53c2\u65702&#xff1a;OLED\u7684\u521d\u59cb\u5316\u53c2\u6570<\/li>\n<\/ul>\n<p>\u4f5c\u7528&#xff1a;\u5bf9OLED\u663e\u793a\u5668\u8fdb\u884c\u521d\u59cb\u5316<\/p>\n<p>\u8865\u5145&#xff1a;OLED_InitTypeDef\u7ed3\u6784&#xff08;OLED\u53c2\u6570\u83dc\u5355&#xff09;<\/p>\n<p>struct OLED_InitTypeDed<br \/>\n{<br \/>\n    int(*i2c_write_cb)(uint8_t addr,const uint8_t* pdata,uint16_t size);<br \/>\n} <\/p>\n<p>\u5206\u6790&#xff1a;<\/p>\n<p>i2c_write_cb&#xff1a;I2C\u5199\u6570\u636e\u56de\u8c03\u51fd\u6570<\/p>\n<p>#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;si2c.h&#034;\/\/\u5f15\u7528\u8f6fI2C\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;oled.h&#034;\/\/\u5f15\u7528OLED\u7684\u5934\u6587\u4ef6<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nSI2C_TypeDef si2c;<\/p>\n<p>\/*\u58f0\u660eOLED\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nOLED_TypeDef oled;<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_SoftwareI2C_Init(void);<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u5199\u5b57\u8282\u51fd\u6570*\/<br \/>\nint i2c_write_bytes(uint8_t addr,const uint8_t* pdata,uint16_t size);<\/p>\n<p>\/*\u58f0\u660eOLED\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_OLEDScreen_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n  \/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SoftwareI2C_Init();<br \/>\n\/*\u521d\u59cb\u5316OLED*\/<br \/>\nMy_OLEDScreen_Init();<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n}<\/p>\n<p>void My_SoftwareI2C_Init(void)<br \/>\n{<br \/>\n    \/*\u914d\u7f6eSCL\u548cSDA\u5f15\u811a*\/<\/p>\n<p>\/*\u6307\u5b9aSCL\u7684\u4f4d\u7f6e*\/<br \/>\nsi2c.SCL_GPIOx &#061; GPIOB;<br \/>\nsi2c.SCL_GPIO_Pin &#061; GPIO_Pin_6;<br \/>\n\/*\u6307\u5b9aSDA\u7684\u4f4d\u7f6e*\/<br \/>\nsi2c.SDA_GPIOx &#061; GPIOB;<br \/>\nsi2c.SDA_GPIO_Pin &#061; GPIO_Pin_7;<\/p>\n<p>\/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SI2C_Init(&amp;si2c);<br \/>\n}<\/p>\n<p>int i2c_write_bytes(uint8_t addr,const uint8_t* pdata,uint16_t size)<br \/>\n{<br \/>\nreturn My_SI2C_SendBytes(&amp;si2c,addr,pdata,size);<br \/>\n}<\/p>\n<p>void My_OLEDScreen_Init(void)<br \/>\n{<br \/>\n\/*\u58f0\u660eOLED\u521d\u59cb\u5316\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nOLED_InitTypeDef OLED_InitStruct;<br \/>\n\/*\u5c06\u8f6fI2C\u5199\u5b57\u8282\u51fd\u6570\u8d4b\u7ed9\u7ed3\u6784\u4e2d\u7684\u53d8\u91cf*\/<br \/>\nOLED_InitStruct.i2c_write_cb &#061; i2c_write_bytes;<br \/>\n\/*\u521d\u59cb\u5316OLED*\/<br \/>\nOLED_Init(&amp;oled,&amp;OLED_InitStruct);<br \/>\n} <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<p>\u5c01\u88c5\u5e95\u5c42\u9a71\u52a8&#xff1a;\u5c06\u8f6f\u4ef6I2C\u7684\u53d1\u9001\u51fd\u6570My_SI2C_SendBytes\u5c01\u88c5\u6210\u901a\u7528\u63a5\u53e3i2c_write_byte<\/p>\n<p>\u6ce8\u518c\u56de\u8c03\u51fd\u6570&#xff1a;\u5c06i2c_write_byte\u8d4b\u503c\u7ed9OLED\u521d\u59cb\u5316\u7ed3\u6784\u7684i2c_write_cb\u6210\u5458&#xff0c;\u5173\u8054\u9a71\u52a8\u4e0e\u5c4f\u5e55<\/p>\n<p>\u7edf\u4e00\u8c03\u7528\u5165\u53e3&#xff1a;\u5728OLED_Init\u5185\u90e8\u901a\u8fc7\u56de\u8c03\u51fd\u6570i2c_write_cb\u53d1\u8d77I2C\u901a\u4fe1&#xff0c;\u5c06\u53c2\u6570\u4f20\u7ed9\u5e95\u5c42\u53d1\u9001<\/p>\n<h4 id=\"8.3.%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5%E5%92%8C%E6%93%8D%E4%BD%9C\">8.3.\u57fa\u672c\u6982\u5ff5\u548c\u64cd\u4f5c<\/h4>\n<h5 id=\"8.3.1.%E7%94%BB%E7%AC%94%E5%92%8C%E7%94%BB%E5%88%B7\">8.3.1.\u753b\u7b14\u548c\u753b\u5237<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"234\" src=\"2026-01-313s3da14vsl0.png\" width=\"381\" \/><\/p>\n<p>\/*\u8bbe\u7f6e\u753b\u7b14*\/<br \/>\nvoid OLED_SetPen(OLED_TypeDef *OLED, uint8_t Pen_Color, uint8_t Width);<br \/>\n\/*\u8bbe\u7f6e\u753b\u5237*\/<br \/>\nvoid OLED_SetBrush(OLED_TypeDef *OLED, uint8_t Brush_Color);<\/p>\n<h5 id=\"8.3.2.%E5%B1%8F%E5%B9%95%E5%9D%90%E6%A0%87%E7%B3%BB\">8.3.2.\u5c4f\u5e55\u5750\u6807\u7cfb<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"160\" src=\"2026-01-31rtpi5u0fuxz.png\" width=\"422\" \/><\/p>\n<h5 id=\"8.3.3.%E5%85%89%E6%A0%87\">8.3.3.\u5149\u6807<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"166\" src=\"2026-01-31uk4ccnm5hc4.png\" width=\"433\" \/><\/p>\n<p>\/*\u8bbe\u7f6e\u5149\u6807\u4f4d\u7f6e*\/<br \/>\nvoid OLED_SetCursor(OLED_TypeDef *OLED, int16_t X, int16_t Y);<br \/>\n\/*\u8bbe\u7f6e\u5149\u6807\u7684X\u5750\u6807*\/<br \/>\nvoid OLED_SetCursorX(OLED_TypeDef *OLED, int16_t X);<br \/>\n\/*\u8bbe\u7f6e\u5149\u6807\u7684Y\u5750\u6807*\/<br \/>\nvoid OLED_SetCursorY(OLED_TypeDef *OLED, int16_t Y);<br \/>\n\/*\u79fb\u52a8\u5149\u6807*\/<br \/>\nvoid OLED_MoveCursor(OLED_TypeDef *OLED, int16_t dX, int16_t dY);<br \/>\n\/*\u6cbfX\u8f74\u65b9\u5411\u79fb\u52a8\u5149\u6807*\/<br \/>\nvoid OLED_MoveCursorX(OLED_TypeDef *OLED, int16_t dX);<br \/>\n\/*\u6cbfY\u8f74\u65b9\u5411\u79fb\u52a8\u5149\u6807*\/<br \/>\nvoid OLED_MoveCursorY(OLED_TypeDef *OLED, int16_t dY);<br \/>\n\/*\u83b7\u53d6\u5149\u6807\u5f53\u524d\u4f4d\u7f6e*\/<br \/>\nvoid OLED_GetCursor(OLED_TypeDef *OLED, int16_t *pXOut, int16_t *pYOut);<br \/>\n\/*\u83b7\u53d6\u5149\u6807X\u5750\u6807*\/<br \/>\nint16_t OLED_GetCursorX(OLED_TypeDef *OLED);<br \/>\n\/*\u83b7\u53d6\u5149\u6807Y\u5750\u6807*\/<br \/>\nint16_t OLED_GetCursorY(OLED_TypeDef *OLED);<\/p>\n<h4 id=\"8.4.%E6%96%87%E5%AD%97%E7%9B%B8%E5%85%B3%E7%9A%84%E6%93%8D%E4%BD%9C\">8.4.\u6587\u5b57\u76f8\u5173\u7684\u64cd\u4f5c<\/h4>\n<h5 id=\"8.4.1.%E6%89%93%E5%8D%B0%E5%AD%97%E7%AC%A6%E4%B8%B2\">8.4.1.\u6253\u5370\u5b57\u7b26\u4e32<\/h5>\n<p>int OLED_DrawString(OLED_TypeDef* OLED,const char* Str); <\/p>\n<p>\u89e3\u6790&#xff1a;<\/p>\n<ul>\n<li>\u53c2\u65701&#xff1a;\u6240\u4f7f\u7528\u7684OLED\u7684\u540d\u79f0<\/li>\n<li>\u53c2\u65702&#xff1a;\u8981\u663e\u793a\u7684\u5b57\u7b26\u4e32<\/li>\n<\/ul>\n<p>\u793a\u4f8b&#xff1a;<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n  \/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SoftwareI2C_Init();<br \/>\n\/*\u521d\u59cb\u5316OLED*\/<br \/>\nMy_OLEDScreen_Init();<\/p>\n<p>\/\/#1&#xff1a;\u6253\u5370Hello World<\/p>\n<p>\/*\u767d\u8272\u753b\u7b14*\/<br \/>\nOLED_SetPen(&amp;oled,PEN_COLOR_WHITE,1);<br \/>\n\/*\u900f\u660e\u753b\u5237*\/<br \/>\nOLED_SetBrush(&amp;oled,PEN_COLOR_TRANSPARENT);<br \/>\n\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,24,50);<br \/>\n\/*\u6253\u5370\u5b57\u7b26\u4e32*\/<br \/>\nOLED_DrawString(&amp;oled,&#034;Hello world&#034;);<br \/>\n\/*\u5c06\u6570\u636e\u53d1\u9001OLED*\/<br \/>\nOLED_SendBuffer(&amp;oled);<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n} <\/p>\n<h5 id=\"8.4.2.%E8%AE%BE%E7%BD%AE%E5%AD%97%E4%BD%93\">8.4.2.\u8bbe\u7f6e\u5b57\u4f53<\/h5>\n<p>\u793a\u4f8b&#xff1a;<\/p>\n<p>#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;si2c.h&#034;\/\/\u5f15\u7528\u8f6fI2C\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;oled.h&#034;\/\/\u5f15\u7528OLED\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;kt16.h&#034;\/\/\u5f15\u7528\u5b57\u4f53\u5934\u6587\u4ef6<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nSI2C_TypeDef si2c;<\/p>\n<p>\/*\u58f0\u660eOLED\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nOLED_TypeDef oled;<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_SoftwareI2C_Init(void);<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u5199\u5b57\u8282\u51fd\u6570*\/<br \/>\nint i2c_write_bytes(uint8_t addr,const uint8_t* pdata,uint16_t size);<\/p>\n<p>\/*\u58f0\u660eOLED\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_OLEDScreen_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n  \/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SoftwareI2C_Init();<br \/>\n\/*\u521d\u59cb\u5316OLED*\/<br \/>\nMy_OLEDScreen_Init();<\/p>\n<p>\/\/#1&#xff1a;\u6253\u5370Hello World<\/p>\n<p>\/*\u767d\u8272\u753b\u7b14*\/<br \/>\nOLED_SetPen(&amp;oled,PEN_COLOR_WHITE,1);<br \/>\n\/*\u900f\u660e\u753b\u5237*\/<br \/>\nOLED_SetBrush(&amp;oled,PEN_COLOR_TRANSPARENT);<br \/>\n\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,24,50);<br \/>\n\/*\u6253\u5370\u5b57\u7b26\u4e32*\/<br \/>\nOLED_DrawString(&amp;oled,&#034;Hello world&#034;);<\/p>\n<p>\/\/#2&#xff1a;\u6253\u5370\u4f60\u597d\u4e16\u754c<\/p>\n<p>\/*\u8bbe\u7f6e\u5b57\u4f53*\/<br \/>\nOLED_SetFont(&amp;oled,&amp;kt16);<br \/>\n\/*\u8ba1\u7b97\u6a2a\u5750\u6807*\/<br \/>\nint16_t x &#061; (OLED_GetScreenWidth(&amp;oled) &#8211; OLED_GetStrWidth(&amp;oled,&#034;\u4f60\u597d\u4e16\u754c&#034;)) \/ 2;<br \/>\n\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,x,28);<br \/>\n\/*\u6253\u5370\u5b57\u7b26\u4e32*\/<br \/>\nOLED_DrawString(&amp;oled,&#034;\u4f60\u597d\u4e16\u754c&#034;);<\/p>\n<p>\/*\u5c06\u6570\u636e\u53d1\u9001OLED*\/<br \/>\nOLED_SendBuffer(&amp;oled);<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n} <\/p>\n<h5 id=\"8.4.3.%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%89%93%E5%8D%B0%E5%AD%97%E7%AC%A6%E4%B8%B2\">8.4.3.\u683c\u5f0f\u5316\u6253\u5370\u5b57\u7b26\u4e32<\/h5>\n<p>#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;si2c.h&#034;\/\/\u5f15\u7528\u8f6fI2C\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;oled.h&#034;\/\/\u5f15\u7528OLED\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;kt16.h&#034;\/\/\u5f15\u7528\u5b57\u4f53\u5934\u6587\u4ef6<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nSI2C_TypeDef si2c;<\/p>\n<p>\/*\u58f0\u660eOLED\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nOLED_TypeDef oled;<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_SoftwareI2C_Init(void);<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u5199\u5b57\u8282\u51fd\u6570*\/<br \/>\nint i2c_write_bytes(uint8_t addr,const uint8_t* pdata,uint16_t size);<\/p>\n<p>\/*\u58f0\u660eOLED\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_OLEDScreen_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n  \/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SoftwareI2C_Init();<br \/>\n\/*\u521d\u59cb\u5316OLED*\/<br \/>\nMy_OLEDScreen_Init();<\/p>\n<p>\/\/#1&#xff1a;\u6253\u5370Hello World<\/p>\n<p>\/*\u767d\u8272\u753b\u7b14*\/<br \/>\nOLED_SetPen(&amp;oled,PEN_COLOR_WHITE,1);<br \/>\n\/*\u900f\u660e\u753b\u5237*\/<br \/>\nOLED_SetBrush(&amp;oled,PEN_COLOR_TRANSPARENT);<br \/>\n\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,24,50);<br \/>\n\/*\u6253\u5370\u5b57\u7b26\u4e32*\/<br \/>\nOLED_DrawString(&amp;oled,&#034;Hello world&#034;);<\/p>\n<p>\/\/#2&#xff1a;\u6253\u5370\u4f60\u597d\u4e16\u754c<\/p>\n<p>\/*\u8bbe\u7f6e\u5b57\u4f53*\/<br \/>\nOLED_SetFont(&amp;oled,&amp;kt16);<br \/>\n\/*\u8ba1\u7b97\u6a2a\u5750\u6807*\/<br \/>\nint16_t x &#061; (OLED_GetScreenWidth(&amp;oled) &#8211; OLED_GetStrWidth(&amp;oled,&#034;\u4f60\u597d\u4e16\u754c&#034;)) \/ 2;<br \/>\n\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,x,28);<br \/>\n\/*\u6253\u5370\u5b57\u7b26\u4e32*\/<br \/>\nOLED_DrawString(&amp;oled,&#034;\u4f60\u597d\u4e16\u754c&#034;);<\/p>\n<p>\/\/#3&#xff1a;\u683c\u5f0f\u5316\u6253\u5370\u5b57\u7b26\u4e32<\/p>\n<p>\/*\u8bbe\u7f6e\u9ed8\u8ba4\u5b57\u4f53*\/<br \/>\nOLED_SetFont(&amp;oled,&amp;default_font);<br \/>\n\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,58,64);<br \/>\n\/*\u683c\u5f0f\u5316\u5b57\u7b26\u4e32*\/<br \/>\nOLED_Printf(&amp;oled,&#034;%04d\/%02d\/%02d&#034;,2026,1,29);<br \/>\n\/*\u5c06\u6570\u636e\u53d1\u9001OLED*\/<br \/>\nOLED_SendBuffer(&amp;oled);<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n} <\/p>\n<h5 id=\"8.4.4.%E8%AE%BE%E7%BD%AE%E6%96%87%E6%9C%AC%E5%8C%BA%E5%9F%9F\">8.4.4.\u8bbe\u7f6e\u6587\u672c\u533a\u57df<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"169\" src=\"2026-01-31bjs3qb2pbhy.png\" width=\"369\" \/><\/p>\n<p>\/*\u8bbe\u7f6e\u526a\u5207\u533a\u57df*\/<br \/>\nvoid OLED_StartClipRegion(OLED_TypeDef *OLED, int16_t X, int16_t Y, uint16_t Width, uint16_t Height);<br \/>\n\/*\u505c\u6b62\u526a\u5207\u533a\u57df*\/<br \/>\nvoid OLED_StopClipRegion(OLED_TypeDef *OLED);<br \/>\n#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;si2c.h&#034;\/\/\u5f15\u7528\u8f6fI2C\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;oled.h&#034;\/\/\u5f15\u7528OLED\u7684\u5934\u6587\u4ef6<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nSI2C_TypeDef si2c;<\/p>\n<p>\/*\u58f0\u660eOLED\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nOLED_TypeDef oled;<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_SoftwareI2C_Init(void);<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u5199\u5b57\u8282\u51fd\u6570*\/<br \/>\nint i2c_write_bytes(uint8_t addr,const uint8_t* pdata,uint16_t size);<\/p>\n<p>\/*\u58f0\u660eOLED\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_OLEDScreen_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n  \/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SoftwareI2C_Init();<br \/>\n\/*\u521d\u59cb\u5316OLED*\/<br \/>\nMy_OLEDScreen_Init();<\/p>\n<p>\/\/#4:\u8bbe\u7f6e\u6587\u672c\u533a\u57df<\/p>\n<p>\/*\u8bbe\u7f6e\u526a\u5207\u533a\u57df*\/<br \/>\nOLED_StartTextRegion(&amp;oled,0,0,128,64);<br \/>\nOLED_DrawString(&amp;oled,&#034;We are in the fantasy.\\\\r\\\\n&#034;);<br \/>\nOLED_DrawString(&amp;oled,&#034;Beautiful light is always filled there.\\\\r\\\\n&#034;);<br \/>\nOLED_DrawString(&amp;oled,&#034;The life has been filled&#8230;\\\\r\\\\n&#034;);<br \/>\n\/*\u5c06\u6570\u636e\u53d1\u9001OLED*\/<br \/>\nOLED_SendBuffer(&amp;oled);<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n} <\/p>\n<h4 id=\"8.5.%E7%BB%98%E5%9B%BE%E7%9B%B8%E5%85%B3%E7%9A%84%E6%93%8D%E4%BD%9C\" style=\"background-color:transparent\">8.5.\u7ed8\u56fe\u76f8\u5173\u7684\u64cd\u4f5c<\/h4>\n<h5 id=\"8.5.1.%E7%94%BB%E7%82%B9\">8.5.1.\u753b\u70b9<\/h5>\n<p>\/*\u753b\u70b9*\/<br \/>\nvoid OLED_DrawDot(OLED_TypeDef *OLED);<br \/>\n#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;si2c.h&#034;\/\/\u5f15\u7528\u8f6fI2C\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;oled.h&#034;\/\/\u5f15\u7528OLED\u7684\u5934\u6587\u4ef6<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nSI2C_TypeDef si2c;<\/p>\n<p>\/*\u58f0\u660eOLED\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nOLED_TypeDef oled;<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_SoftwareI2C_Init(void);<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u5199\u5b57\u8282\u51fd\u6570*\/<br \/>\nint i2c_write_bytes(uint8_t addr,const uint8_t* pdata,uint16_t size);<\/p>\n<p>\/*\u58f0\u660eOLED\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_OLEDScreen_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n  \/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SoftwareI2C_Init();<br \/>\n\/*\u521d\u59cb\u5316OLED*\/<br \/>\nMy_OLEDScreen_Init();<\/p>\n<p>\/\/#5&#xff1a;\u753b\u70b9<\/p>\n<p>\/*\u767d\u8272\u753b\u7b14*\/<br \/>\nOLED_SetPen(&amp;oled,PEN_COLOR_WHITE,3);<br \/>\n\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,29,32);<br \/>\n\/*\u753b\u70b9*\/<br \/>\nOLED_DrawDot(&amp;oled);<\/p>\n<p>\/*\u753b\u5269\u4e0b\u76847\u4e2a\u70b9*\/<br \/>\nfor(uint32_t i &#061; 1;i &lt; 8;i&#043;&#043;)<br \/>\n{<br \/>\n\/*\u5149\u6807\u5de6\u79fb10\u50cf\u7d20*\/<br \/>\nOLED_MoveCursorX(&amp;oled,10);<br \/>\n\/*\u753b\u70b9*\/<br \/>\nOLED_DrawDot(&amp;oled);<br \/>\n}<br \/>\n\/*\u5c06\u6570\u636e\u53d1\u9001OLED*\/<br \/>\nOLED_SendBuffer(&amp;oled);<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n} <\/p>\n<h5 id=\"8.5.2.%E7%94%BB%E7%BA%BF\">8.5.2.\u753b\u7ebf<\/h5>\n<p>\/*\u4ece\u5149\u6807\u7684\u5f53\u524d\u4f4d\u7f6e\u5230&#xff08;x&#xff0c;y&#xff09;\u753b\u7ebf*\/<br \/>\nvoid OLED_DrawLine(OLED_TypeDef *OLED, int16_t X, int16_t Y);<br \/>\n\/*\u4ece\u5149\u6807\u7684\u5f53\u524d\u4f4d\u7f6e\u5230&#xff08;x&#xff0c;y&#xff09;\u753b\u7ebf&#xff0c;\u5e76\u628a\u5149\u6807\u79fb\u52a8\u5230&#xff08;x&#xff0c;y&#xff09;*\/<br \/>\nvoid OLED_LineTo(OLED_TypeDef *OLED, int16_t X, int16_t Y);<br \/>\n#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;si2c.h&#034;\/\/\u5f15\u7528\u8f6fI2C\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;oled.h&#034;\/\/\u5f15\u7528OLED\u7684\u5934\u6587\u4ef6<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nSI2C_TypeDef si2c;<\/p>\n<p>\/*\u58f0\u660eOLED\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nOLED_TypeDef oled;<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_SoftwareI2C_Init(void);<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u5199\u5b57\u8282\u51fd\u6570*\/<br \/>\nint i2c_write_bytes(uint8_t addr,const uint8_t* pdata,uint16_t size);<\/p>\n<p>\/*\u58f0\u660eOLED\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_OLEDScreen_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n  \/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SoftwareI2C_Init();<br \/>\n\/*\u521d\u59cb\u5316OLED*\/<br \/>\nMy_OLEDScreen_Init();<\/p>\n<p>\/\/#6&#xff1a;\u753b\u7ebf<\/p>\n<p>\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,0,0);<br \/>\n\/*\u753b\u7ebf*\/<br \/>\nOLED_DrawLine(&amp;oled,128,64);<\/p>\n<p>\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,0,64);<br \/>\n\/*\u753b\u7ebf*\/<br \/>\nOLED_DrawLine(&amp;oled,128,0);<\/p>\n<p>\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,84,22);<br \/>\n\/*\u753b\u7ebf*\/<br \/>\nOLED_LineTo(&amp;oled,44,22);<br \/>\nOLED_LineTo(&amp;oled,44,42);<br \/>\nOLED_LineTo(&amp;oled,84,42);<\/p>\n<p>\/*\u5c06\u6570\u636e\u53d1\u9001OLED*\/<br \/>\nOLED_SendBuffer(&amp;oled);<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n} <\/p>\n<h5 id=\"8.5.3.%E7%94%BB%E7%9F%A9%E5%BD%A2%E5%92%8C%E7%94%BB%E5%9C%86\">8.5.3.\u753b\u77e9\u5f62\u548c\u753b\u5706<\/h5>\n<p>\/*\u753b\u5706*\/<br \/>\nvoid OLED_DrawCircle(OLED_TypeDef *OLED, uint16_t Radius);<br \/>\n\/*\u753b\u77e9\u5f62*\/<br \/>\nvoid OLED_DrawRect(OLED_TypeDef *OLED, uint16_t Width, uint16_t Height);<br \/>\n#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;si2c.h&#034;\/\/\u5f15\u7528\u8f6fI2C\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;oled.h&#034;\/\/\u5f15\u7528OLED\u7684\u5934\u6587\u4ef6<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nSI2C_TypeDef si2c;<\/p>\n<p>\/*\u58f0\u660eOLED\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nOLED_TypeDef oled;<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_SoftwareI2C_Init(void);<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u5199\u5b57\u8282\u51fd\u6570*\/<br \/>\nint i2c_write_bytes(uint8_t addr,const uint8_t* pdata,uint16_t size);<\/p>\n<p>\/*\u58f0\u660eOLED\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_OLEDScreen_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n  \/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SoftwareI2C_Init();<br \/>\n\/*\u521d\u59cb\u5316OLED*\/<br \/>\nMy_OLEDScreen_Init();<\/p>\n<p>\/\/#7&#xff1a;\u753b\u77e9\u5f62\u548c\u5706<\/p>\n<p>\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,20,20);<br \/>\n\/*\u767d\u8272\u753b\u7b14*\/<br \/>\nOLED_SetPen(&amp;oled,PEN_COLOR_WHITE,1);<br \/>\n\/*\u900f\u660e\u753b\u5237*\/<br \/>\nOLED_SetBrush(&amp;oled,BRUSH_TRANSPARENT);<br \/>\n\/*\u753b\u77e9\u5f62*\/<br \/>\nOLED_DrawRect(&amp;oled,40,20);<\/p>\n<p>\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,65,30);<br \/>\n\/*\u753b\u5706\u5f62*\/<br \/>\nOLED_DrawCircle(&amp;oled,5);<\/p>\n<p>\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,70,20);<br \/>\n\/*\u900f\u660e\u753b\u7b14*\/<br \/>\nOLED_SetPen(&amp;oled,PEN_COLOR_TRANSPARENT,1);<br \/>\n\/*\u900f\u660e\u753b\u5237*\/<br \/>\nOLED_SetBrush(&amp;oled,BRUSH_WHITE);<br \/>\n\/*\u753b\u77e9\u5f62*\/<br \/>\nOLED_DrawRect(&amp;oled,40,20);<\/p>\n<p>\/*\u5c06\u6570\u636e\u53d1\u9001OLED*\/<br \/>\nOLED_SendBuffer(&amp;oled);<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n} <\/p>\n<h5 id=\"8.5.4.%E7%BB%98%E5%88%B6%E4%BD%8D%E5%9B%BE\">8.5.4.\u7ed8\u5236\u4f4d\u56fe<\/h5>\n<p>\/*\u753b\u4f4d\u56fe*\/<br \/>\nvoid OLED_DrawBitmap(OLED_TypeDef *OLED, uint16_t Width, uint16_t Height, const uint8_t *pBitmap); <\/p>\n<p>\u56fe\u7247\u8f6c\u6362\u7f51\u5740&#xff1a;https:\/\/javl.github.io\/image2cpp\/<\/p>\n<p>\u56fe\u50cf\u53c2\u6570\u8bbe\u7f6e<\/p>\n<p>\u6ee1\u5c4f\u4e3a&#xff1a;128 * 64<\/p>\n<p>\u7f29\u653e\u6a21\u5f0f\u4e3a&#xff1a;stretch to fill canvas<\/p>\n<p>\u8f93\u51fa\u683c\u5f0f\u4e3a&#xff1a;Plain bytes<\/p>\n<p>\u751f\u6210\u4ee3\u7801<\/p>\n<p>#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;si2c.h&#034;\/\/\u5f15\u7528\u8f6fI2C\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;oled.h&#034;\/\/\u5f15\u7528OLED\u7684\u5934\u6587\u4ef6<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nSI2C_TypeDef si2c;<\/p>\n<p>\/*\u58f0\u660eOLED\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nOLED_TypeDef oled;<\/p>\n<p>\/*\u58f0\u660e\u4f4d\u56fe\u6570\u636e\u53d8\u91cf*\/<br \/>\nuint8_t bitmap[] &#061; {};<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_SoftwareI2C_Init(void);<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u5199\u5b57\u8282\u51fd\u6570*\/<br \/>\nint i2c_write_bytes(uint8_t addr,const uint8_t* pdata,uint16_t size);<\/p>\n<p>\/*\u58f0\u660eOLED\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_OLEDScreen_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n  \/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SoftwareI2C_Init();<br \/>\n\/*\u521d\u59cb\u5316OLED*\/<br \/>\nMy_OLEDScreen_Init();<\/p>\n<p>\/\/#8&#xff1a;\u7ed8\u5236\u4f4d\u56fe<\/p>\n<p>\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,0,0);<br \/>\n\/*\u7ed8\u56fe*\/<br \/>\nOLED_DrawBitmap(&amp;oled,128,64,bitmap);<\/p>\n<p>\/*\u5c06\u6570\u636e\u53d1\u9001OLED*\/<br \/>\nOLED_SendBuffer(&amp;oled);<\/p>\n<p>while(1)<br \/>\n{<br \/>\n}<br \/>\n} <\/p>\n<p>\u7ed8\u5236\u52a8\u56fe&#xff1a;<\/p>\n<p>#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;si2c.h&#034;\/\/\u5f15\u7528\u8f6fI2C\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;oled.h&#034;\/\/\u5f15\u7528OLED\u7684\u5934\u6587\u4ef6<br \/>\n#include &#034;delay.h&#034;<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nSI2C_TypeDef si2c;<\/p>\n<p>\/*\u58f0\u660eOLED\u7ed3\u6784\u53d8\u91cf*\/<br \/>\nOLED_TypeDef oled;<\/p>\n<p>\/*\u58f0\u660e\u4f4d\u56fe\u6570\u636e\u53d8\u91cf*\/<br \/>\nuint8_t bitmap[] &#061; {};<br \/>\nconst uint8_t bitmapFlip[] &#061; {};<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_SoftwareI2C_Init(void);<\/p>\n<p>\/*\u58f0\u660e\u8f6fI2C\u5199\u5b57\u8282\u51fd\u6570*\/<br \/>\nint i2c_write_bytes(uint8_t addr,const uint8_t* pdata,uint16_t size);<\/p>\n<p>\/*\u58f0\u660eOLED\u521d\u59cb\u5316\u51fd\u6570*\/<br \/>\nvoid My_OLEDScreen_Init(void);<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n    \/*\u521d\u59cb\u5316\u8f6fI2C*\/<br \/>\nMy_SoftwareI2C_Init();<br \/>\n\/*\u521d\u59cb\u5316OLED*\/<br \/>\nMy_OLEDScreen_Init();<\/p>\n<p>\/\/#8&#xff1a;\u7ed8\u5236\u52a8\u56fe<\/p>\n<p>while(1)<br \/>\n{<br \/>\n\/*\u6e05\u5c4f*\/<br \/>\nOLED_Clear(&amp;oled)<br \/>\n\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,0,0);<br \/>\n\/*\u7ed8\u56fe*\/<br \/>\n    OLED_DrawBitmap(&amp;oled,128,64,bitmap);<br \/>\n\/*\u5c06\u6570\u636e\u53d1\u9001OLED*\/<br \/>\n    OLED_SendBuffer(&amp;oled);<\/p>\n<p>Delay(500);<\/p>\n<p>\/*\u6e05\u5c4f*\/<br \/>\nOLED_Clear(&amp;oled)<br \/>\n\/*\u8bbe\u7f6e\u5149\u6807*\/<br \/>\nOLED_SetCursor(&amp;oled,0,0);<br \/>\n\/*\u7ed8\u56fe*\/<br \/>\n    OLED_DrawBitmap(&amp;oled,128,64,bitmap);<br \/>\n\/*\u5c06\u6570\u636e\u53d1\u9001OLED*\/<br \/>\n    OLED_SendBuffer(&amp;oled);<\/p>\n<p>Delay(500);<br \/>\n}<br \/>\n} <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I2C<br \/>\n\u76ee\u5f55<br \/>\nI2C<br \/>\n\u4e00\u3001\u57fa\u672c\u7535\u8def\u7ed3\u6784<br \/>\n1.1.\u4e32\u53e3\u7684\u7f3a\u70b9<br \/>\n1.2.I2C\u603b\u7ebf\u7684\u7535\u8def\u7ed3\u6784<br \/>\n1.3.\u6570\u636e\u7ebf\u548c\u65f6\u949f\u7ebf<br \/>\n1.4.\u903b\u8f91\u7ebf\u4e0e<br \/>\n1.4.1.\u903b\u8f91\u4e0e<br \/>\n1.4.2.\u903b\u8f91\u7ebf\u4e0e<br \/>\n1.5.\u4e3b\u673a\u5982\u4f55\u53d1\u9001\u65f6\u949f\u4fe1\u53f7<br \/>\n1.6.\u4e3b\u673a\u5982\u4f55\u53d1\u9001\u6570\u636e<br \/>\n1.7.\u4ece\u673a\u5982\u4f55\u53d1\u9001\u6570\u636e<br \/>\n1.8.\u4e3a\u4f55\u4e0a\u62c9&#xff1f;\u4e3a\u4f55\u5f00\u6f0f&#xff1f;<br \/>\n\u4e8c\u3001\u901a\u4fe1\u534f\u8bae<br \/>\n2.1.I2C\u901a\u4fe1\u7684\u57fa\u672c\u6d41\u7a0b<br \/>\n\u200b\u7f16\u8f91<br \/>\n2.2.I2C\u7684\u6570\u636e\u5e27\u683c\u5f0f<br \/>\n2.3.\u8d77\u59cb\u4f4d\u548c\u505c\u6b62\u4f4d<br \/>\n2.3.1.\u8d77\u59cb\u4f4d<br \/>\n2<\/p>\n","protected":false},"author":2,"featured_media":69114,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[217,270,305],"topic":[],"class_list":["post-69134","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-stm32","tag-270","tag-305"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>STM32\u7b14\u8bb0\u5f52\u7eb34\uff1aI2C - \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\/69134.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"STM32\u7b14\u8bb0\u5f52\u7eb34\uff1aI2C - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"I2C \u76ee\u5f55 I2C \u4e00\u3001\u57fa\u672c\u7535\u8def\u7ed3\u6784 1.1.\u4e32\u53e3\u7684\u7f3a\u70b9 1.2.I2C\u603b\u7ebf\u7684\u7535\u8def\u7ed3\u6784 1.3.\u6570\u636e\u7ebf\u548c\u65f6\u949f\u7ebf 1.4.\u903b\u8f91\u7ebf\u4e0e 1.4.1.\u903b\u8f91\u4e0e 1.4.2.\u903b\u8f91\u7ebf\u4e0e 1.5.\u4e3b\u673a\u5982\u4f55\u53d1\u9001\u65f6\u949f\u4fe1\u53f7 1.6.\u4e3b\u673a\u5982\u4f55\u53d1\u9001\u6570\u636e 1.7.\u4ece\u673a\u5982\u4f55\u53d1\u9001\u6570\u636e 1.8.\u4e3a\u4f55\u4e0a\u62c9&#xff1f;\u4e3a\u4f55\u5f00\u6f0f&#xff1f; \u4e8c\u3001\u901a\u4fe1\u534f\u8bae 2.1.I2C\u901a\u4fe1\u7684\u57fa\u672c\u6d41\u7a0b \u200b\u7f16\u8f91 2.2.I2C\u7684\u6570\u636e\u5e27\u683c\u5f0f 2.3.\u8d77\u59cb\u4f4d\u548c\u505c\u6b62\u4f4d 2.3.1.\u8d77\u59cb\u4f4d 2\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/69134.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-30T21:57:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215747-697d295b1bfb6.png\" \/>\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=\"33 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69134.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/69134.html\",\"name\":\"STM32\u7b14\u8bb0\u5f52\u7eb34\uff1aI2C - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-30T21:57:50+00:00\",\"dateModified\":\"2026-01-30T21:57:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/69134.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/69134.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69134.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"STM32\u7b14\u8bb0\u5f52\u7eb34\uff1aI2C\"}]},{\"@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\u7b14\u8bb0\u5f52\u7eb34\uff1aI2C - \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\/69134.html","og_locale":"zh_CN","og_type":"article","og_title":"STM32\u7b14\u8bb0\u5f52\u7eb34\uff1aI2C - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"I2C \u76ee\u5f55 I2C \u4e00\u3001\u57fa\u672c\u7535\u8def\u7ed3\u6784 1.1.\u4e32\u53e3\u7684\u7f3a\u70b9 1.2.I2C\u603b\u7ebf\u7684\u7535\u8def\u7ed3\u6784 1.3.\u6570\u636e\u7ebf\u548c\u65f6\u949f\u7ebf 1.4.\u903b\u8f91\u7ebf\u4e0e 1.4.1.\u903b\u8f91\u4e0e 1.4.2.\u903b\u8f91\u7ebf\u4e0e 1.5.\u4e3b\u673a\u5982\u4f55\u53d1\u9001\u65f6\u949f\u4fe1\u53f7 1.6.\u4e3b\u673a\u5982\u4f55\u53d1\u9001\u6570\u636e 1.7.\u4ece\u673a\u5982\u4f55\u53d1\u9001\u6570\u636e 1.8.\u4e3a\u4f55\u4e0a\u62c9&#xff1f;\u4e3a\u4f55\u5f00\u6f0f&#xff1f; \u4e8c\u3001\u901a\u4fe1\u534f\u8bae 2.1.I2C\u901a\u4fe1\u7684\u57fa\u672c\u6d41\u7a0b \u200b\u7f16\u8f91 2.2.I2C\u7684\u6570\u636e\u5e27\u683c\u5f0f 2.3.\u8d77\u59cb\u4f4d\u548c\u505c\u6b62\u4f4d 2.3.1.\u8d77\u59cb\u4f4d 2","og_url":"https:\/\/www.wsisp.com\/helps\/69134.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-30T21:57:50+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130215747-697d295b1bfb6.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"33 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/69134.html","url":"https:\/\/www.wsisp.com\/helps\/69134.html","name":"STM32\u7b14\u8bb0\u5f52\u7eb34\uff1aI2C - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-30T21:57:50+00:00","dateModified":"2026-01-30T21:57:50+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/69134.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/69134.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/69134.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"STM32\u7b14\u8bb0\u5f52\u7eb34\uff1aI2C"}]},{"@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\/69134","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=69134"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/69134\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/69114"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=69134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=69134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=69134"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=69134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}