{"id":258818,"date":"2015-06-07T17:09:02","date_gmt":"2015-06-07T13:09:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=258818"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=258818","title":{"rendered":"\u041f\u043e\u0440\u0442 i2cdevlib \u043d\u0430 STM32 HAL"},"content":{"rendered":"<p>     \t<img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/593\/36f\/695\/59336f695d7e45f4bcf6e4db31a45fdc.jpg\" width=\"70%\"\/><br \/>  \u0421\u0438\u043b\u044c\u043d\u043e \u0443\u0434\u0438\u0432\u0438\u043b\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b\u044f\u0441\u043d\u0438\u043b, \u0447\u0442\u043e \u043f\u043e\u0434 STM32 \u043d\u0435\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u0432 \u043f\u043e\u0434 \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 i2c \u0441\u0435\u043d\u0441\u043e\u0440\u044b, \u043a\u0430\u043a \u043f\u043e\u0434 Arduino. \u0422\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438, \u0431\u044b\u043b\u0438 \u0447\u0430\u0441\u0442\u044c\u044e \u043a\u0430\u043a\u043e\u0439 \u043b\u0438\u0431\u043e \u041e\u0421 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, ChubiOS, FreeRTOS, NuttX) \u0438 \u0431\u044b\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 POSIX-like. \u0410 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434 HAL \ud83d\ude41<\/p>\n<p>  Arduino \u043a\u043e\u043c\u044e\u043d\u0438\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/jrowberg\/i2cdevlib\">i2cdevlib<\/a> \u0434\u043b\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u043e\u0442 \u0436\u0435\u043b\u0435\u0437\u0430 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u0432 \u0441\u0435\u043d\u0441\u043e\u0440\u043e\u0432. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u0435\u043b\u044e\u0441\u044c \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u043e\u0439 \u2014 <a href=\"https:\/\/github.com\/anvol\/i2cdevlib\/tree\/master\/STM32\">\u043f\u043e\u0440\u0442 i2cdevlib \u043d\u0430 STM32 HAL<\/a> (pull-request \u0443\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b), \u0430 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u043a\u0430\u043c\u0443\u0448\u043a\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0431\u0440\u0430\u043b \u043f\u043e \u043f\u0443\u0442\u0438. \u041d\u0443 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0431\u0443\u0434\u0443\u0442.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0421 \u0447\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c<\/h4>\n<p>  \u041d\u0430 \u0440\u0443\u043a\u0430\u0445 \u0443 \u043c\u0435\u043d\u044f dev board stm32f429i-disco, \u043f\u043b\u0430\u0442\u0430 \u0441 \u0441\u0435\u043d\u0441\u043e\u0440\u0430\u043c\u0438 gy-87, arduino uno, \u0441\u0440\u0435\u0434\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 EmBitz 0.40 (ex Em::Blocks) \u0438 Arduino.<br \/>  \u0410\u0440\u0434\u0443\u0438\u043d\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432. \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u0435\u043d\u0441\u043e\u0440 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 BMP085\/BMP180. \u0412\u044b\u0431\u0440\u0430\u043d \u0432\u0432\u0438\u0434\u0443 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0441\u0435\u043d\u0441\u043e\u0440\u0430 \u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b-\u0432\u0430 \u043a\u043e\u0434\u0430 \u0432 \u0435\u0433\u043e \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0435.<\/p>\n<h4>\u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439<\/h4>\n<p>  <\/p>\n<ol>\n<li>\u041f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0441 \u0421++ \u043d\u0430 \u0421. \u0414\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u0434\u043b\u044f \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430<\/li>\n<li>\u0412 i2cdevlib \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 i2c \u043d\u0430 HAL&#8217;\u043e\u0432\u0441\u043a\u0438\u0435 \u043f\u043e \u043f\u0443\u0442\u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0432 arduino-related \u043a\u0443\u0441\u043a\u0438 \u043a\u043e\u0434\u0430<\/li>\n<li>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u043e\u0442\u043b\u0430\u0434\u043a\u0430<\/li>\n<\/ol>\n<h4>\u041f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u0434<\/h4>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0441 \u0421++ \u043d\u0430 \u0421. \u041d\u0435\u0442, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u2014 \u043e\u0431\u044c\u044f\u0441\u043d\u044e \u0437\u0430\u0447\u0435\u043c \ud83d\ude42<br \/>  \u0412 \u043c\u0438\u0440\u0435 embedded \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0447\u0430\u0449\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0438\u0441\u0442\u044b\u0439 \u0421. \u041f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0442\u043e\u043c\u0443 \u0441\u043b\u0443\u0436\u0438\u0442 \u0438 \u0441\u0430\u043c HAL. \u041f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 (EmBlocks, Keil) \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043d\u0430 \u0421. \u041a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 STM32CubeMX \u0442\u0430\u043a\u0436\u0435 \u0441\u0438\u0448\u043d\u044b\u0439. \u0414\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0448\u043d\u0443\u044e \u043b\u0438\u0431\u0443 \u0432 \u0421++ \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043b\u0435\u0433\u0447\u0435, \u0447\u0435\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u0435\u0441\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 \u0421++ \u0440\u0430\u0434\u0438 \u043b\u0438\u0431\u044b.<\/p>\n<p>  \u041f\u043e\u0435\u0445\u0430\u043b\u0438. \u041c\u0435\u043d\u044f\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u044b\u043b\u043e <b>I2Cdev::readByte<\/b> \u0441\u0442\u0430\u043b\u043e <b>I2Cdev_readByte<\/b>. \u0422\u0430\u043a\u0436\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u043a\u043e \u0432\u0441\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0430\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u0433\u0434\u0435 \u0435\u0433\u043e \u043d\u0435\u0442 (<b>readByte<\/b> -&gt; <b>I2Cdev_readByte<\/b>). \u0420\u0443\u0442\u0438\u043d\u0430, \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e. <br \/>  \u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u2014 \u0432\u0441\u0435\u0433\u043e 4 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u0436\u0435\u043b\u0435\u0437\u043e\u043c:<\/p>\n<pre><code>uint8_t I2Cdev_readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout); uint8_t I2Cdev_readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout); uint16_t I2Cdev_writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t* data); uint16_t I2Cdev_writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t* data); <\/code><\/pre>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u043f\u0440\u043e\u0434\u0435\u043b\u044b\u0432\u0430\u0435\u043c \u0441 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u043c BMP085. \u0414\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u0438\u043d\u043a\u043b\u044e\u0434\u044b (math.h, stdint.h, stdlib.h, string.h) \u043f\u043e \u043f\u0443\u0442\u0438 \u0438 \u043e\u0431\u044c\u044f\u0432\u043b\u044f\u0435\u043c \u0442\u0438\u043f bool. \u042d\u0442\u043e \u0421, \u0434\u0435\u0442\u043a\u0430) \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u0442\u043e\u0438\u043b\u043e \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 bool -&gt; uint8_t\u2026<\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0432 I2CDev \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c i2c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0439:  <\/p>\n<pre><code>#include &quot;stm32f4xx_hal.h&quot;  I2C_HandleTypeDef * I2Cdev_hi2c; <\/code><\/pre>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043d\u0430 HAL<\/h4>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0439 \u043d\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0431\u0443\u0434\u0435\u0442 I2Cdev_readBytes. \u0412\u043e\u0442 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433, \u0431\u0435\u0437 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0445 \u043a\u0443\u0441\u043a\u043e\u0432 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u043f\u043e\u0434 \u0440\u0430\u0437\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\/\u0432\u0435\u0440\u0441\u0438\u0438<\/p>\n<pre><code>\/** Read multiple bytes from an 8-bit device register.  * @param devAddr I2C slave device address  * @param regAddr First register regAddr to read from  * @param length Number of bytes to read  * @param data Buffer to store read data in  * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)  * @return Number of bytes read (-1 indicates failure)  *\/ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout) {     int8_t count = 0;     uint32_t t1 = millis();      \/\/ Arduino v1.0.1+, Wire library     \/\/ Adds official support for repeated start condition, yay!      \/\/ I2C\/TWI subsystem uses internal buffer that breaks with large data requests     \/\/ so if user requests more than BUFFER_LENGTH bytes, we have to do it in     \/\/ smaller chunks instead of all at once     for (uint8_t k = 0; k &lt; length; k += min(length, BUFFER_LENGTH)) {         Wire.beginTransmission(devAddr);         Wire.write(regAddr);         Wire.endTransmission();         Wire.beginTransmission(devAddr);         Wire.requestFrom(devAddr, (uint8_t)min(length - k, BUFFER_LENGTH));          for (; Wire.available() && (timeout == 0 || millis() - t1 &lt; timeout); count++) {             data[count] = Wire.read();         }     }      \/\/ check for timeout     if (timeout &gt; 0 && millis() - t1 &gt;= timeout && count &lt; length) count = -1; \/\/ timeout      return count; } <\/code><\/pre>\n<p>  \u042f \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u044e, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u043a\u043e\u0441\u0442\u044b\u043b\u044c \u0441 \u0446\u0438\u043a\u043b\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0432\u0435\u0434\u044c \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 length &gt; BUFFER_LENGTH \u043c\u044b \u043f\u043e \u043d\u043e\u0432\u043e\u0439 \u0443\u043a\u0430\u0436\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0447\u0442\u043e \u043a\u043e\u0434  <\/p>\n<pre><code>Wire.beginTransmission(devAddr); Wire.write(regAddr); Wire.endTransmission(); Wire.beginTransmission(devAddr); <\/code><\/pre>\n<p>  \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c <i>\u043f\u0435\u0440\u0435\u0434<\/i> \u0446\u0438\u043a\u043b\u043e\u043c. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0441\u043c\u044b\u0441\u043b \u043f\u043e\u043d\u044f\u0442\u0435\u043d, \u043f\u0438\u0448\u0435\u043c \u043f\u043e\u0434 HAL:<\/p>\n<pre><code>uint8_t I2Cdev_readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout) {     uint16_t tout = timeout &gt; 0 ? timeout : I2CDEV_DEFAULT_READ_TIMEOUT;      HAL_I2C_Master_Transmit(I2Cdev_hi2c, devAddr &lt;&lt; 1, &regAddr, 1, tout);     if (HAL_I2C_Master_Receive(I2Cdev_hi2c, devAddr &lt;&lt; 1, data, length, tout) == HAL_OK)      \treturn length;     else         return -1; } <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0434\u0432\u0438\u0433 \u0430\u0434\u0440\u0435\u0441\u0430 \u2014 devAddr &lt;&lt; 1. \u041a\u043e\u0433\u0434\u0430 \u044f \u043f\u0435\u0440\u0435\u0448\u0435\u043b \u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0441 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u043c, \u0442\u043e \u043f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u043d\u0430\u0431\u0440\u043e\u0441\u0430\u043b \u0441\u043a\u0430\u043d\u0435\u0440 \u0448\u0438\u043d\u044b:<\/p>\n<pre><code>uint8_t i = 0; for(i = 0; i&lt;255; i++) {     if(HAL_I2C_IsDeviceReady(&hi2c3, i, 10, 100) == HAL_OK) \t\tprintf(&quot;Ready: 0x%02x&quot;, i); }  <\/code><\/pre>\n<p>  \u0412\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u044f \u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u043e \u0432\u0437\u044f\u043b \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 0-255, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e 112 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0445 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u0430\u0434\u0440\u0435\u0441\u043e\u0432. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u043e \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u2014 \u043a\u0430\u0436\u0434\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043d\u0430 \u043b\u0438\u043d\u0438\u0438 \u043e\u0442\u043e\u0437\u0432\u0430\u043b\u043e\u0441\u044c \u0434\u0432\u0430\u0436\u0434\u044b \u043f\u043e\u0434\u0440\u044f\u0434, \u043f\u0440\u0438 \u0447\u0435\u043c, \u043d\u0435 \u043d\u0430 \u0441\u0432\u043e\u0439 \u0430\u0434\u0440\u0435\u0441:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d36\/a5f\/b42\/d36a5fb42eed4585b6a9e903191088cc.jpg\"\/><\/p>\n<p>  <b>Wire.begin()<\/b> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 7-\u0431\u0438\u0442\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441, \u0430 HAL \u2014 8-\u0431\u0438\u0442\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435. \u0421\u043f\u0443\u0441\u0442\u044f \u043c\u0438\u043d\u0443\u0442\u0443 \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u0439 \u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0441\u043a\u0430\u043d\u0435\u0440\u0430:  <\/p>\n<pre><code>uint8_t i = 0; for(i = 15; i&lt;127; i++) {     if(HAL_I2C_IsDeviceReady(&hi2c3, i &lt;&lt; 1, 10, 100) == HAL_OK) \t\tprintf(&quot;Ready: 0x%02x&quot;, i); }  <\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434 \u2014 \u0430\u0434\u0440\u0435\u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u0430\u043c\u043e\u043c\u0443 \u0441\u0434\u0432\u0438\u043d\u0443\u0442\u044c \u043d\u0430 \u0431\u0438\u0442 \u0432\u043b\u0435\u0432\u043e \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0439 HAL_I2C_***<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/3d9\/9ce\/9b9\/3d99ce9b91ad42bd89a371f5cbf91bb7.jp\"\/><\/p>\n<p>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u043a i2cdevlib. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043d\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u2014 <b>I2Cdev_readWords<\/b>.<\/p>\n<pre><code>uint8_t I2Cdev_readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout) {     uint16_t tout = timeout &gt; 0 ? timeout : I2CDEV_DEFAULT_READ_TIMEOUT;      HAL_I2C_Master_Transmit(I2Cdev_hi2c, devAddr &lt;&lt; 1, &regAddr, 1, tout);     if (HAL_I2C_Master_Receive(I2Cdev_hi2c, devAddr &lt;&lt; 1, (uint8_t *)data, length*2, tout) == HAL_OK)      \treturn length;     else         return -1; } <\/code><\/pre>\n<p>  \u0412 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0435 \u0442\u0430\u043c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f MSB \u0438 LSB \u0432 \u0431\u0443\u0444\u0435\u0440.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043d\u0435 \u0432\u0440\u0443<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>for (uint8_t k = 0; k &lt; length * 2; k += min(length * 2, BUFFER_LENGTH)) {     Wire.beginTransmission(devAddr);     Wire.write(regAddr);     Wire.endTransmission();     Wire.beginTransmission(devAddr);     Wire.requestFrom(devAddr, (uint8_t)(length * 2)); \/\/ length=words, this wants bytes      bool msb = true; \/\/ starts with MSB, then LSB     for (; Wire.available() && count &lt; length && (timeout == 0 || millis() - t1 &lt; timeout);) {         if (msb) {             \/\/ first byte is bits 15-8 (MSb=15)             data[count] = Wire.read() &lt;&lt; 8;         } else {             \/\/ second byte is bits 7-0 (LSb=0)             data[count] |= Wire.read();             #ifdef I2CDEV_SERIAL_DEBUG                 Serial.print(data[count], HEX);                 if (count + 1 &lt; length) Serial.print(&quot; &quot;);             #endif             count++;         }         msb = !msb;     }      Wire.endTransmission(); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0443\u0442 \u043d\u0430\u0441 \u0436\u0434\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0430\u0434\u0440\u0435\u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 START \u2014 STOP \u0431\u0438\u0442\u043e\u0432. \u0410 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u043d\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u044c\u043d\u043e. \u0414\u043b\u044f arduino \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Wire \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u0432\u0435\u0434\u044c \u0432 \u043d\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0441\u0430\u043c \u043f\u0438\u0448\u0435\u0442 begin\/end \u0438 \u0448\u043b\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438. \u041d\u0430\u043c \u0436\u0435 \u043d\u0430\u0434\u043e \u044d\u0442\u043e \u0432\u0441\u0435 \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u043e\u0434\u0438\u043d \u0431\u0443\u0444\u0435\u0440 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <b>malloc<\/b> \u0438 <b>memcpy<\/b>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0446\u0438\u043a\u043b\u0435.<\/p>\n<pre><code>\/** Write multiple bytes to an 8-bit device register.  * @param devAddr I2C slave device address  * @param regAddr First register address to write to  * @param length Number of bytes to write  * @param data Buffer to copy new data from  * @return Status of operation (true = success)  *\/ uint16_t I2Cdev_writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data) {     \/\/ Creating dynamic array to store regAddr + data in one buffer     uint8_t * dynBuffer;     dynBuffer = (uint8_t *) malloc(sizeof(uint8_t) * (length+1));     dynBuffer[0] = regAddr;      \/\/ copy array     memcpy(dynBuffer+1, data, sizeof(uint8_t) * length);      HAL_StatusTypeDef status = HAL_I2C_Master_Transmit(I2Cdev_hi2c, devAddr &lt;&lt; 1, dynBuffer, length+1, 1000);     free(dynBuffer);     return status == HAL_OK; } <\/code><\/pre>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0438 \u0434\u043b\u044f <b>I2Cdev_writeWords<\/b>, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u043c\u044f\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u043e\u0434 uint16_t + \u043e\u0434\u0438\u043d \u0431\u0430\u0439\u0442 \u043d\u0430 uint8_t regAddr. HAL&#8217;\u0443 \u0432\u0440\u0435\u043c, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 uint8_t, \u043d\u043e \u0434\u043b\u0438\u043d\u043d\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \ud83d\ude42<\/p>\n<pre><code>\/** Write multiple words to a 16-bit device register.  * @param devAddr I2C slave device address  * @param regAddr First register address to write to  * @param length Number of words to write  * @param data Buffer to copy new data from  * @return Status of operation (true = success)  *\/ uint16_t I2Cdev_writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t* data) {     \/\/ Creating dynamic array to store regAddr + data in one buffer     uint8_t * dynBuffer;     dynBuffer = (uint8_t *) malloc(sizeof(uint8_t) + sizeof(uint16_t) * length);     dynBuffer[0] = regAddr;      \/\/ copy array     memcpy(dynBuffer+1, data, sizeof(uint16_t) * length);     HAL_StatusTypeDef status = HAL_I2C_Master_Transmit(I2Cdev_hi2c, devAddr &lt;&lt; 1, dynBuffer, sizeof(uint8_t) + sizeof(uint16_t) * length, 1000);     free(dynBuffer);     return status == HAL_OK; } <\/code><\/pre>\n<h4>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u043e\u0442\u043b\u0430\u0434\u043a\u0430<\/h4>\n<p>  \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0430 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c i2c, \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432 <b>I2Cdev_hi2c<\/b> \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0435\u043d\u0441\u043e\u0440\u0430. \u0412\u043e\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0435\u0435 \u0440\u0430\u0431\u043e\u0442\u044b:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043f\u0440\u0438\u043c\u0435\u0440 BMP180<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>#include &quot;stm32f4xx.h&quot; #include &quot;stm32f4xx_hal.h&quot; #include &lt;stdint.h&gt; #include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &quot;I2Cdev.h&quot; #include &quot;BMP085.h&quot;  I2C_HandleTypeDef hi2c3;  int main(void) {     SystemInit();     HAL_Init();      GPIO_InitTypeDef GPIO_InitStruct;      \/**I2C3 GPIO Configuration     PC9     ------&gt; I2C3_SDA     PA8     ------&gt; I2C3_SCL     *\/      __GPIOA_CLK_ENABLE();     __GPIOC_CLK_ENABLE();      GPIO_InitStruct.Pin = GPIO_PIN_9;     GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;     GPIO_InitStruct.Pull = GPIO_PULLUP;     GPIO_InitStruct.Speed = GPIO_SPEED_FAST;     GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;     HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);      GPIO_InitStruct.Pin = GPIO_PIN_8;     GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;     GPIO_InitStruct.Pull = GPIO_PULLUP;     GPIO_InitStruct.Speed = GPIO_SPEED_FAST;     GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);      __I2C3_CLK_ENABLE();      hi2c3.Instance = I2C3;     hi2c3.Init.ClockSpeed = 400000;     hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;     hi2c3.Init.OwnAddress1 = 0x10;     hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;     hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;     hi2c3.Init.OwnAddress2 = 0x11;     hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;     hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;      HAL_I2C_Init(&hi2c3);      I2Cdev_hi2c = &hi2c3; \/\/ init of i2cdevlib.       \/\/ You can select other i2c device anytime and      \/\/ call the same driver functions on other sensors      while(!BMP085_testConnection()) ;      BMP085_initialize();      while (1)     {         BMP085_setControl(BMP085_MODE_TEMPERATURE);         HAL_Delay(BMP085_getMeasureDelayMilliseconds(BMP085_MODE_TEMPERATURE));         float t = BMP085_getTemperatureC();          BMP085_setControl(BMP085_MODE_PRESSURE_3);         HAL_Delay(BMP085_getMeasureDelayMilliseconds(BMP085_MODE_PRESSURE_3));         float p = BMP085_getPressure();          float a = BMP085_getAltitude(p, 101325);         printf(&quot;T: %3.1f  P: %3.0f  A: %3.2f&quot;, t, p ,a);          HAL_Delay(1000);     } }  void SysTick_Handler() {     HAL_IncTick();     HAL_SYSTICK_IRQHandler(); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443 \u0432 \u0421, \u0434\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u041f\u0430\u0441\u043a\u0430\u043b\u044f\u0445 \u0438 \u0432\u044b\u0441\u043e\u0442\u0443 \u043d\u0430\u0434 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u043c\u043e\u0440\u044f \u0432 \u043c\u0435\u0442\u0440\u0430\u0445<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/690\/452\/46d\/69045246d9db491b83a6b7cd9e14cc19.jpg\"\/><\/p>\n<h4>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h4>\n<p>  \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u0442\u0430\u043a\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u0434\u0432\u0430 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u2014 \u0434\u043b\u044f BMP085\/BMP180 \u0438 MPU6050. \u0420\u0430\u0431\u043e\u0442\u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u043e\u043a\u0430\u0436\u0443 \u043d\u0430 \u0444\u043e\u0442\u043e \u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0444\u043e\u0442\u043e<\/b><\/p>\n<div class=\"spoiler_text\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/31e\/b19\/2e9\/31eb192e9a7f45e4af945aaf1a91bc2c.jpg\"\/>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>#include &quot;stm32f4xx.h&quot; #include &quot;stm32f4xx_hal.h&quot; #include &lt;stdint.h&gt; #include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &quot;I2Cdev.h&quot; #include &quot;BMP085.h&quot; #include &quot;MPU6050.h&quot;  I2C_HandleTypeDef hi2c3;  int main(void) {     SystemInit();     HAL_Init();      GPIO_InitTypeDef GPIO_InitStruct;      \/**I2C3 GPIO Configuration     PC9     ------&gt; I2C3_SDA     PA8     ------&gt; I2C3_SCL     *\/      __GPIOA_CLK_ENABLE();     __GPIOC_CLK_ENABLE();      GPIO_InitStruct.Pin = GPIO_PIN_9;     GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;     GPIO_InitStruct.Pull = GPIO_PULLUP;     GPIO_InitStruct.Speed = GPIO_SPEED_FAST;     GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;     HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);      GPIO_InitStruct.Pin = GPIO_PIN_8;     GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;     GPIO_InitStruct.Pull = GPIO_PULLUP;     GPIO_InitStruct.Speed = GPIO_SPEED_FAST;     GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);      __I2C3_CLK_ENABLE();      hi2c3.Instance = I2C3;     hi2c3.Init.ClockSpeed = 400000;     hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;     hi2c3.Init.OwnAddress1 = 0x10;     hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;     hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;     hi2c3.Init.OwnAddress2 = 0x11;     hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;     hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;      HAL_I2C_Init(&hi2c3);      I2Cdev_hi2c = &hi2c3; \/\/ init of i2cdevlib.       \/\/ You can select other i2c device anytime and      \/\/ call the same driver functions on other sensors      while(!BMP085_testConnection()) ;      int16_t ax, ay, az;     int16_t gx, gy, gz;      int16_t c_ax, c_ay, c_az;     int16_t c_gx, c_gy, c_gz;      MPU6050_initialize();     BMP085_initialize();     MPU6050_setFullScaleGyroRange(MPU6050_GYRO_FS_250);     MPU6050_setFullScaleAccelRange(MPU6050_ACCEL_FS_2);      MPU6050_getMotion6(&c_ax, &c_ay, &c_az, &c_gx, &c_gy, &c_gz);     while (1)     {         BMP085_setControl(BMP085_MODE_TEMPERATURE);          HAL_Delay(BMP085_getMeasureDelayMilliseconds(BMP085_MODE_TEMPERATURE));         float t = BMP085_getTemperatureC();          BMP085_setControl(BMP085_MODE_PRESSURE_3);         HAL_Delay(BMP085_getMeasureDelayMilliseconds(BMP085_MODE_PRESSURE_3));         float p = BMP085_getPressure();          float a = BMP085_getAltitude(p, 101325);          printf(buf, &quot;T: %3.1f  P: %3.0f  A: %3.2f&quot;, t, p ,a);          MPU6050_getMotion6(&ax, &ay, &az, &gx, &gy, &gz);          printf(&quot;Accel: %d    %d    %d&quot;, ax - c_ax, ay - c_ay, az - c_az);         printf(&quot;Gyro: %d    %d    %d&quot;, gx - c_gx, gy - c_gy, gz - c_gz);                  HAL_Delay(1000);     } }  void SysTick_Handler() {     HAL_IncTick();     HAL_SYSTICK_IRQHandler(); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0435 \u0441\u0435\u043d\u0441\u043e\u0440\u043e\u0432 \u0441\u0432\u0435\u0440\u044f\u043b\u0438\u0441\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 arduino uno \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u0443\u044e \u043a \u0442\u0435\u043c \u0436\u0435 \u0441\u0435\u043d\u0441\u043e\u0440\u0430\u043c.<br \/>  \u0412 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044e \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0435\u043d\u0441\u043e\u0440\u043e\u0432, \u0447\u0442\u043e \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u043d\u0430 \u0440\u0443\u043a\u0430\u0445 \u2014 ADXL345 \u0438 HMC5883L. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0432\u0430\u043c \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u0440\u0443\u0434\u0430 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u0415\u0441\u043b\u0438 \u0447\u0442\u043e \u2014 \u043f\u0438\u0448\u0438\u0442\u0435, \u043f\u043e\u043c\u043e\u0433\u0443 \ud83d\ude42<\/p>\n<p>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043c\u043e\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u043a\u043e\u043c\u0443-\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0438\/\u0438\u043b\u0438 \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0441 \u0410\u0440\u0434\u0443\u0438\u043d\u043e\u043a \u043d\u0430 STM32.<br \/>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441!<\/p>\n<p>  \u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c:<br \/>  <a href=\"http:\/\/i2c.info\/i2c-bus-specification\">\u0421\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f i2c<\/a><br \/>  <a href=\"http:\/\/www.i2cdevlib.com\">\u0421\u0430\u0439\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 i2cdevlib \u0441 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430\u043c\u0438 \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u044f\u043c\u0438<\/a>     \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/259709\/\"> http:\/\/habrahabr.ru\/post\/259709\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t<img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/593\/36f\/695\/59336f695d7e45f4bcf6e4db31a45fdc.jpg\" width=\"70%\"\/><br \/>  \u0421\u0438\u043b\u044c\u043d\u043e \u0443\u0434\u0438\u0432\u0438\u043b\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b\u044f\u0441\u043d\u0438\u043b, \u0447\u0442\u043e \u043f\u043e\u0434 STM32 \u043d\u0435\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u0432 \u043f\u043e\u0434 \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 i2c \u0441\u0435\u043d\u0441\u043e\u0440\u044b, \u043a\u0430\u043a \u043f\u043e\u0434 Arduino. \u0422\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438, \u0431\u044b\u043b\u0438 \u0447\u0430\u0441\u0442\u044c\u044e \u043a\u0430\u043a\u043e\u0439 \u043b\u0438\u0431\u043e \u041e\u0421 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, ChubiOS, FreeRTOS, NuttX) \u0438 \u0431\u044b\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 POSIX-like. \u0410 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434 HAL \ud83d\ude41<\/p>\n<p>  Arduino \u043a\u043e\u043c\u044e\u043d\u0438\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/jrowberg\/i2cdevlib\">i2cdevlib<\/a> \u0434\u043b\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u043e\u0442 \u0436\u0435\u043b\u0435\u0437\u0430 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u0432 \u0441\u0435\u043d\u0441\u043e\u0440\u043e\u0432. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u0435\u043b\u044e\u0441\u044c \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u043e\u0439 \u2014 <a href=\"https:\/\/github.com\/anvol\/i2cdevlib\/tree\/master\/STM32\">\u043f\u043e\u0440\u0442 i2cdevlib \u043d\u0430 STM32 HAL<\/a> (pull-request \u0443\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b), \u0430 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u043a\u0430\u043c\u0443\u0448\u043a\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0431\u0440\u0430\u043b \u043f\u043e \u043f\u0443\u0442\u0438. \u041d\u0443 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0431\u0443\u0434\u0443\u0442.  <\/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-258818","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/258818","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=258818"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/258818\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=258818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=258818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=258818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}