{"id":343434,"date":"2023-01-01T21:01:12","date_gmt":"2023-01-01T21:01:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343434"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343434","title":{"rendered":"<span>\u041e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e SPI \u043c\u0435\u0436\u0434\u0443 Raspberry Pi \u0438 Arduino<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9f5\/2ac\/e84\/9f52ace849bbb05ffcfb6a64e248e684.png\" width=\"1965\" height=\"1011\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9f5\/2ac\/e84\/9f52ace849bbb05ffcfb6a64e248e684.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u0440\u043e\u0431\u043e\u0442\u043e\u0442\u0435\u0445\u043d\u0438\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0430 Python, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0435 \u0437\u0440\u0435\u043d\u0438\u0435, ROS \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0433\u043e \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0440\u0443\u043b\u0438\u0442 \u0432\u0441\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c\u0438 \u043c\u043e\u0442\u043e\u0440\u0430\u043c\u0438, \u0441\u0435\u0440\u0432\u043e\u043f\u0440\u0438\u0432\u043e\u0434\u0430\u043c\u0438 \u0438 \u0434\u0430\u0442\u0447\u0438\u043a\u0430\u043c\u0438.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u043e \u0447\u0435\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f &#8212; \u044d\u0442\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0434\u0432\u0443\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432. Arduino \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 5V, Raspberry \u043d\u0430 3.3V. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e LogicLevelConverter \u043d\u0430 4 \u043a\u0430\u043d\u0430\u043b\u0430.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/bdc\/095\/7d3\/bdc0957d3f3727072d44b9b9a5be20bb.jpeg\" alt=\"Logic level converter.\" title=\"Logic level converter.\" width=\"800\" height=\"800\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bdc\/095\/7d3\/bdc0957d3f3727072d44b9b9a5be20bb.jpeg\" data-blurred=\"true\"\/><figcaption>Logic level converter.<\/figcaption><\/figure>\n<p>\u041f\u043e\u0440\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0441\u0442\u0440\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b<br \/>Arduino Uno(Nano):<\/p>\n<ul>\n<li>\n<p>13 &#8212; SCK &#8212; \u0442\u0430\u043a\u0442\u043e\u0432\u044b\u0435 \u0438\u043c\u043f\u0443\u043b\u044c\u0441\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 SPI<\/p>\n<\/li>\n<li>\n<p>12 &#8212; MISO (Master Input Slave Output) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u043e\u043c\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Arduino) \u043a \u0432\u0435\u0434\u0443\u0449\u0435\u043c\u0443 (Raspberry)<\/p>\n<\/li>\n<li>\n<p>11 &#8212; MOSI (Master Output Slave Input) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Raspberry) \u043a \u0432\u0435\u0434\u043e\u043c\u043e\u043c\u0443 (Arduino)<\/p>\n<\/li>\n<li>\n<p>10 &#8212; CS \u0438\u043b\u0438 SS (Chip Select \u0438\u043b\u0438 Slave Select) &#8212; \u0432\u044b\u0431\u043e\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b. Raspberry \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 2 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 SPI \u0441\u0440\u0430\u0437\u0443, \u0438 \u044d\u0442\u043e\u0442 \u043f\u043e\u0440\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f, \u0441 \u043a\u0430\u043a\u0438\u043c \u0438\u0434\u0435\u0442 \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<li>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/fcc\/c3d\/b3b\/fccc3db3b066438851da06eb1bbfc71d.jpeg\" width=\"857\" height=\"756\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fcc\/c3d\/b3b\/fccc3db3b066438851da06eb1bbfc71d.jpeg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<p>Arduino Mega:<\/p>\n<ul>\n<li>\n<p>52 &#8212; SCK &#8212; \u0442\u0430\u043a\u0442\u043e\u0432\u044b\u0435 \u0438\u043c\u043f\u0443\u043b\u044c\u0441\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 SPI<\/p>\n<\/li>\n<li>\n<p>50 &#8212; MISO (Master Input Slave Output) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u043e\u043c\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Arduino) \u043a \u0432\u0435\u0434\u0443\u0449\u0435\u043c\u0443 (Raspberry)<\/p>\n<\/li>\n<li>\n<p>51 &#8212; MOSI (Master Output Slave Input) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Raspberry) \u043a \u0432\u0435\u0434\u043e\u043c\u043e\u043c\u0443 (Arduino)<\/p>\n<\/li>\n<li>\n<p>53 &#8212; CS \u0438\u043b\u0438 SS (Chip Select \u0438\u043b\u0438 Slave Select) &#8212; \u0432\u044b\u0431\u043e\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b. Raspberry \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 2 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 SPI \u0441\u0440\u0430\u0437\u0443, \u0438 \u044d\u0442\u043e\u0442 \u043f\u043e\u0440\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f, \u0441 \u043a\u0430\u043a\u0438\u043c \u0438\u0434\u0435\u0442 \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<li>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/e98\/23c\/257\/e9823c2573a47be536b0896154417d39.jpg\" alt=\" \" title=\" \" width=\"1010\" height=\"1148\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e98\/23c\/257\/e9823c2573a47be536b0896154417d39.jpg\" data-blurred=\"true\"\/><figcaption> <\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<p>Raspberry PI:<\/p>\n<ul>\n<li>\n<p>23 &#8212; SCK &#8212; \u0442\u0430\u043a\u0442\u043e\u0432\u044b\u0435 \u0438\u043c\u043f\u0443\u043b\u044c\u0441\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 SPI<\/p>\n<\/li>\n<li>\n<p>21 &#8212; MISO (Master Input Slave Output) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u043e\u043c\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Arduino) \u043a \u0432\u0435\u0434\u0443\u0449\u0435\u043c\u0443 (Raspberry)<\/p>\n<\/li>\n<li>\n<p>19 &#8212; MOSI (Master Output Slave Input) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Raspberry) \u043a \u0432\u0435\u0434\u043e\u043c\u043e\u043c\u0443 (Arduino)<\/p>\n<\/li>\n<li>\n<p>24 &#8212; CS \u0438\u043b\u0438 SS (Chip Select \u0438\u043b\u0438 Slave Select) &#8212; \u0432\u044b\u0431\u043e\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b. Raspberry \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 2 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 SPI \u0441\u0440\u0430\u0437\u0443, \u0438 \u044d\u0442\u043e\u0442 \u043f\u043e\u0440\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f, \u0441 \u043a\u0430\u043a\u0438\u043c \u0438\u0434\u0435\u0442 \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<li>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ab4\/c9a\/79b\/ab4c9a79b1017c2951c521dfa3c001d2.png\" width=\"2831\" height=\"1557\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ab4\/c9a\/79b\/ab4c9a79b1017c2951c521dfa3c001d2.png\"\/><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043a Logic level converter \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u043d\u0430\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u0437\u0435\u043c\u043b\u044f<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a \u043a\u043e\u0434\u0443:<\/p>\n<p>\u041d\u0430 Raspberry Pi \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c SPI:<\/p>\n<ol>\n<li>\n<p><code>sudo raspi-config<\/code> <\/p>\n<\/li>\n<li>\n<p><em>Interfacing options &#8212; SPI<\/em> <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/29e\/7f0\/1c8\/29e7f01c89fe0afbdd91b226446771d6.webp\" width=\"791\" height=\"448\"\/><figcaption><\/figcaption><\/figure>\n<\/li>\n<li>\n<p> \u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c SPI<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6c3\/423\/682\/6c3423682651a711b895e846d5e5dad3.webp\" width=\"790\" height=\"448\"\/><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <strong>spidev<\/strong><\/p>\n<p><code>pip3 install spidev<\/code><\/p>\n<p>\u0418 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0443 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"python\">import spidev import time from camer2 import getCherry  def list_int_to_bytes(input_list):     # Split list int values to list ready for transfer by SPI     # every value from -32768 to 32767     # will be replaced two values from -255 to 255     # Original values must be collected by Arduino after transmission      output_list = []     for int_data in input_list:         output_list.append(int_data >> 8)         output_list.append(int_data &amp; 255)     return output_list   def spi_send(txData):     # Send and recieve 40 bytes     N = 40     spi = spidev.SpiDev()     spi.open(0, 0)     spi.max_speed_hz = 1000000     txData = list_int_to_bytes(txData)     txData = txData+[0]*(N-len(txData))     rxData = []     _ = spi.xfer2([240])  # 240 - b11110000 - start byte     for i in range(40):         rxData.append(spi.xfer2([txData[i]])[0])     spi.close()     return rxData  recieved_data = spi_send([1,2,3,4,5,6])<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f spi_send \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e 20 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0442 -32768 \u0434\u043e 32767, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 40 \u0431\u0430\u0439\u0442 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 Arduino. \u0412 \u043e\u0442\u0432\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 40 \u0431\u0430\u0439\u0442, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0438\u0437 Arduino<\/p>\n<p>\u041a\u043e\u0434 \u0434\u043b\u044f Arduino:<\/p>\n<pre><code class=\"cpp\">#include &lt;SPI.h>  #define DATA_SIZE 40 byte data[DATA_SIZE];\/\/\u043c\u0430\u0441\u0441\u0438\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 int int_data[DATA_SIZE \/ 2];\/\/\u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043e\u0442 Raspberry byte sendData[DATA_SIZE];\/\/\u043c\u0430\u0441\u0441\u0438\u0432, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u043d\u0430 Raspberry volatile byte counter = 0; volatile byte in_byte = 0; volatile byte spiTranferEnd = 0; volatile byte spiTranferStarted = 0;  void fillSendData() {\/\/\u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438   for (byte i = 1; i &lt; 40; i++) {     sendData[i] = i;   } }  void setup() {   Serial.begin(9600);   pinMode(MISO, OUTPUT);   SPCR |= _BV(SPE);\/\/\u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c SPI \u0432 \u0440\u0435\u0436\u0438\u043c Slave   SPI.attachInterrupt();\/\/\u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u043f\u043e SPI   fillSendData(); }  ISR (SPI_STC_vect)\/\/\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 {   in_byte = SPDR;   if (in_byte == 240 and !spiTranferStarted) {     spiTranferStarted = 1;     counter = 0;     SPDR = sendData[counter];   }   if (spiTranferStarted and counter > 0) {     data[counter - 1] = in_byte;     SPDR = sendData[counter];   }   counter++;    if (counter == DATA_SIZE) {     SPDR = sendData[counter - 1];     counter = 0;     spiTranferStarted = 0;     spiTranferEnd = 1;   } }  void joinRecievedBytes() {\/\/\u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 40 \u0431\u0430\u0439\u0442 \u0432 20 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b\u0438\u0441\u044c   for (int i = 0; i &lt; DATA_SIZE; i += 2) {     int_data[i \/ 2] = data[i] &lt;&lt; 8 | data[i + 1];   }   spiTranferEnd = 0; }  void printSpiData() {\/\/\u0432\u044b\u0432\u043e\u0434 \u0432 \u043c\u043e\u043d\u0438\u0442\u043e\u0440 \u043f\u043e\u0440\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439   for (int i = 0; i &lt; DATA_SIZE \/ 2; i++) {     Serial.print(int_data[i]);     Serial.print(\" \");   }   Serial.println(); }  void loop () {   if (spiTranferEnd) {\/\/\u0435\u0441\u043b\u0438 \u044d\u0442\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u043b\u0430 \u0440\u0430\u0432\u043d\u0430 true, \u0437\u043d\u0430\u0447\u0438\u0442 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u0441\u0435 40 \u0431\u0430\u0439\u0442     joinRecievedBytes();\/\/\u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0437 40 \u0431\u0430\u0439\u0442 20 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439      \/\/ \u0422\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c int_data     \/\/ if (int_data[0]==1) {     \/\/    \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c     \/\/}     printSpiData();\/\/\u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043c\u043e\u043d\u0438\u0442\u043e\u0440 \u043f\u043e\u0440\u0442\u0430. \u0422\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432!     \/\/\u041f\u041e\u0422\u041e\u041c \u041e\u0422\u041a\u041b\u042e\u0427\u0418\u0422\u042c, \u0422.\u041a. \u0417\u0410\u041c\u0415\u0414\u041b\u042f\u0415\u0422 \u0420\u0410\u0411\u041e\u0422\u0423 \u041f\u0420\u041e\u0413\u0420\u0410\u041c\u041c\u042b   } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u0435 \u0434\u0435\u043b\u0430! \u0423\u0441\u043f\u0435\u0445\u043e\u0432!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/708844\/\"> https:\/\/habr.com\/ru\/post\/708844\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u0440\u043e\u0431\u043e\u0442\u043e\u0442\u0435\u0445\u043d\u0438\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0430 Python, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0435 \u0437\u0440\u0435\u043d\u0438\u0435, ROS \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0433\u043e \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0440\u0443\u043b\u0438\u0442 \u0432\u0441\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c\u0438 \u043c\u043e\u0442\u043e\u0440\u0430\u043c\u0438, \u0441\u0435\u0440\u0432\u043e\u043f\u0440\u0438\u0432\u043e\u0434\u0430\u043c\u0438 \u0438 \u0434\u0430\u0442\u0447\u0438\u043a\u0430\u043c\u0438.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u043e \u0447\u0435\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f &#8212; \u044d\u0442\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0434\u0432\u0443\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432. Arduino \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 5V, Raspberry \u043d\u0430 3.3V. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e LogicLevelConverter \u043d\u0430 4 \u043a\u0430\u043d\u0430\u043b\u0430.<\/p>\n<figure class=\"full-width\"><figcaption>Logic level converter.<\/figcaption><\/figure>\n<p>\u041f\u043e\u0440\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0441\u0442\u0440\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b<br \/>Arduino Uno(Nano):<\/p>\n<ul>\n<li>\n<p>13 &#8212; SCK &#8212; \u0442\u0430\u043a\u0442\u043e\u0432\u044b\u0435 \u0438\u043c\u043f\u0443\u043b\u044c\u0441\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 SPI<\/p>\n<\/li>\n<li>\n<p>12 &#8212; MISO (Master Input Slave Output) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u043e\u043c\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Arduino) \u043a \u0432\u0435\u0434\u0443\u0449\u0435\u043c\u0443 (Raspberry)<\/p>\n<\/li>\n<li>\n<p>11 &#8212; MOSI (Master Output Slave Input) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Raspberry) \u043a \u0432\u0435\u0434\u043e\u043c\u043e\u043c\u0443 (Arduino)<\/p>\n<\/li>\n<li>\n<p>10 &#8212; CS \u0438\u043b\u0438 SS (Chip Select \u0438\u043b\u0438 Slave Select) &#8212; \u0432\u044b\u0431\u043e\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b. Raspberry \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 2 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 SPI \u0441\u0440\u0430\u0437\u0443, \u0438 \u044d\u0442\u043e\u0442 \u043f\u043e\u0440\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f, \u0441 \u043a\u0430\u043a\u0438\u043c \u0438\u0434\u0435\u0442 \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<li>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<p>Arduino Mega:<\/p>\n<ul>\n<li>\n<p>52 &#8212; SCK &#8212; \u0442\u0430\u043a\u0442\u043e\u0432\u044b\u0435 \u0438\u043c\u043f\u0443\u043b\u044c\u0441\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 SPI<\/p>\n<\/li>\n<li>\n<p>50 &#8212; MISO (Master Input Slave Output) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u043e\u043c\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Arduino) \u043a \u0432\u0435\u0434\u0443\u0449\u0435\u043c\u0443 (Raspberry)<\/p>\n<\/li>\n<li>\n<p>51 &#8212; MOSI (Master Output Slave Input) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Raspberry) \u043a \u0432\u0435\u0434\u043e\u043c\u043e\u043c\u0443 (Arduino)<\/p>\n<\/li>\n<li>\n<p>53 &#8212; CS \u0438\u043b\u0438 SS (Chip Select \u0438\u043b\u0438 Slave Select) &#8212; \u0432\u044b\u0431\u043e\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b. Raspberry \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 2 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 SPI \u0441\u0440\u0430\u0437\u0443, \u0438 \u044d\u0442\u043e\u0442 \u043f\u043e\u0440\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f, \u0441 \u043a\u0430\u043a\u0438\u043c \u0438\u0434\u0435\u0442 \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<li>\n<figure class=\"full-width\"><figcaption> <\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<p>Raspberry PI:<\/p>\n<ul>\n<li>\n<p>23 &#8212; SCK &#8212; \u0442\u0430\u043a\u0442\u043e\u0432\u044b\u0435 \u0438\u043c\u043f\u0443\u043b\u044c\u0441\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 SPI<\/p>\n<\/li>\n<li>\n<p>21 &#8212; MISO (Master Input Slave Output) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u043e\u043c\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Arduino) \u043a \u0432\u0435\u0434\u0443\u0449\u0435\u043c\u0443 (Raspberry)<\/p>\n<\/li>\n<li>\n<p>19 &#8212; MOSI (Master Output Slave Input) &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u0435\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (Raspberry) \u043a \u0432\u0435\u0434\u043e\u043c\u043e\u043c\u0443 (Arduino)<\/p>\n<\/li>\n<li>\n<p>24 &#8212; CS \u0438\u043b\u0438 SS (Chip Select \u0438\u043b\u0438 Slave Select) &#8212; \u0432\u044b\u0431\u043e\u0440 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b. Raspberry \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 2 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 SPI \u0441\u0440\u0430\u0437\u0443, \u0438 \u044d\u0442\u043e\u0442 \u043f\u043e\u0440\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f, \u0441 \u043a\u0430\u043a\u0438\u043c \u0438\u0434\u0435\u0442 \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<li>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043a Logic level converter \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u043d\u0430\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u0437\u0435\u043c\u043b\u044f<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a \u043a\u043e\u0434\u0443:<\/p>\n<p>\u041d\u0430 Raspberry Pi \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c SPI:<\/p>\n<ol>\n<li>\n<p><code>sudo raspi-config<\/code> <\/p>\n<\/li>\n<li>\n<p><em>Interfacing options &#8212; SPI<\/em> <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/li>\n<li>\n<p> \u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c SPI<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <strong>spidev<\/strong><\/p>\n<p><code>pip3 install spidev<\/code><\/p>\n<p>\u0418 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0443 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<pre><code class=\"python\">import spidev import time from camer2 import getCherry  def list_int_to_bytes(input_list):     # Split list int values to list ready for transfer by SPI     # every value from -32768 to 32767     # will be replaced two values from -255 to 255     # Original values must be collected by Arduino after transmission      output_list = []     for int_data in input_list:         output_list.append(int_data >> 8)         output_list.append(int_data &amp; 255)     return output_list   def spi_send(txData):     # Send and recieve 40 bytes     N = 40     spi = spidev.SpiDev()     spi.open(0, 0)     spi.max_speed_hz = 1000000     txData = list_int_to_bytes(txData)     txData = txData+[0]*(N-len(txData))     rxData = []     _ = spi.xfer2([240])  # 240 - b11110000 - start byte     for i in range(40):         rxData.append(spi.xfer2([txData[i]])[0])     spi.close()     return rxData  recieved_data = spi_send([1,2,3,4,5,6])<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f spi_send \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e 20 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0442 -32768 \u0434\u043e 32767, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 40 \u0431\u0430\u0439\u0442 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 Arduino. \u0412 \u043e\u0442\u0432\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 40 \u0431\u0430\u0439\u0442, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0438\u0437 Arduino<\/p>\n<p>\u041a\u043e\u0434 \u0434\u043b\u044f Arduino:<\/p>\n<pre><code class=\"cpp\">#include &lt;SPI.h>  #define DATA_SIZE 40 byte data[DATA_SIZE];\/\/\u043c\u0430\u0441\u0441\u0438\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 int int_data[DATA_SIZE \/ 2];\/\/\u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043e\u0442 Raspberry byte sendData[DATA_SIZE];\/\/\u043c\u0430\u0441\u0441\u0438\u0432, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u043d\u0430 Raspberry volatile byte counter = 0; volatile byte in_byte = 0; volatile byte spiTranferEnd = 0; volatile byte spiTranferStarted = 0;  void fillSendData() {\/\/\u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438   for (byte i = 1; i &lt; 40; i++) {     sendData[i] = i;   } }  void setup() {   Serial.begin(9600);   pinMode(MISO, OUTPUT);   SPCR |= _BV(SPE);\/\/\u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c SPI \u0432 \u0440\u0435\u0436\u0438\u043c Slave   SPI.attachInterrupt();\/\/\u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u043f\u043e SPI   fillSendData(); }  ISR (SPI_STC_vect)\/\/\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 {   in_byte = SPDR;   if (in_byte == 240 and !spiTranferStarted) {     spiTranferStarted = 1;     counter = 0;     SPDR = sendData[counter];   }   if (spiTranferStarted and counter > 0) {     data[counter - 1] = in_byte;     SPDR = sendData[counter];   }   counter++;    if (counter == DATA_SIZE) {     SPDR = sendData[counter - 1];     counter = 0;     spiTranferStarted = 0;     spiTranferEnd = 1;   } }  void joinRecievedBytes() {\/\/\u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 40 \u0431\u0430\u0439\u0442 \u0432 20 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b\u0438\u0441\u044c   for (int i = 0; i &lt; DATA_SIZE; i += 2) {     int_data[i \/ 2] = data[i] &lt;&lt; 8 | data[i + 1];   }   spiTranferEnd = 0; }  void printSpiData() {\/\/\u0432\u044b\u0432\u043e\u0434 \u0432 \u043c\u043e\u043d\u0438\u0442\u043e\u0440 \u043f\u043e\u0440\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439   for (int i = 0; i &lt; DATA_SIZE \/ 2; i++) {     Serial.print(int_data[i]);     Serial.print(\" \");   }   Serial.println(); }  void loop () {   if (spiTranferEnd) {\/\/\u0435\u0441\u043b\u0438 \u044d\u0442\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u043b\u0430 \u0440\u0430\u0432\u043d\u0430 true, \u0437\u043d\u0430\u0447\u0438\u0442 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u0441\u0435 40 \u0431\u0430\u0439\u0442     joinRecievedBytes();\/\/\u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0437 40 \u0431\u0430\u0439\u0442 20 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439      \/\/ \u0422\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c int_data     \/\/ if (int_data[0]==1) {     \/\/    \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c     \/\/}     printSpiData();\/\/\u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043c\u043e\u043d\u0438\u0442\u043e\u0440 \u043f\u043e\u0440\u0442\u0430. \u0422\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432!     \/\/\u041f\u041e\u0422\u041e\u041c \u041e\u0422\u041a\u041b\u042e\u0427\u0418\u0422\u042c, \u0422.\u041a. \u0417\u0410\u041c\u0415\u0414\u041b\u042f\u0415\u0422 \u0420\u0410\u0411\u041e\u0422\u0423 \u041f\u0420\u041e\u0413\u0420\u0410\u041c\u041c\u042b   } }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u0435 \u0434\u0435\u043b\u0430! \u0423\u0441\u043f\u0435\u0445\u043e\u0432!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/708844\/\"> https:\/\/habr.com\/ru\/post\/708844\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-343434","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=343434"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343434\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}