{"id":6647,"date":"2024-06-02T11:01:48","date_gmt":"2024-06-02T03:01:48","guid":{"rendered":"http:\/\/www.hellofpga.com\/?p=6647"},"modified":"2024-06-02T11:01:48","modified_gmt":"2024-06-02T03:01:48","slug":"ov7670-2","status":"publish","type":"post","link":"http:\/\/www.hellofpga.com\/index.php\/2024\/06\/02\/ov7670-2\/","title":{"rendered":"Xillinux \u7ae0\u8282\u5341\u516d \uff08\u8865\u5145\u4e00\uff09\u5728 Smart Zynq\u4e3b\u677f\u4e0a\u901a\u8fc7 I2C\u63a5\u53e3\u5bf9 OV7670 \u76f8\u673a\u4f20\u611f\u5668\u7684\u5bc4\u5b58\u5668\u8fdb\u884c\u914d\u7f6e"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u672c\u6587\u6839\u636e Xillinux \uff08xillybus\uff09\u5b98\u65b9\u7684\u5b50\u7f51\u7ad9 www.01signal.com \u4e2d\u7684\u5185\u5bb9\u8f6c\u8f7d\u6574\u7406\u800c\u6765\uff0c\u5982\u5bf9\u539f\u59cb\u5185\u5bb9\u611f\u5174\u8da3\u7684\u53ef\u8bbf\u95ee\u4e0b\u5217\u94fe\u63a5\u8fdb\u884c\u67e5\u770b&nbsp;<a href=\"https:\/\/www.01signal.com\/zh\/xillinux\/ov7670-sccb-control\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u4f7f\u7528 Smart Zynq\u901a\u8fc7 I2C \u5199\u5165 OV7670 camera sensor\u7684 registers<\/a> \u6216\u8005\u82f1\u6587\u539f\u5185\u5bb9<a href=\"https:\/\/www.01signal.com\/xillinux\/ov7670-sccb-control\/\">Writing to OV7670 camera sensor&#8217;s registers through I2C with Smart Zynq<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e5f\u611f\u8c22xillybus \u5b98\u65b9\u5bf9\u539f\u59cb\u5185\u5bb9\u7684\u68b3\u7406\uff0c \u672c\u6587\u4ec5\u5728\u4e0a\u8ff0\u5185\u5bb9\u4e2d\u5bf9\u6587\u4e2d\u90e8\u5206\u7ffb\u8bd1\u5185\u5bb9\u505a\u4e86\u7b80\u5355\u5fae\u8c03\uff0c\u4ee5\u4fbf\u66f4\u597d\u7684\u7406\u89e3\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4ecb\u7ecd<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6559\u7a0b\u89e3\u91ca\u4e86\u5982\u4f55\u4f7f\u7528 Smart Zynq \u5f00\u53d1\u677f\u8bbf\u95ee OV7670 \u76f8\u673a\u4f20\u611f\u5668\u7684\u5bc4\u5b58\u5668\u3002\u8fd9\u662f<a href=\"http:\/\/www.hellofpga.com\/index.php\/2024\/04\/15\/ov7670\/\" data-type=\"link\" data-id=\"http:\/\/www.hellofpga.com\/index.php\/2024\/04\/15\/ov7670\/\">\u4e0a\u4e00\u8282<\/a>\u5185\u5bb9\u7684\u8865\u5145\u5185\u5bb9\uff0c<a href=\"http:\/\/www.hellofpga.com\/index.php\/2024\/04\/15\/ov7670\/\" data-type=\"link\" data-id=\"http:\/\/www.hellofpga.com\/index.php\/2024\/04\/15\/ov7670\/\">\u4e0a\u4e00\u8282<\/a>\u63cf\u8ff0\u4e86\u5982\u4f55\u4ece\u76f8\u673a\u4f20\u611f\u5668\u63a5\u6536\u89c6\u9891\u6570\u636e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">OV7670 \u6709\u4e00\u4e2a\u4e32\u884c\u6444\u50cf\u5934\u63a7\u5236\u603b\u7ebf\u63a5\u53e3\uff08SCCB\uff09\u7528\u4e8e\u914d\u7f6e\u76f8\u673a\u4f20\u611f\u5668\u7684\u53c2\u6570\u3002SCCB \u534f\u8bae\u5728 Omnivision \u7684\u540d\u4e3a\u201cOmniVision Serial Camera Control Bus (SCCB) Functional Specification\u201d\u7684\u6587\u6863\u4e2d\u5b9a\u4e49\u3002\u8be5\u534f\u8bae\u4e0e\u4f17\u6240\u5468\u77e5\u7684\u7684 I2C \u534f\u8bae\u517c\u5bb9\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bbf\u95ee\u76f8\u673a\u4f20\u611f\u5668\u5bc4\u5b58\u5668\u7684\u4e3b\u8981\u52a8\u673a\u662f\u4f7f\u76f8\u673a\u4ea7\u751f\u5177\u6709\u6b63\u786e\u989c\u8272\u7684\u56fe\u50cf\u3002\u7136\u800c\uff0c\u901a\u8fc7\u5176\u5bc4\u5b58\u5668\u63a7\u5236\u76f8\u673a\u8fd8\u6709\u5176\u4ed6\u4f18\u70b9\uff1a\u63a7\u5236\u6570\u5b57\u4fe1\u53f7\u7684\u7535\u6d41\uff0c\u63a7\u5236\u5e76\u53ef\u80fd\u505c\u6b62\u76f8\u673a\u7684\u4eae\u5ea6\u548c\u989c\u8272\u7684\u81ea\u52a8\u8c03\u6574\uff0c\u8bf7\u6c42\u6d4b\u8bd5\u56fe\u6848\uff08test pattern\uff09\u7b49\u529f\u80fd\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Zynq\u5904\u7406\u5668\u6709\u4e24\u8def\u5185\u7f6e\u7684I2C\u5355\u5143\uff0c\u6bcf\u8def\u90fd\u53ef\u4ee5\u5145\u5f53I2C\u603b\u7ebf master\u7684\u89d2\u8272\uff0c\u53ef\u4ee5\u4f7f\u7528\u5176\u4e2d\u4efb\u4e00\u5355\u5143\u4e0e\u76f8\u673a\u4f20\u611f\u5668\u901a\u4fe1\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u5f53\u5c1d\u8bd5\u4f7f\u7528\u8fd9\u4e9b\u5185\u7f6e\u7684I2C\u5355\u5143\u65f6\u53d1\u73b0\u5b83\u4eec\u4e0d\u80fd\u4e0e OV7670\u5f88\u597d\u5730\u914d\u5408\u4f7f\u7528\u3002\u539f\u56e0\u53ef\u80fd\u662f\u7ebf\u8def\u4e0a\u5b58\u5728\u5927\u91cf\u566a\u97f3\uff08\u5f53\u4f7f\u7528\u675c\u90a6\u7ebf\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\uff09\u3002\u5e76\u4e14\u7f3a\u4e4f\u4e13\u7528\u7684\u4e0a\u62c9\u7535\u963b\u662f\u53e6\u4e00\u4e2a\u53ef\u80fd\u7684\u539f\u56e0\uff08 FPGA\u7684\u5185\u90e8\u4e0a\u62c9\u7535\u963b\u53ef\u4ee5\u89e3\u51b3\u6b64\u95ee\u9898\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u4e8e\u65e0\u6cd5\u4f7f\u7528\u5185\u7f6e\u7684I2C\u5355\u5143\uff0c\u56e0\u6b64\u5728\u9879\u76ee\u4e2d\u6dfb\u52a0\u4e86\u4e00\u4e2aVerilog\u6a21\u5757\u3002\u6b64\u903b\u8f91\u8bbe\u8ba1\u5f97\u66f4\u597d\u5730\u5e94\u5bf9\u566a\u58f0\u4fe1\u53f7\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5bf9Vivado \u9879\u76ee\u8fdb\u884c\u66f4\u6539<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u7684\u5185\u5bb9\u662f\u57fa\u4e8e\u4e0a\u4e00\u8282\u5185\u5bb9\uff08<a href=\"http:\/\/www.hellofpga.com\/index.php\/2024\/04\/15\/ov7670\/\">Xillinux \u7ae0\u8282\u5341\u516d \u4f7f\u7528 Smart Zynq \u4ece OV7670 \u6444\u50cf\u5934\u6a21\u5757\u8fdb\u884c\u5b9e\u65f6\u53d6\u666f\u548c\u89c6\u9891\u6355\u6349<\/a>&nbsp;\uff09\u4e2d\u521b\u5efa\u7684vivado \u9879\u76ee\u5c55\u5f00\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece<a href=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/i2c_if.v\" data-type=\"link\" data-id=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/i2c_if.v\">\u6b64\u94fe\u63a5<\/a>\u4e0b\u8f7dI2C\u603b\u7ebf\u4e3b\u673a\u90e8\u5206\u7684Verilog\u5b9e\u73b0\u3002\u5c06\u6b64\u6587\u4ef6\u590d\u5236\u5230\u5de5\u7a0b\u4e0b\u7684 verilog\/src\/ \u76ee\u5f55\u4e2d\u3002\u7136\u540e\u5c06\u8be5\u6587\u4ef6\u6dfb\u52a0\u5230 Vivado \u9879\u76ee\u4e2d\uff1a \u5355\u51fb File &gt; Add Sources\u2026 \u5e76\u9009\u62e9\u201cAdd or create design sources\u201d\u3002\u7136\u540e\u5355\u51fb\u201c Next\u201d\u3002\u5355\u51fb\u201cAdd Files\u201d\u6309\u94ae\u5e76\u9009\u62e9 verilog\/src\/ \u76ee\u5f55\u4e2d\u540d\u4e3a\u201ci2c_if.v\u201d\u7684\u6587\u4ef6\u3002\u7136\u540e\u5355\u51fb\u201cFinish\u201d\u6309\u94ae\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5904\u7406\u5668\u5728\u4e24\u4e2a Xillybus \u6570\u636e\u6d41\u7684\u5e2e\u52a9\u4e0b\u64cd\u4f5c\u8fd9\u4e2a\u6a21\u5757 \u3002\u5728\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u6253\u5f00verilog\/src\/xillydemo.v \u3002\u5220\u9664\u6807\u8bb0\u4e3a\u201cPART 3\u201d\u7684\u4ee3\u7801\u90e8\u5206\u3002\u63d2\u5165\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\u6765\u4ee3\u66ff\u8be5\u90e8\u5206\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> \/*<br>    * PART 3<br>    * ======<br>    *<br>    * The instantiation of i2c_if demonstrates how to use two Xillybus<br>    * streams to implement an I2C interface with the camera sensor module.<br>    * <br>    *\/<br><br>   i2c_if i2c_if_ins<br>     (<br>      .bus_clk(bus_clk),<br>      .quiesce(quiesce),<br><br>      .i2c_clk(J6[15]),<br>      .i2c_data(J6[14]),<br><br>      .user_w_write_8_open(user_w_write_8_open),<br>      .user_w_write_8_wren(user_w_write_8_wren),<br>      .user_w_write_8_data(user_w_write_8_data),<br>      .user_w_write_8_full(user_w_write_8_full),<br><br>      .user_r_read_8_open(user_r_read_8_open),<br>      .user_r_read_8_rden(user_r_read_8_rden),<br>      .user_r_read_8_data(user_r_read_8_data),<br>      .user_r_read_8_empty(user_r_read_8_empty),<br>      .user_r_read_8_eof(user_r_read_8_eof)<br>      );<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6216\u8005\uff0c\u60a8\u53ef\u4ee5\u4ece<a href=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/xillydemo.v\" data-type=\"link\" data-id=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/xillydemo.v\" target=\"_blank\" rel=\"noreferrer noopener\">\u6b64\u5904<\/a>\u4e0b\u8f7d\u6b64\u66f4\u6539\u540e\u7684 xillydemo.v \u3002\u5b8c\u6210\u66f4\u6539\u540e\u6309\u7167\u4ee5\u5f80\u7684\u65b9\u6cd5\u521b\u5efa bitstream \u6587\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u6ce8\u610f\uff0c i2c_if module \u8fde\u63a5\u5230 J6[15] \u548c J6[14]\u3002\u8fd9\u4e9b\u7aef\u53e3\u901a\u8fc7\u6392\u9488\u8fde\u63a5\u5230\u76f8\u673a\u6a21\u5757\u7684 SCL \u548c SDA\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u66f4\u6539\u76f8\u673a\u4f20\u611f\u5668\u7684\u5bc4\u5b58\u5668<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u4ece\u6b64<a href=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/i2c.c\" target=\"_blank\" rel=\"noreferrer noopener\">\u94fe\u63a5<\/a>\u4e0b\u8f7d\u5411\u76f8\u673a\u53d1\u9001 I<sup>2<\/sup>C \u547d\u4ee4\u7684\u8ba1\u7b97\u673a\u7a0b\u5e8f\u3002\u5c06\u6b64\u7a0b\u5e8f\u590d\u5236\u5230 Xillinux\u7684\u6587\u4ef6\u7cfb\u7edf\u4e2d(\u590d\u5236\u65b9\u5f0f\u53ef\u4ee5\u901a\u8fc7TF\u5361\u76f4\u63a5\u590d\u5236\uff0c\u6216\u8005\u7528scp\u547d\u4ee4\u4f20\u8f93\uff08<a href=\"http:\/\/www.hellofpga.com\/index.php\/2023\/11\/15\/scp\/\">Xillinux \u7ae0\u8282\u5341 Windows \u901a\u8fc7 SCP \u547d\u4ee4 \u8fdc\u7a0b\u4f20\u8f93\u6587\u4ef6\u7ed9Xillinux \u7cfb\u7edf<\/a>&nbsp;\uff09\uff0c\u4e5f\u53ef\u4ee5\u7528CIFS\u7684\u65b9\u5f0f\u4f20\u8f93\u6587\u4ef6\uff08<a href=\"http:\/\/www.hellofpga.com\/index.php\/2023\/12\/10\/cifs2\/\">Xillinux \u7ae0\u8282\u5341\u4e8c \u5728Xillinux \u7cfb\u7edf\u4e0a\u642d\u5efa CIFS\u670d\u52a1(samba)\uff0c\u5b9e\u73b0\u4e0eWindows \u6587\u4ef6\u5171\u4eab<\/a>&nbsp;\uff09)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u6211\u4eec\u7528CIFS\u7684\u65b9\u5f0f\u5c06i2c\u6587\u4ef6\u653e\u5230home\u6587\u4ef6\u5939\u4e0b\uff0c\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"662\" height=\"301\" src=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-4.png\" alt=\"\" class=\"wp-image-6663\" style=\"width:367px;height:auto\" srcset=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-4.png 662w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-4-300x136.png 300w\" sizes=\"auto, (max-width: 662px) 100vw, 662px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06\u76ee\u5f55\u66f4\u6539\u4e3a\u6587\u4ef6\u6240\u5728\u7684\u4f4d\u7f6e\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u952e\u5165\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u6267\u884c\u7f16\u8bd1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">gcc -Wall -O3 -o i2c i2c.c<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"745\" height=\"260\" src=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-5.png\" alt=\"\" class=\"wp-image-6664\" style=\"width:456px;height:auto\" srcset=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-5.png 745w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-5-300x105.png 300w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u7f16\u8bd1\u8fc7\u7a0b\u5e94\u8be5\u9759\u9ed8\u5b8c\u6210\u3002\u7f16\u8bd1\u6210\u529f\u540e\uff0c\u53ef\u4ee5\u770b\u5230\u76ee\u5f55\u4e0b\u591a\u4e86\u4e2ai2c\u7a0b\u5e8f\u6587\u4ef6<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"622\" height=\"258\" src=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-6.png\" alt=\"\" class=\"wp-image-6665\" style=\"width:460px;height:auto\" srcset=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-6.png 622w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-6-300x124.png 300w\" sizes=\"auto, (max-width: 622px) 100vw, 622px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u7a0b\u5e8f\u53ef\u4ee5\u901a\u8fc7 .\/i2c \u547d\u4ee4\u6765\u8fd0\u884c\u8fd0\u884c\uff0c\u4e0b\u9762\u662f\u8be5\u7a0b\u5e8f\u7684\u8fd0\u884c\u65b9\u5f0f\u548c\u7a0b\u5e8f\u6b63\u5e38\u751f\u6210\u7684\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># .\/i2c<br>Camera sensor's product ID is 0x7673<br>Reg 0x3d = 0x88 (to be altered)<br>Reg 0xb0 = 0x00 (to be altered)<br>Reg 0x6f = 0x9a (to be altered)<br>Wrote 0x3d = 0x81<br>Wrote 0xb0 = 0x84<br>Wrote 0x6f = 0x9f<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"713\" height=\"445\" src=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-7.png\" alt=\"\" class=\"wp-image-6666\" style=\"width:438px;height:auto\" srcset=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-7.png 713w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-7-300x187.png 300w\" sizes=\"auto, (max-width: 713px) 100vw, 713px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u7a0b\u5e8f\u8bfb\u53d6\u5305\u542b\u76f8\u673a\u4f20\u611f\u5668 product ID\u7684\u5bc4\u5b58\u5668 \u3002 OV7670 \u76f8\u673a\u4f20\u611f\u5668\u6709\u4e0d\u540c\u7248\u672c\u3002\u672c\u6559\u7a0b\u4f7f\u7528\u7684\uff08product ID\uff09\u7f16\u53f7\u662f 0x7673 \u7684\u76f8\u673a\u4f20\u611f\u5668\u3002\u4e0d\u592a\u53ef\u80fd\u4f1a\u9047\u5230\u4e0d\u540cproduct ID\u6807\u8bc6\u7684 OV7670 \u76f8\u673a\u4f20\u611f\u5668\u3002\u5982\u679c product ID \u4e0d\u540c\uff0c\u5219\u5f88\u53ef\u80fd\u76f8\u673a\u6a21\u5757\u4e0a\u53ef\u80fd\u5b89\u88c5\u4e86\u5176\u4ed6\u578b\u53f7\u7684\u76f8\u673a\u4f20\u611f\u5668\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u7a0b\u5e8f\u8fdb\u884c\u6700\u5c0f\u9650\u5ea6\u7684\u5fc5\u8981\u66f4\u6539\uff0c\u4ee5\u786e\u4fdd\u76f8\u673a\u4f20\u611f\u5668\u56fe\u50cf\u7684\u989c\u8272\u6b63\u786e\u65e0\u8bef\u3002\u4e3a\u4e86\u6b64\u76ee\u7684\uff0c\u6211\u4eec\u4ec5\u66f4\u6539\u4e86\u4e09\u4e2a\u5bc4\u5b58\u5668\u7684\u503c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fdb\u884c\u4efb\u4f55\u66f4\u6539\u4e4b\u524d\uff0c\u7a0b\u5e8f\u4f1a\u8bfb\u53d6\u5bc4\u5b58\u5668\u7684\u73b0\u6709\u503c\u3002\u8fd9\u4e9b\u662f\u7a0b\u5e8f\u8f93\u51fa\u4e2d\u7684\u63a5\u4e0b\u6765\u7684\u4e09\u884c\u3002\u7136\u540e\u7a0b\u5e8f\u5c06\u6b63\u786e\u7684\u503c\u5199\u5165\u8fd9\u4e9b\u5bc4\u5b58\u5668\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ecf\u8fc7\u4e0a\u8ff0\u914d\u7f6e\u540e\u518d\u6839\u636e\u4e0a\u4e00\u7ae0\u8282\u7684\u64cd\u4f5c\u6765\u67e5\u770b\uff0c\u5c31\u80fd\u53d1\u73b0\u663e\u793a\u7684\u989c\u8272\u5df2\u7ecf\u53d8\u5f97\u6b63\u5e38\u4e86\u3002\u5982\u4f7f\u7528\u675c\u90a6\u7ebf\u7684\u60c5\u51b5\u4e0b\u56fe\u50cf\u4e0d\u662f\u5f88\u7a33\u5b9a \uff0c\u53ef\u4ee5\u6839\u636e\u4e0b\u6587\u4e2d\u63d0\u5230\u7684\u5185\u5bb9\u901a\u8fc7\u4fee\u6539\u5bc4\u5b58\u5668\u7684\u65b9\u5f0f\u6765\u51cf\u5c11\u76f8\u673a\u8f93\u51fa\u7684\u9a71\u52a8\u7535\u6d41\uff0c\u518d\u6765\u770b\u6548\u679c\u3002<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"743\" src=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-8-1024x743.png\" alt=\"\" class=\"wp-image-6673\" style=\"width:542px;height:auto\" srcset=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-8-1024x743.png 1024w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-8-300x218.png 300w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-8-768x558.png 768w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/image-8.png 1226w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u8fd9\u4e09\u4e2a\u5bc4\u5b58\u5668\u7684\u529f\u80fd<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u5e78\u7684\u662f\uff0c\u76f8\u673a\u4f20\u611f\u5668\u5bc4\u5b58\u5668\u7684\u529f\u80fd\u4ecb\u7ecd\u4ec5\u88ab\u90e8\u5206\u8bb0\u5f55\u3002\u5f88\u591a OV7670\u7684\u5bc4\u5b58\u5668\u90fd\u88ab\u5b9a\u4e49\u4e3a\u201creserved\u201d\u3002\u56e0\u6b64\uff0c\u6ca1\u6709\u89e3\u91ca\u4e3a\u4ec0\u4e48\u5bc4\u5b58\u5668\u4e2d\u7684\u4e00\u4e9b\u6539\u53d8\u662f\u5fc5\u8981\u7684\u3002\u5173\u4e8e OV7670\u548c\u5bc4\u5b58\u5668\u914d\u7f6e\u7684\u4fe1\u606f\u6765\u6e90\u6709\u5f88\u591a\u3002\u5bfb\u627e\u6709\u5173\u5bc4\u5b58\u5668\u63d0\u793a\u7684\u6700\u4f73\u4f4d\u7f6e\u662f\u76f8\u673a\u4f20\u611f\u5668\u7684 Linux driver\uff1a\u00a0<a href=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/ov7670.c\" data-type=\"link\" data-id=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/ov7670.c\" target=\"_blank\" rel=\"noreferrer noopener\">ov7670.c<\/a>\uff08\u6765\u6e90\u4e8egithub\uff0c\u9700\u8981\u79d1\u5b66\u4e0a\u7f51\uff09\u3002\u7279\u522b\u662f\uff0c ov7670_default_regs[] \uff08 driver\u4e2d\u5b9a\u4e49\u7684 variable \uff09\u5305\u542b\u8bb8\u591a\u6709\u4ef7\u503c\u7684\u63d0\u793a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b\u662f\u5173\u4e8e\u4e3a\u4ec0\u4e48 i2c.c \u7a0b\u5e8f\u6539\u53d8\u4e09\u4e2a\u5bc4\u5b58\u5668\u7684\u89e3\u91ca\u3002\u4e0d\u5e78\u7684\u662f,\u5c3d\u7ba1\u8fd9\u4e9b\u6539\u53d8\u663e\u7136\u662f\u5fc5\u8981\u7684,\u4f46\u5176\u4e2d\u4e00\u4e9b\u6539\u53d8\u7684\u539f\u56e0\u5c1a\u4e0d\u6e05\u695a\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>COM13 (0x3d)\uff1a \u9996\u5148\uff0c\u8fd9\u4e2a\u5bc4\u5b58\u5668\u7684 bit 0 \u6539\u4e3a &#8216;1&#8217;\u3002\u56e0\u6b64\uff0c U \u548c V \u7684\u4f4d\u7f6e\u5728\u76f8\u673a\u4f20\u611f\u5668\u7684\u8f93\u51fa\u4e2d\u4ea4\u6362\u3002\u8fd9\u662f\u5fc5\u9700\u6539\u53d8\u7684\uff0c\u4ee5\u4fbf\u8f93\u51fa\u683c\u5f0f\u4e3a UYVY\u3002\u8fd9\u662f mplayer \u548c\u5176\u4ed6\u8f6f\u4ef6\u6240\u671f\u671b\u7684\u683c\u5f0f\u3002\u53e6\u5916\uff0c\u8fd9\u4e2a\u5bc4\u5b58\u5668\u7684 bit 3 \u6539\u6210\u4e86 &#8216;0&#8217;\u3002\u8fd9\u4e2a bit \u7684\u542b\u4e49\u5e76\u6ca1\u6709\u5199\u5728\u76f8\u673a\u4f20\u611f\u5668\u7684\u6587\u6863\u4e2d\u3002<\/li>\n\n\n\n<li>Reserved register (0xb0)\uff1a \u6ca1\u6709\u5173\u4e8e\u6b64\u5bc4\u5b58\u5668\u7684\u6587\u6863\u3002<\/li>\n\n\n\n<li>AWBCTR0 (0x6f)\uff1a \u8fd9\u4e2a\u5bc4\u5b58\u5668\u4e0e\u76f8\u673a\u4f20\u611f\u5668\u7684 white balance\uff08\u767d\u5e73\u8861\uff09\u6709\u5173\u3002\u6839\u636e OV7670\u7684 Implementation Guide\uff0c\u5c06 0x9f \u5199\u5165\u8fd9\u4e2a\u5bc4\u5b58\u5668\u4f1a\u5bfc\u81f4\u4e24\u4e2a\u53d8\u5316\uff1a Advanced AWB mode \u542f\u7528\uff0c Maximum color gain \u4ece 2x \u66f4\u6539\u4e3a 4x\u3002\u5982\u679c\u8fd9\u4e2a\u5bc4\u5b58\u5668\u4e0d\u6539\u7684\u8bdd\uff0c white balance\uff08\u767d\u5e73\u8861\uff09 \u5c31\u4e0d\u597d\u7528\u4e86\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5199\u5165\u5bc4\u5b58\u5668<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u662f @writelist\u7684\u5b9a\u4e49\uff0c\u53ef\u4ee5\u5728 i2c.c \u7a0b\u5e8f\u7684\u5f00\u5934\u9644\u8fd1\u627e\u5230\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>static<\/strong> <strong>const<\/strong> <strong>struct<\/strong> {\n  <strong>int<\/strong> addr;\n  <strong>int<\/strong> value;\n} writelist [] = {\n  { 0x3d, 0x81 }, <em>\/\/ COM13, swap UV, turn off reserved bit 3<\/em>\n  { 0xb0, 0x84 },\n  { 0x6f, 0x9f }, <em>\/\/ AWBCTR0, crucial for white balance<\/em>\n\n  { -1, -1 }, <em>\/\/ Terminate<\/em>\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">@writelist \u6570\u7ec4\u7684\u5143\u7d20\u5185\u5bb9\u7531\u4e24\u4e2a\u6570\u5b57\u7ec4\u6210\uff1a \u7b2c\u4e00\u4e2a\u6570\u5b57\u662f\u5bc4\u5b58\u5668\u7684\u5730\u5740\u3002\u7b2c\u4e8c\u4e2a\u6570\u5b57\u662f\u5e94\u5199\u5165\u8be5\u5bc4\u5b58\u5668\u7684\u503c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u7b2c\u4e00\u4e2a\u5143\u7d20\u662f { 0x3d, 0x81 }\u3002\u8fd9\u610f\u5473\u7740\u503c 0x81 \u88ab\u5199\u5165 COM13\u5bc4\u5b58\u5668\u4e2d\u3002\u8fd9\u4e2a\u5bc4\u5b58\u5668\u7684 \u5730\u5740\u5c31\u662f 0x3d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6570\u7ec4\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5fc5\u987b\u662f { -1, -1 }\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u51cf\u5c11\u76f8\u673a\u4f20\u611f\u5668\u7684\u9a71\u52a8\u7535\u6d41<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u6444\u50cf\u5934\u4f20\u611f\u5668\u4e0e Smart Zynq \u677f\u4e4b\u95f4\u7684\u8fde\u7ebf\u8fc7\u957f\u65f6\uff08\u6b64\u5904\u6307\u7528\u675c\u90a6\u7ebf\u8fdb\u884c\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\uff09\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u89c6\u9891\u56fe\u50cf\u4e0d\u7a33\u5b9a\uff1a \u89c6\u9891\u5e27\u8df3\u8dc3\uff0c\u56fe\u50cf\u4e0a\u51fa\u73b0\u7eff\u8272\u548c\u7d2b\u8272\u6761\u7eb9\u3002\u8fd9\u79cd\u60c5\u51b5\u7ecf\u5e38\u53d1\u751f\u662f\u56e0\u4e3a\u7535\u7ebf\u4e4b\u95f4\u51fa\u73b0\u4e32\u6270\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u51cf\u5c11\u76f8\u673a\u4f20\u611f\u5668\u65bd\u52a0\u5230\u4fe1\u53f7\u7ebf\u7f06\u4e0a\u7684\u7535\u6d41\uff08\u9a71\u52a8\u7535\u6d41\uff09\u53ef\u4ee5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u4e3a\u6b64\uff0c\u8bf7\u5c06\u503c 0x00 \u5199\u5165 COM2\u5bc4\u5b58\u5668\u3002\u8fd9\u4e2a\u5bc4\u5b58\u5668\u7684\u5730\u5740\u5c31\u662f 0x09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6362\u53e5\u8bdd\u8bf4\uff0c\u5c06 @writelist\u7684\u5b9a\u4e49\u6539\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>static<\/strong> <strong>const<\/strong> <strong>struct<\/strong> {\n  <strong>int<\/strong> addr;\n  <strong>int<\/strong> value;\n} writelist [] = {\n  { 0x09, 0x00 }, <em>\/\/ Drive current to 1x level<\/em>\n  { -1, -1 }, <em>\/\/ Terminate<\/em>\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\u6309\u521a\u624d\u7684\u65b9\u5f0f\u5bf9\u7a0b\u5e8f\u8fdb\u884c\u7f16\u8bd1\uff0c \u5e76\u50cf\u4e4b\u524d\u4e00\u6837\u8fd0\u884c\u8be5\u7a0b\u5e8f\u5373\u53ef\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5176\u4ed6\u53ef\u80fd\u6027<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u76f8\u673a\u4f20\u611f\u5668\u7684\u6587\u6863\uff08\u7279\u522b\u662f<em>OV7670\/OV7171 CMOS VGA (640&#215;480) CameraChip Implementation Guide<\/em>\u00a0\uff09\u63d0\u4f9b\u4e86\u6709\u5173\u5176\u4ed6\u51e0\u4e2a\u5bc4\u5b58\u5668\u7684\u4fe1\u606f\u3002\u5982\u4e0a\u6240\u8ff0\uff0c\u00a0<a href=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/ov7670.c\" target=\"_blank\" rel=\"noreferrer noopener\">Linux kernel\u7684driver\u00a0<\/a>\u4e5f\u53ef\u4ee5\u63d0\u4f9b\u91cd\u8981\u63d0\u793a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56de\u60f3\u4e00\u4e0b\u672c\u6559\u7a0b\u7684\u7b2c\u4e00\u90e8\u5206\uff08<a href=\"http:\/\/www.hellofpga.com\/index.php\/2024\/04\/15\/ov7670\/\">Xillinux \u7ae0\u8282\u5341\u516d \u4f7f\u7528 Smart Zynq \u4ece OV7670 \u6444\u50cf\u5934\u6a21\u5757\u8fdb\u884c\u5b9e\u65f6\u53d6\u666f\u548c\u89c6\u9891\u6355\u6349<\/a>&nbsp;\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u91cd\u7f6e\u76f8\u673a\u4f20\u611f\u5668\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>echo 1 &gt; \/dev\/xillybus_write_32<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u6709\u5bc4\u5b58\u5668\u90fd\u4f1a\u56e0\u8be5\u547d\u4ee4\u800c\u8fd4\u56de\u5230\u5176\u9ed8\u8ba4\u503c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6253\u5370\u51fa\u6240\u6709\u5bc4\u5b58\u5668\u7684\u503c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u662f i2c.c \u7a0b\u5e8f\u4e2d main() \u51fd\u6570\u7684\u4e00\u90e8\u5206\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>if<\/strong> (0) { <em>\/\/ Change this in order to print out registers instead<\/em>\n    <strong>for<\/strong> (i=0; i&lt;=0xc9; i++) {\n      i2c_read(i, &amp;value);\n\n      <strong>printf<\/strong>(\"Reg 0x%02x = 0x%02x\\n\", i, value);\n    }\n\n    <strong>return<\/strong> 0;\n  }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u90e8\u5206\u7684\u76ee\u7684\u662f\u5c55\u793a\u6240\u6709\u5bc4\u5b58\u5668\u7684\u6570\u503c\u3002\u7531\u4e8e\u201cif (0)\u201d\u6761\u4ef6\uff0c\u901a\u5e38\u6c38\u8fdc\u4e0d\u4f1a\u5230\u8fbe\u6b64\u90e8\u5206\u3002\u5c06\u5176\u66f4\u6539\u4e3a\u201cif (1)\u201d\u4ee5\u83b7\u5f97\u6240\u6709\u5bc4\u5b58\u5668\u503c\u7684\u6253\u5370\u8f93\u51fa\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6253\u5370\u51fa\u6240\u6709\u5bc4\u5b58\u5668\u7684\u65f6\u95f4\u5e94\u8be5\u4e0d\u5230\u4e00\u79d2\u3002\u5982\u679c\u7a0b\u5e8f\u6267\u884c\u6682\u65f6\u6682\u505c\u6216\u7a0b\u5e8f\u5361\u4f4f\uff0c\u5219\u539f\u56e0\u662f I<sup>2<\/sup>C\u603b\u7ebf\u4e0a\u7684\u901a\u4fe1\u9519\u8bef\u3002\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u65f6\uff0c\u7a0b\u5e8f\u7684\u8f93\u51fa\u53ef\u80fd\u4e0d\u6b63\u786e\u6216\u4e0d\u5b8c\u6574\u3002\u91cd\u65b0\u8fd0\u884c\u8be5\u7a0b\u5e8f\uff0c\u76f4\u81f3\u8fd0\u884c\u5feb\u901f\u3001\u6d41\u7545\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u6709\u5bc4\u5b58\u5668\u7684\u6253\u5370\u8f93\u51fa\u5747\u53ef\u5728<a href=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/register-vals-after-change.txt\" data-type=\"link\" data-id=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/register-vals-after-change.txt\" target=\"_blank\" rel=\"noreferrer noopener\">\u6b64\u94fe\u63a5<\/a>\u4e0b\u8f7d\u3002\u6b64\u6253\u5370\u8f93\u51fa\u7684\u5185\u5bb9\u662f\u76f8\u673a\u4f20\u611f\u5668\u56fe\u50cf\u989c\u8272\u6b63\u786e\u65f6\u7684\u5bc4\u5b58\u5668\u7684\u503c \u3002\u9ed8\u8ba4\u503c\u7684\u6253\u5370\u8f93\u51fa(\u76f8\u673a\u4f20\u611f\u5668\u91cd\u7f6e\u540e\u7acb\u5373\u6253\u5370)\u53ef\u4ee5<a href=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/register-vals-before-change.txt\" data-type=\"link\" data-id=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/06\/register-vals-before-change.txt\" target=\"_blank\" rel=\"noreferrer noopener\">\u5728\u6b64\u5904<\/a>\u4e0b\u8f7d\u3002\u8bf7\u6ce8\u610f,\u7531\u4e8e\u81ea\u52a8\u4eae\u5ea6\u63a7\u5236\u3001\u767d\u5e73\u8861\u7b49,\u76f8\u673a\u4f1a\u4e0d\u65ad\u7684\u81ea\u52a8\u6539\u53d8\u5176\u4e2d\u67d0\u4e00\u4e9b\u5bc4\u5b58\u5668\u7684\u503c \u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>I<sup>2<\/sup>C \u5199\u64cd\u4f5c\u662f\u5982\u4f55\u6267\u884c\u7684<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><p style=\"margin-bottom: 0px; padding-bottom: 15px; color: rgb(27, 46, 24); font-family: verdana, Arial, Helvetica, sans-serif; font-size: 16px; white-space: normal;\">\u672c\u8282\u4e3b\u8981\u719f\u6089 I<sup>2<\/sup>C \u534f\u8bae\u7684\u57fa\u7840\u77e5\u8bc6\u3002<\/p><p style=\"margin-bottom: 0px; padding-bottom: 15px; color: rgb(27, 46, 24); font-family: verdana, Arial, Helvetica, sans-serif; font-size: 16px; white-space: normal;\">i2c.c \u7a0b\u5e8f\u901a\u8fc7\u4e24\u4e2a Xillybus \u6570\u636e\u6d41\u4e0e FPGA \u5185\u90e8\u7684 i2c_if.v \u6a21\u5757\u8fdb\u884c\u901a\u4fe1\uff1a \/dev\/xillybus_write_8 \u548c \/dev\/xillybus_read_8\u3002<\/p><p style=\"margin-bottom: 0px; padding-bottom: 15px; color: rgb(27, 46, 24); font-family: verdana, Arial, Helvetica, sans-serif; font-size: 16px; white-space: normal;\">I<sup>2<\/sup>C \u5199\u64cd\u4f5c\u7684\u6267\u884c\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p><ul style=\"margin-bottom: 0px; margin-left: 1.4em; padding-bottom: 10px; color: rgb(27, 46, 24); font-family: verdana, Arial, Helvetica, sans-serif; white-space: normal;\"><li style=\"margin-bottom: 3px;\">\u5f53 host \u6253\u5f00 \/dev\/xillybus_write_8\u65f6\uff0c FPGA \u751f\u6210 I<sup>2<\/sup>C start condition\uff08I2C\u8d77\u59cb\u4fe1\u53f7\uff09\u3002<\/li><li style=\"margin-bottom: 3px;\">\u5199\u5165\u6b64 device file\uff08\u8bbe\u5907\u6587\u4ef6\uff09 \u7684\u5b57\u8282\u5c06\u4f1a\u51fa\u73b0\u5728 I<sup>2<\/sup>C \u603b\u7ebf\u4e0a\uff08\u672a\u7ecf\u4efb\u4f55\u4fee\u6539\uff09\u3002<\/li><li style=\"margin-bottom: 3px;\">\u5f53 host \u5173\u95ed \/dev\/xillybus_write_8\u65f6\uff0c FPGA \u751f\u6210 I<sup>2<\/sup>C stop condition\uff08I2C\u7ed3\u675f\u4fe1\u53f7\uff09\u3002<\/li><\/ul><p style=\"margin-bottom: 0px; padding-bottom: 15px; color: rgb(27, 46, 24); font-family: verdana, Arial, Helvetica, sans-serif; font-size: 16px; white-space: normal;\">\u8fd9\u4e9b\u6b65\u9aa4\u7531 i2c_write() \u51fd\u6570\u5b9e\u73b0\u7684\uff1a<\/p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">static void i2c_write(int addr, unsigned char data) {<br>  unsigned char sendbuf[3] = { i2c_addr &lt;&lt; 1, addr, data };<br>  allwrite(sendbuf, sizeof(sendbuf));<br>}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u51fd\u6570\u51c6\u5907\u4e00\u4e2a\u7531 3 \u4e2a\u5b57\u8282\u7ec4\u6210\u7684buffer \uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>I<sup>2<\/sup>C slave \u5730\u5740\u3002 ov7670\u7684I2C\u4ece\u5730\u5740\u662f0x42\u3002\u6bcf\u6b21i2c\u901a\u8baf\u65f6master\u7aef\u90fd\u9700\u8981\u53d1\u9001\u8be5\u5730\u5740<\/li>\n\n\n\n<li>\u4ee3\u64cd\u4f5c\u7684\u5bc4\u5b58\u5668\u5730\u5740\u3002<\/li>\n\n\n\n<li>\u5199\u5165\u8be5\u5bc4\u5b58\u5668\u7684\u503c\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">FPGA \u901a\u8fc7 I<sup>2<\/sup>C \u603b\u7ebf\u5c06\u8fd9\u4e09\u4e2a\u5b57\u8282\u53d1\u9001\u5230\u76f8\u673a\u4f20\u611f\u5668\u3002 i2c_write() \u51fd\u6570\u6253\u5f00 \/dev\/xillybus_write_8\uff0c\u4ece buffer\u5199\u5165\u6570\u636e\uff0c\u7136\u540e\u5173\u95ed\u6587\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6839\u636e I<sup>2<\/sup>C \u534f\u8bae\uff0c\u63a5\u6536\u65b9\u5fc5\u987b\u5bf9\u603b\u7ebf\u4e0a\u6240\u63a5\u6536\u5230\u7684\u6bcf\u4e2a\u5b57\u8282\u8fdb\u884c\u5e94\u7b54\uff08ack\uff09\uff1a \u6bcf\u4e2a\u5b57\u8282\uff08\u7531 8 \u4f4d\u7ec4\u6210\uff09\u4f20\u8f93\u540e\uff0c\u4f1a\u6709\u4e00\u4e2a\u7b2c9\u4f4d\u6570\u636e\u7528\u4e8e\u5e94\u7b54\u7684\u76ee\u7684\u3002\u8fd9\u7b2c9\u4f4d\u5728\u4f20\u8f93\u671f\u95f4\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u65f6\u9699\u3002\u63a5\u6536\u5b57\u8282\u7684\u4e00\u4fa7\u5fc5\u987b\u5728\u8be5\u65f6\u9699\u671f\u95f4\u5c06 SDA \u4fe1\u53f7\u7ebf\u7ebf\u62c9\u81f3 &#8216;0&#8217; \uff0c\u4ee5\u5411\u53d1\u9001\u65b9\u544a\u77e5\u786e\u8ba4\u63a5\u6536\u5230\u8be5\u5b8c\u6574\u5b57\u8282\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u76f8\u673a\u4f20\u611f\u5668\u4e0d\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u54cd\u5e94\uff0c FPGA \u5185\u90e8\u7684 i2c_if \u6a21\u5757\u5c06\u62d2\u7edd\u901a\u8fc7device file\uff08\u8bbe\u5907\u6587\u4ef6\uff09\u63a5\u53d7\u66f4\u591a\u5b57\u8282\u3002\u8fd9\u4e0d\u4f1a\u5bfc\u81f4\u9519\u8bef\uff0c\u4f46\u5bf9 close() \u51fd\u6570\u7684\u8c03\u7528\u53ea\u6709\u5728\u5ef6\u8fdf 1000 ms\u540e\u624d\u4f1a\u8fd4\u56de\u3002\u539f\u56e0\u662f Xillybus\u7684\u9a71\u52a8\u5728\u5173\u95ed\u6587\u4ef6\u4e4b\u524d\u4e00\u76f4\u5728\u7b49\u5f85\u6240\u6709\u5269\u4f59\u6570\u636e\u5230\u8fbe FPGA \u3002\u4f46\u5982\u679c I<sup>2<\/sup>C slave \u6ca1\u6709\u5bf9\u5176\u4e2d\u7684\u4e00\u4e2a\u5b57\u8282\u8fdb\u884c\u5e94\u7b54\uff08ack\uff09\uff0c FPGA \u5c06\u62d2\u7edd\u63a5\u53d7\u4e0b\u4e00\u4e2a\u5b57\u8282\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c \u9a71\u52a8\u5c06\u7b49\u5f85 1000 ms\uff0c\u7136\u540e\u5173\u95ed\u6587\u4ef6\uff0c\u5e76\u5c06\u6b64\u6d88\u606f\u6dfb\u52a0\u5230 kernel log\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Timed out while flushing. Output data may be lost.<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">kernel log \u7684\u6d88\u606f\u53ef\u4ee5\u4f7f\u7528\u201cdmesg\u201d\u547d\u4ee4\u67e5\u770b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u603b\u4e4b\uff0c\u5982\u679c\u5bf9 i2c_write() \u7684\u51fd\u6570\u8c03\u7528\u9700\u8981\u4e00\u79d2\u949f\u624d\u80fd\u5b8c\u6210\uff0c\u539f\u56e0\u5f88\u53ef\u80fd\u662f\u76f8\u673a\u4f20\u611f\u5668\u6ca1\u6709\u6b63\u786e\u54cd\u5e94 I<sup>2<\/sup>C\u603b\u7ebf\u7684\u64cd\u4f5c\u3002\u6444\u50cf\u5934\u4f20\u611f\u5668\u53ef\u80fd\u672a\u6b63\u786e\u8fde\u63a5\u5230 FPGA\uff0c\u6216\u8005\u6839\u672c\u6ca1\u6709\u8fde\u63a5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>I<sup>2<\/sup>C \u7684\u8bfb\u64cd\u4f5c\u662f\u5982\u4f55\u6267\u884c\u7684<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bfb\u64cd\u4f5c\u66f4\u590d\u6742\uff0c\u56e0\u4e3a\u5b83\u7531\u4e24\u4e2a\u5355\u72ec\u7684\u64cd\u4f5c\u7ec4\u6210\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5199\u64cd\u4f5c\uff0c\u4f46\u662f\u6ca1\u6709\u6570\u636e\u5b57\u8282\u3002\u6b64\u64cd\u4f5c\u7684\u76ee\u7684\u662f\u5c06\u5f85\u8bfb\u53d6\u7684\u5bc4\u5b58\u5668\u5730\u5740\u63d0\u4ea4\u7ed9 I<sup>2<\/sup>C slave\u3002<\/li>\n\n\n\n<li>\u4e00\u4e2a\u8bfb\u64cd\u4f5c\u3002\u5bc4\u5b58\u5668\u7684\u503c\u4ece slave \u53d1\u9001\u5230 master\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">i2c_read() \u529f\u80fd\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">static void i2c_read(int addr, unsigned char *data) {<br>  int fdr;<br><br>  unsigned char cmdbuf[2] = { i2c_addr &lt;&lt; 1, addr };<br>  unsigned char dummybuf[2] = { (i2c_addr &lt;&lt; 1) | 1, 0 };<br><br>  allwrite(cmdbuf, sizeof(cmdbuf));<br><br>  \/\/ We open xillybus_read_8 only now. Had it been open during the first<br>  \/\/ operation, there would have been a restart condition rather than a<br>  \/\/ stop condition after the first command.<br><br>  fdr = open(\"\/dev\/xillybus_read_8\", O_RDONLY);<br><br>  if (fdr &lt; 0) {<br>    perror(\"Failed to open \/dev\/xillybus_read_8 read-only\");<br>    exit(1);<br>  }<br><br>  allwrite(dummybuf, sizeof(dummybuf));<br><br>  allread(fdr, data, sizeof(*data));<br><br>  close(fdr);<br>}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u51fd\u6570\u9996\u5148\u5411 slave\u53d1\u9001\u4e24\u4e2a\u5b57\u8282 (@cmdbuf)\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>I<sup>2<\/sup>C slave\u5730\u5740\u3002ov7670\u662f 0x42\uff0c\u548c\u4e4b\u524d\u7684\u5199\u64cd\u4f5c\u4e00\u6837\u3002<\/li>\n\n\n\n<li>\u6211\u4eec\u8981\u8bfb\u53d6\u7684\u5bc4\u5b58\u5668\u7684\u5730\u5740 \u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">i2c_read() \u7136\u540e\u6253\u5f00 \/dev\/xillybus_read_8\u3002\u8bf7\u6ce8\u610f\uff0c\u4e0e allwrite()\u76f8\u6bd4\uff0c allread()\u6ca1\u6709\u8fd9\u6837\u505a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\uff0c i2c_read() \u501f\u52a9 allwrite()\u5411 bus \u5199\u5165\u4e24\u4e2a\u5b57\u8282\uff08@dummybuf\uff09\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>I<sup>2<\/sup>C address\u3002\u8fd9\u662f 0x43\uff0c\u5b83\u544a\u8bc9 slave \u8fd9\u662f\u5bf9\u603b\u7ebf\u7684\u8bfb\u64cd\u4f5c\u3002<\/li>\n\n\n\n<li>\u4e00\u4e2a\u503c\u662f0\u7684\u5b57\u8282\u3002 i2c_if \u6a21\u5757\u5c06\u5ffd\u7565\u8be5\u5b57\u8282\u7684\u5185\u5bb9\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">FPGA \u4e2d\u7684 i2c_if \u6a21\u5757\u5c06\u68c0\u67e5\u5b83\u63a5\u6536\u5230\u7684\u7b2c\u4e00\u4e2a\u5b57\u8282\u7684 bit 0 \u3002 FPGA \u6839\u636e\u6b64\u4f4d\u63a8\u65ad\u5e94\u8be5\u5bf9\u603b\u7ebf\u8fdb\u884c\u5199\u64cd\u4f5c\u8fd8\u662f\u8bfb\u64cd\u4f5c\u3002\u5982\u679c\u9700\u8981\u8bfb\u53d6\u64cd\u4f5c\uff0c\u5219\u5ffd\u7565\u6240\u6709\u5176\u4ed6\u5b57\u8282\u7684\u5185\u5bb9\u3002\u8fd9\u4e9b\u5b57\u8282\u4ec5\u7528\u4e8e\u901a\u77e5 FPGA \u5e94\u63a5\u6536\u591a\u5c11\u5b57\u8282\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">i2c_if \u6a21\u5757\u4ece\u603b\u7ebf\u8bfb\u53d6\u8bf7\u6c42\u7684\u5b57\u8282\u6570\uff0c\u5e76\u901a\u8fc7 \/dev\/xillybus_read_8\u5c06\u5176\u53d1\u9001\u5230 host \u3002\u5728\u901a\u8fc7\u5199\u5165 @dummybuf\u542f\u52a8\u603b\u7ebf\u4e0a\u7684\u8bfb\u64cd\u4f5c\u4e4b\u524d\uff0c\u5fc5\u987b\u6253\u5f00\u8be5 device file \uff08\u8bbe\u5907\u6587\u4ef6\uff09\u3002\u6b64\u540e\uff0c allread() \u8bfb\u53d6\u5bc4\u5b58\u5668\u7684\u503c\u3002 allread() \u4e0d\u4f1a\u6253\u5f00\u548c\u5173\u95ed\u6587\u4ef6\uff0c\u56e0\u4e3a\u6587\u4ef6\u5fc5\u987b\u88ab\u63d0\u524d\u6253\u5f00\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Bus restart<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u8282\u4e0e OV7670 \u76f8\u673a\u4f20\u611f\u5668\u65e0\u5173\u3002\u4f46\u5982\u679c i2c_if \u4e0e\u4e0d\u540c\u7684 slave\u4e00\u8d77\u4f7f\u7528,\u6b64\u4fe1\u606f\u53ef\u80fd\u6709\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u6ce8\u610f\uff0c i2c_read() \u5bf9 allwrite() \u6267\u884c\u4e86\u4e24\u6b21\u51fd\u6570\u8c03\u7528\u3002\u6bcf\u6b21\uff0c \/dev\/xillybus_write_8 \u90fd\u4f1a\u88ab\u6253\u5f00\u548c\u5173\u95ed\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u6570\u636e\u53d1\u9001\u4e4b\u524d\u6709\u4e00\u4e2a I<sup>2<\/sup>C start condition\uff08I2C\u8d77\u59cb\u4fe1\u53f7\uff09 \uff0c\u4e4b\u540e\u6709\u4e00\u4e2a I<sup>2<\/sup>C stop condition\uff08I2C\u7ed3\u675f\u4fe1\u53f7\uff09 \u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e5f\u5c31\u662f\u8bf4\uff0c \u5bc4\u5b58\u5668\u7684\u5730\u5740\u53d1\u9001\u5230 slave\u4e4b\u540e\uff0c\u8fd8\u6709\u4e00\u4e2a stop condition\uff08I2C\u7ed3\u675f\u4fe1\u53f7\uff09 \u3002\u7136\u540e\u5728 master \u5f00\u59cb\u8bfb\u64cd\u4f5c\u4e4b\u524d\u8fd8\u6709\u4e00\u4e2a start condition\uff08I2C\u8d77\u59cb\u4fe1\u53f7\uff09 \u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u76f8\u673a\u4f20\u611f\u5668\u9884\u8ba1\u4f1a\u53d1\u751f\u8fd9\u4e00\u7cfb\u5217\u4e8b\u4ef6\u3002\u4f46\u662f\uff0c\u5982\u679c\u5c1d\u8bd5\u6267\u884c\u5982\u4e0b\u8bfb\u53d6\u64cd\u4f5c\uff0c\u5219\u5145\u5f53 I<sup>2<\/sup>C slaves \u7684\u5176\u4ed6\u7535\u5b50\u7ec4\u4ef6\u5c06\u65e0\u6cd5\u6b63\u5e38\u5de5\u4f5c\uff1a \u8fd9\u4e9b\u7ec4\u4ef6\u5fd8\u8bb0\u4e86\u5bc4\u5b58\u5668\u7684\u5730\u5740\u4ee5\u54cd\u5e94 stop condition\uff08\u505c\u6b62\u4fe1\u53f7\uff09\u3002\u56e0\u6b64\uff0c\u6709\u5fc5\u8981\u5728\u603b\u7ebf\u4e0a\u7684\u7b2c\u4e00\u4e2a\u548c\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u4e4b\u95f4\u751f\u6210\u4e00\u4e2a restart condition\uff08\u91cd\u65b0\u542f\u52a8\u7684\u4fe1\u53f7\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">i2c_if \u6a21\u5757\u652f\u6301\u8fd9\u79cd\u53ef\u80fd\u6027\uff1a \u5982\u679c \/dev\/xillybus_write_8 \u5173\u95ed\u7136\u540e\u91cd\u65b0\u6253\u5f00\uff0c\u800c \/dev\/xillybus_read_8 \u6301\u7eed\u6253\u5f00\uff0c\u90a3\u4e48 bus \u4e0a\u5c31\u4f1a\u51fa\u73b0\u4e00\u4e2a restart condition\uff08\u91cd\u65b0\u542f\u52a8\u7684\u4fe1\u53f7\uff09 \u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5982\u679c slave \u9700\u8981 restart condition\uff08\u91cd\u65b0\u542f\u52a8\u7684\u4fe1\u53f7\uff09\uff0c\u5219\u9700\u8981\u79fb\u52a8\u5bf9 allwrite() \u7684\u51fd\u6570\u8c03\u7528\u3002\u90a3\u4e48 i2c_read() \u5c06\u4f1a\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">fdr = open(\"\/dev\/xillybus_read_8\", O_RDONLY);<br><br>  if (fdr &lt; 0) {<br>    [ ... ]<br>  }<br><br>  allwrite(cmdbuf, sizeof(cmdbuf));<br>  allwrite(dummybuf, sizeof(dummybuf));<br><br>  allread(fdr, data, sizeof(*data));<br><br>  close(fdr);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u518d\u6b21\u5f3a\u8c03\uff0c\u6b64\u4ee3\u7801\u4e0d\u9002\u5408 OV7670\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ed3\u8bba<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u4f7f\u7528 Xillybus IP \u6838\u8bbf\u95ee\u76f8\u673a\u4f20\u611f\u5668\u7684\u5bc4\u5b58\u5668\u3002\u4e0e I<sup>2<\/sup>C \u603b\u7ebf\u8fde\u63a5\u9700\u8981\u4e00\u4e2a\u9644\u52a0\u6a21\u5757\uff1a i2c_if\u3002\u8be5\u6a21\u5757\u5bf9\u4e8e\u4e0e\u5176\u4ed6 I<sup>2<\/sup>C slaves\u901a\u4fe1\u4e5f\u5f88\u6709\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u5e78\u7684\u662f\uff0c\u7f3a\u4e4f\u6709\u5173 OV7670 \u76f8\u673a\u6a21\u5757\u5bc4\u5b58\u5668\u7684\u53ef\u7528\u4fe1\u606f\u3002\u56e0\u6b64\uff0c\u53ef\u80fd\u9700\u8981\u5728\u4e92\u8054\u7f51\u4e0a\u641c\u7d22\u89e3\u51b3\u65b9\u6848\u6216\u5411\u76f8\u673a\u4f20\u611f\u5668\u7684 Linux driver\u5bfb\u6c42\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6559\u7a0b\u89e3\u91ca\u4e86\u5982\u4f55\u4f7f\u7528 Smart Zynq \u5f00\u53d1\u677f\u8bbf\u95ee OV7670 \u76f8\u673a\u4f20\u611f\u5668\u7684\u5bc4\u5b58\u5668\u3002\u8fd9\u662f\u4e0a\u4e00\u8282\u5185\u5bb9\u7684\u8865\u5145\u5185\u5bb9\uff0c\u4e0a\u4e00\u8282\u63cf\u8ff0\u4e86\u5982\u4f55\u4ece\u76f8\u673a\u4f20\u611f\u5668\u63a5\u6536\u89c6\u9891\u6570\u636e\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-6647","post","type-post","status-publish","format-standard","hentry","category-xillinux"],"views":1472,"_links":{"self":[{"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/posts\/6647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/comments?post=6647"}],"version-history":[{"count":31,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/posts\/6647\/revisions"}],"predecessor-version":[{"id":6690,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/posts\/6647\/revisions\/6690"}],"wp:attachment":[{"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/media?parent=6647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/categories?post=6647"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/tags?post=6647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}