{"id":282781,"date":"2023-09-15T04:05:46","date_gmt":"2023-09-14T20:05:46","guid":{"rendered":"https:\/\/lrxjmw.cn\/jmlqdbhgzyly.html"},"modified":"2023-09-15T04:05:46","modified_gmt":"2023-09-14T20:05:46","slug":"jmlqdbhgzyly","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/jmlqdbhgzyly.html","title":{"rendered":"\u63ed\u79d8Linux SPI\u9a71\u52a8\uff1a\u80cc\u540e\u5de5\u4f5c\u539f\u7406\u4e0e\u5173\u952e\u6280\u672f"},"content":{"rendered":"
\u8fd1\u5e74\u6765linux\u516c\u793e\uff0c\u968f\u7740\u7269\u8054\u7f51\u548c\u5d4c\u5165\u5f0f\u7cfb\u7edf<\/a>\u7684\u5feb\u901f\u53d1\u5c55\uff0cSPI\uff08Serial Peripheral Interface\uff09\u603b\u7ebf\u5df2\u7ecf\u6210\u4e3a\u8fde\u63a5\u5404\u79cd\u5916\u8bbe\u7684\u91cd\u8981\u63a5\u53e3\u4e4b\u4e00\u3002\u5728Linux<\/a>\u7cfb\u7edf\u4e2d\uff0c\u901a\u8fc7SPI\u9a71\u52a8\u53ef\u4ee5\u5b9e\u73b0\u4e0e\u5916\u8bbe\u4e4b\u95f4\u7684\u9ad8\u6548\u6570\u636e\u4f20\u8f93\u3002\u672c\u6587\u5c06\u5e26\u60a8\u6df1\u5165\u4e86\u89e3Linux\u4e0b\u7684SPI\u9a71\u52a8\u4f8b\u7a0b\uff0c\u63ed\u79d8\u5176\u80cc\u540e\u7684\u5de5\u4f5c\u539f\u7406\u548c\u5173\u952e\u6280\u672f\u3002<\/p>\n \u4e00\u3001\u4ec0\u4e48\u662fSPI\uff1f<\/p>\n SPI\u662f\u4e00\u79cd\u5168\u53cc\u5de5\u3001\u540c\u6b65\u901a\u4fe1\u534f\u8bae\uff0c\u7528\u4e8e\u5728\u4e3b\u63a7\u82af\u7247\u548c\u5916\u8bbe\u4e4b\u95f4\u8fdb\u884c\u6570\u636e\u4f20\u8f93\u3002\u5b83\u4ee5\u4e3b\u4ece\u65b9\u5f0f\u5de5\u4f5c\uff0c\u901a\u5e38\u7531\u4e00\u4e2a\u4e3b\u8bbe\u5907\u548c\u591a\u4e2a\u4ece\u8bbe\u5907\u7ec4\u6210\u3002\u4e3b\u8bbe\u5907\u901a\u8fc7\u65f6\u949f\u4fe1\u53f7\u63a7\u5236\u6570\u636e\u4f20\u8f93\u7684\u65f6\u5e8f\uff0c\u5e76\u901a\u8fc7\u7247\u9009\u4fe1\u53f7\u9009\u62e9\u4e0e\u4e4b\u901a\u4fe1\u7684\u4ece\u8bbe\u5907\u3002<\/p>\n \u4e8c\u3001SPI\u9a71\u52a8\u5728Linux\u4e2d\u7684\u4f5c\u7528<\/p>\n \u5728Linux\u7cfb\u7edf\u4e2d\uff0cSPI\u9a71\u52a8\u8d1f\u8d23\u7ba1\u7406SPI\u603b\u7ebf\u548c\u76f8\u5173\u5916\u8bbe\u4e4b\u95f4\u7684\u901a\u4fe1\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7ec4API\u51fd\u6570\uff0c\u4f7f\u5f97\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u65b9\u4fbf\u5730\u4e0eSPI\u8bbe\u5907\u8fdb\u884c\u4ea4\u4e92\u3002\u901a\u8fc7\u8c03\u7528\u8fd9\u4e9bAPI\u51fd\u6570\uff0c\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u53d1\u9001\u548c\u63a5\u6536\u6570\u636e\uff0c\u5e76\u5bf9\u76f8\u5173\u53c2\u6570\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n \u4e09\u3001\u5982\u4f55\u7f16\u5199Linux SPI\u9a71\u52a8\uff1f<\/p>\n \u7f16\u5199\u4e00\u4e2a\u5b8c\u6574\u7684Linux SPI\u9a71\u52a8\u9700\u8981\u4ee5\u4e0b\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\uff1a<\/p>\n 1.\u786e\u5b9a\u786c\u4ef6\u8fde\u63a5\u548c\u8bbe\u5907\u6811\u914d\u7f6e<\/p>\n \u5728\u5f00\u59cb\u7f16\u5199\u9a71\u52a8\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u5b9aSPI\u603b\u7ebf\u7684\u786c\u4ef6\u8fde\u63a5\uff0c\u5e76\u5728\u8bbe\u5907\u6811\u4e2d\u8fdb\u884c\u76f8\u5e94\u7684\u914d\u7f6e\u3002\u8bbe\u5907\u6811\u662f\u4e00\u79cd\u63cf\u8ff0\u786c\u4ef6\u8bbe\u5907\u53ca\u5176\u8fde\u63a5\u5173\u7cfb\u7684\u6570\u636e\u7ed3\u6784\uff0c\u901a\u8fc7\u5bf9\u8bbe\u5907\u6811\u7684\u914d\u7f6e\uff0c\u53ef\u4ee5\u544a\u8bc9\u5185\u6838\u5982\u4f55\u6b63\u786e\u5730\u521d\u59cb\u5316\u548c\u7ba1\u7406SPI\u603b\u7ebf\u3002<\/p>\n 2.\u6ce8\u518cSPI\u9a71\u52a8<\/p>\n \u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u9a71\u52a8\u7a0b\u5e8f\u9700\u8981\u901a\u8fc7\u8c03\u7528\u76f8\u5173\u51fd\u6570\u6765\u6ce8\u518c\u81ea\u5df1\u3002\u5728SPI\u9a71\u52a8\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528`spi_register_driver()`\u51fd\u6570\u6765\u6ce8\u518c\u9a71\u52a8\uff0c\u5e76\u4f20\u5165\u4e00\u4e2a`spi_driver`\u7ed3\u6784\u4f53\u4f5c\u4e3a\u53c2\u6570\u3002\u8fd9\u4e2a\u7ed3\u6784\u4f53\u4e2d\u5305\u542b\u4e86\u9a71\u52a8\u7a0b\u5e8f\u7684\u56de\u8c03\u51fd\u6570\u7b49\u4fe1\u606f\u3002<\/p>\n 3.\u5b9e\u73b0\u9a71\u52a8\u7a0b\u5e8f\u7684\u56de\u8c03\u51fd\u6570<\/p>\n SPI\u9a71\u52a8\u7a0b\u5e8f\u9700\u8981\u5b9e\u73b0\u4e00\u7ec4\u56de\u8c03\u51fd\u6570\uff0c\u4ee5\u54cd\u5e94\u4e0d\u540c\u7684\u64cd\u4f5c\u3002\u5176\u4e2d\u6700\u91cd\u8981\u7684\u662f`probe()`\u548c`transfer()`\u51fd\u6570\u3002<\/p>\n -`probe()`\u51fd\u6570\u7528\u4e8e\u5728\u4e0e\u4ece\u8bbe\u5907\u5efa\u7acb\u901a\u4fe1\u65f6\u8fdb\u884c\u521d\u59cb\u5316\u64cd\u4f5c\u3002\u5b83\u4f1a\u88ab\u5185\u6838\u8c03\u7528\uff0c\u5e76\u4f20\u5165\u4e00\u4e2a\u6307\u5411`spi_device`\u7ed3\u6784\u4f53\u7684\u6307\u9488\u4f5c\u4e3a\u53c2\u6570\u3002\u5728\u8be5\u51fd\u6570\u4e2d\uff0c\u53ef\u4ee5\u8fdb\u884c\u4e00\u4e9b\u521d\u59cb\u5316\u8bbe\u7f6e\uff0c\u5982\u8bbe\u7f6e\u65f6\u949f\u9891\u7387\u3001\u4f20\u8f93\u6a21\u5f0f\u7b49\u3002<\/p>\n -`transfer()`\u51fd\u6570\u7528\u4e8e\u5b9e\u9645\u7684\u6570\u636e\u4f20\u8f93\u3002\u901a\u8fc7\u8be5\u51fd\u6570linux spi\u9a71\u52a8\u4f8b\u7a0b<\/strong>\uff0c\u53ef\u4ee5\u53d1\u9001\u548c\u63a5\u6536\u6570\u636e\uff0c\u5e76\u5bf9\u76f8\u5173\u53c2\u6570\u8fdb\u884c\u914d\u7f6e\u3002\u5728\u8be5\u51fd\u6570\u4e2d\uff0c\u9700\u8981\u4f7f\u7528`spi_sync_transfer()`\u51fd\u6570\u6765\u5b9e\u73b0\u6570\u636e\u7684\u540c\u6b65\u4f20\u8f93\u3002<\/p>\n 4.\u7f16\u8bd1\u548c\u52a0\u8f7d\u9a71\u52a8<\/p>\n <\/p>\n