From 2869bc7cca7eeff153eca7cd6d74a1196dbb42bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=85=95=E7=82=8E?= <29385962@qq.com> Date: Sat, 1 Jan 2022 11:47:49 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20arduino/?= =?UTF-8?q?Betas/RGB=5FV1.1.1/i2c.ino?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino/Betas/RGB_V1.1.1/i2c.ino | 63 -------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 arduino/Betas/RGB_V1.1.1/i2c.ino diff --git a/arduino/Betas/RGB_V1.1.1/i2c.ino b/arduino/Betas/RGB_V1.1.1/i2c.ino deleted file mode 100644 index dacc412..0000000 --- a/arduino/Betas/RGB_V1.1.1/i2c.ino +++ /dev/null @@ -1,63 +0,0 @@ -/* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved. - - This software may be distributed and modified under the terms of the GNU - General Public License version 2 (GPL2) as published by the Free Software - Foundation and appearing in the file GPL2.TXT included in the packaging of - this file. Please note that GPL2 Section 2[b] requires that all works based - on this software must also be made publicly available under the terms of - the GPL2 ("Copyleft"). - - Contact information - ------------------- - - Kristian Lauszus, TKJ Electronics - Web : http://www.tkjelectronics.com - e-mail : kristianl@tkjelectronics.com - */ - -const uint8_t IMUAddress = 0x68; // AD0 is logic low on the PCB -const uint16_t I2C_TIMEOUT = 1000; // Used to check for errors in I2C communication - -uint8_t i2cWrite(uint8_t registerAddress, uint8_t data, bool sendStop) { - return i2cWrite(registerAddress, &data, 1, sendStop); // Returns 0 on success -} - -uint8_t i2cWrite(uint8_t registerAddress, uint8_t *data, uint8_t length, bool sendStop) { - Wire.beginTransmission(IMUAddress); - Wire.write(registerAddress); - Wire.write(data, length); - uint8_t rcode = Wire.endTransmission(sendStop); // Returns 0 on success - if (rcode) { - Serial.print(F("i2cWrite failed: ")); - Serial.println(rcode); - } - return rcode; // See: http://arduino.cc/en/Reference/WireEndTransmission -} - -uint8_t i2cRead(uint8_t registerAddress, uint8_t *data, uint8_t nbytes) { - uint32_t timeOutTimer; - Wire.beginTransmission(IMUAddress); - Wire.write(registerAddress); - uint8_t rcode = Wire.endTransmission(false); // Don't release the bus - if (rcode) { - Serial.print(F("i2cRead failed: ")); - Serial.println(rcode); - return rcode; // See: http://arduino.cc/en/Reference/WireEndTransmission - } - Wire.requestFrom(IMUAddress, nbytes, (uint8_t)true); // Send a repeated start and then release the bus after reading - for (uint8_t i = 0; i < nbytes; i++) { - if (Wire.available()) - data[i] = Wire.read(); - else { - timeOutTimer = micros(); - while (((micros() - timeOutTimer) < I2C_TIMEOUT) && !Wire.available()); - if (Wire.available()) - data[i] = Wire.read(); - else { - Serial.println(F("i2cRead timeout")); - return 5; // This error value is not already taken by endTransmission - } - } - } - return 0; // Success -}