You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In general each communication with a register on the accelerometer requires two bytes. The first byte sent is the address of the register you wish to read or write. The second byte is either the contents you wish to write into the register, or, if you're reading, the contents of the register being sent back to the processor.
Here's a bit of code I use to set the range on the LIS331HH (This, and a lot of other register finagling are contained in the .txt document I attached to a comment in the "Data Storage Efficiancy" discussion.
// Write to CTRL_REG4 register located at 0x23 to set Full Scale and some defaults
// 1xxxxxxx Set most significant bit to one to avoid updating data registers between reading the MSB and LSB of data
// x0xxxxxx Bit for selecting big or little endian - default is 0
// xx00xxxx Sets full scale to low range
// xx01xxxx Sets full scale to mid range
// xx11xxxx Sets full scale to high range
// xxxx0000 Default values
Wire.beginTransmission(HH); // Talk to the 331HH
Wire.write(0x23); //Writes the address of the register
// Use only one of the following three statements - this assumes most signifcant bit is 1 and lower four bits are 0
Wire.write(0x80); //Set Range to LOW
//Wire.write(0x90); //Set Range to MED
//Wire.write(0xB0); //Set Range to HIGH
Wire.endTransmission(false); // false causes a restart to be sent
By default data is written into the registers as soon as it is available. This leads to the chance that while you're reading the upper byte of data the accelerometer is putting new information into the lower byte of data, and then when you read the lower byte, you end up with a pair of data bytes from two different readings. Setting the most significant bit to 1, tells the accelerometer not to be changing either byte until they are both read, (or both over written if no reading attempt was made.
Pleasantly enough, on p.31-32 of your datasheet is shows the register for setting the range has the same address and is organized in a similar manner. There are some differences, so please consult the datasheet.
Now, here is a bit of code showing how to read that same register to see if it really contains what was just written to it:
// Read CTRL_REG4 register
Wire.beginTransmission(HH); // Talk to the 331HH
Wire.write(0x23); //Writes the address of the register
Wire.endTransmission(false); // false causes a restart to be sent
Wire.requestFrom(HH, 1); // Request 1 byte
if (Wire.available() > 0){
Serial.print("CTRL_REG4: ");
Serial.println(Wire.read(), HEX); // Print the contents of the register
} else {
Serial.println("No data received");
} // End of if(Wire.available()
In the code above HH was previously defined as the address of the accelerometer: #define HH 0x19 // Address for LIS331HH 6/12/24
The text was updated successfully, but these errors were encountered:
In general each communication with a register on the accelerometer requires two bytes. The first byte sent is the address of the register you wish to read or write. The second byte is either the contents you wish to write into the register, or, if you're reading, the contents of the register being sent back to the processor.
Here's a bit of code I use to set the range on the LIS331HH (This, and a lot of other register finagling are contained in the .txt document I attached to a comment in the "Data Storage Efficiancy" discussion.
By default data is written into the registers as soon as it is available. This leads to the chance that while you're reading the upper byte of data the accelerometer is putting new information into the lower byte of data, and then when you read the lower byte, you end up with a pair of data bytes from two different readings. Setting the most significant bit to 1, tells the accelerometer not to be changing either byte until they are both read, (or both over written if no reading attempt was made.
Pleasantly enough, on p.31-32 of your datasheet is shows the register for setting the range has the same address and is organized in a similar manner. There are some differences, so please consult the datasheet.
Now, here is a bit of code showing how to read that same register to see if it really contains what was just written to it:
In the code above HH was previously defined as the address of the accelerometer:
#define HH 0x19 // Address for LIS331HH 6/12/24
The text was updated successfully, but these errors were encountered: