xxx
Revision 7:704790280bbe, committed 2021-09-30
- Comitter:
- gr66
- Date:
- Thu Sep 30 09:37:35 2021 +0000
- Parent:
- 6:132a63741359
- Commit message:
- Fusion3
Changed in this revision
| LSM6DS33_GR1.cpp | Show annotated file Show diff for this revision Revisions of this file |
| LSM6DS33_GR1.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/LSM6DS33_GR1.cpp Fri Jul 02 18:15:15 2021 +0000
+++ b/LSM6DS33_GR1.cpp Thu Sep 30 09:37:35 2021 +0000
@@ -397,9 +397,9 @@
CTRL2_G,
0
};
-
+/*
// Set low power based on ODR, else keep sensor on high performance
- if(gRate == G_ODR_13_BW_0 | gRate == G_ODR_26_BW_2 | gRate == G_ODR_52_BW_16) {
+ if(gRate == G_ODR_13 | gRate == G_ODR_26 | gRate == G_ODR_52) {
char cmdLow[2] = {
CTRL7_G,
1
@@ -414,7 +414,7 @@
i2c.write(xgAddress, cmdLow, 2);
}
-
+*/
// Write the address we are going to read from and don't end the transaction
i2c.write(xgAddress, cmd, 1, true);
// Read in all the 8 bits of data
@@ -436,7 +436,7 @@
CTRL1_XL,
0
};
-
+/*
// Set low power based on ODR, else keep sensor on high performance
if(aRate == A_ODR_13 | aRate == A_ODR_26 | aRate == A_ODR_52) {
char cmdLow[2] = {
@@ -453,7 +453,7 @@
i2c.write(xgAddress, cmdLow, 2);
}
-
+*/
// Write the address we are going to read from and don't end the transaction
i2c.write(xgAddress, cmd, 1, true);
// Read in all the 8 bits of data
@@ -519,12 +519,12 @@
gy_off=gy_off+gy;
gz_off=gz_off+gz;
//
-
+
gxoll=gxoll+(int32_t)gx_raw;
gyoll=gyoll+(int32_t)gy_raw;
gzoll=gzoll+(int32_t)gz_raw;
-
-
+
+
//wait(0.01);
}
gx_off=gx_off/iter;
@@ -534,7 +534,7 @@
gxoll=gxoll/iter;
gyoll=gyoll/iter;
gzoll=gzoll/iter;
-
+
//
gxol=(gxoll&0x00FF);
gxoh=(gxoll>>8);
@@ -542,6 +542,24 @@
gyoh=(gyoll>>8);
gzol=(gzoll&0x00FF);
gzoh=(gzoll>>8);
-
+
}
+char LSM6DS33::readReg(char add_reg)
+{
+ char data[1];
+ char subAddress = add_reg;
+ i2c.write(xgAddress, &subAddress, 1, true);
+ i2c.read(xgAddress, data, 1);
+
+ return data[0];
+}
+void LSM6DS33::writeReg(char add_reg,char data)
+{
+ // The start of the addresses we want to read from
+ char cmd[2] = {
+ add_reg,
+ data
+ };
+ i2c.write(xgAddress, cmd, 2);
+}
--- a/LSM6DS33_GR1.h Fri Jul 02 18:15:15 2021 +0000
+++ b/LSM6DS33_GR1.h Thu Sep 30 09:37:35 2021 +0000
@@ -95,9 +95,9 @@
enum gyro_odr
{ // ODR (Hz) --- Cutoff
G_POWER_DOWN = 0x00, // 0 0
- G_ODR_13_BW_0 = 0x10, // 12.5 0.0081 low power
- G_ODR_26_BW_2 = 0x20, // 26 2.07 low power
- G_ODR_52_BW_16 = 0x30, // 52 16.32 low power
+ G_ODR_13 = 0x10, // 12.5 0.0081 low power
+ G_ODR_26 = 0x20, // 26 2.07 low power
+ G_ODR_52 = 0x30, // 52 16.32 low power
G_ODR_104 = 0x40, // 104
G_ODR_208 = 0x50, // 208
G_ODR_416 = 0x60, // 416
@@ -257,6 +257,9 @@
/** calibration() -- Calculate the offset of the accel and the gyro
*/
void calibration( int16_t iter);
+ //
+ char readReg(char add_reg);
+ void writeReg(char add_reg,char data);
private:
/** xgAddress store the I2C address