summaryrefslogtreecommitdiff
path: root/src/c/scilab-arduino/cmd_i2c_read_register
diff options
context:
space:
mode:
authorBrijeshcr2017-07-06 15:48:47 +0530
committerGitHub2017-07-06 15:48:47 +0530
commitea958d3c401761dcc24865d9639b2fab31038db8 (patch)
tree8cea93113a46d7015d1a10638778f92275a0ca94 /src/c/scilab-arduino/cmd_i2c_read_register
parentcb1d99232e521c34e9f0c271a6c4176cc7b9cbe4 (diff)
downloadScilab2C_fossee_old-ea958d3c401761dcc24865d9639b2fab31038db8.tar.gz
Scilab2C_fossee_old-ea958d3c401761dcc24865d9639b2fab31038db8.tar.bz2
Scilab2C_fossee_old-ea958d3c401761dcc24865d9639b2fab31038db8.zip
Revert "LinearAlgebra Function Added"
Diffstat (limited to 'src/c/scilab-arduino/cmd_i2c_read_register')
-rw-r--r--src/c/scilab-arduino/cmd_i2c_read_register/u8cmd_i2c_read_registers.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/c/scilab-arduino/cmd_i2c_read_register/u8cmd_i2c_read_registers.cpp b/src/c/scilab-arduino/cmd_i2c_read_register/u8cmd_i2c_read_registers.cpp
new file mode 100644
index 0000000..0a2ec2e
--- /dev/null
+++ b/src/c/scilab-arduino/cmd_i2c_read_register/u8cmd_i2c_read_registers.cpp
@@ -0,0 +1,26 @@
+#include "cmd_i2c_read_register.h"
+#include "Arduino.h"
+#include "Wire.h"
+
+uint16 u8cmd_i2c_read_registers(uint8 address, uint8 reg_adrs)
+{
+ long int reading;
+
+ Wire.beginTransmission(address); // transmit to device address
+ Wire.write(reg_adrs); // sets register pointer to reg_adrs position
+ Wire.endTransmission(); // stop transmitting
+
+ // request reading from sensor
+ Wire.requestFrom(address, 2); // request 2 bytes from slave device with address
+
+ // receive reading from sensor
+ if (2 <= Wire.available()) // if two bytes were received
+ {
+ reading = Wire.read(); // receive high byte (overwrites previous reading)
+ reading = reading << 8; // shift high byte to be high 8 bits
+ reading |= Wire.read(); // receive low byte as lower 8 bits
+ }
+
+ return(reading);
+
+}