cancel
Showing results for 
Search instead for 
Did you mean: 

Tilt function with LSM6DS3 not showing the right values. Am i reading it wrong ?

EJohn.3
Associate

Hi, it is possible that the LSM6DS3 may be obsolete but i really need some help in detecting

a tilt.

I have read the AN4650 application note and followed the instructions.

the tilt example setup is pretty simple.

// Tilt detection setup
//
//***************************************************************************//
void LSM6DS3::tiltDetect()
{
  // embedded function Tilt detecton CTRL10_C - 00111000
  writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, 0x20); // turn on the accelerometer/ ODR_XL=26Hz
  writeRegister(LSM6DS3_ACC_GYRO_CTRL10_C, 0x3C); // enable embedded functions
  writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG, 0x20); // enable tilt detection
  writeRegister(LSM6DS3_ACC_GYRO_MD1_CFG, 0x02);  // tilt detector interrupt driven to INT1 pin
  writeRegister(LSM6DS3_ACC_GYRO_CTRL10_C, 0x38);
  
}

and then assuming that i don't want to use INT1 and INT2,

I can check the value of TILT_IA bit of the FUNC_SRC register

which I implemented it like this

// Tilt detection check
//
//***************************************************************************//
uint8_t LSM6DS3::readTilt( void )
{
  uint8_t output;
  readRegister(&output, LSM6DS3_ACC_GYRO_FUNC_SRC);
  return output;
}

Alright, so now, to my understanding, I know readRegister function reads a byte

of the FUNC_SRC register(unless i'm wrong ??) which itself is also a byte but how do i get the value of

the 5'th bit [BIT5] which is TILT_IA from my reading ???

By the way, I'm using an arduino.

This is the readRegister function.

ignore the SPI_MODE section

//
//  ReadRegister
//
//  Parameters:
//    *outputPointer -- Pass &variable (address of) to save read data to
//    offset -- register to read
//
//****************************************************************************//
status_t LSM6DS3Core::readRegister(uint8_t* outputPointer, uint8_t offset) {
	//Return value
	uint8_t result = 0;
	uint8_t numBytes = 1;
	status_t returnError = IMU_SUCCESS;
 
	switch (commInterface) {
 
	case I2C_MODE:
		Wire.beginTransmission(I2CAddress);
		Wire.write(offset);
		if( Wire.endTransmission() != 0 )
		{
			returnError = IMU_HW_ERROR;
		}
		Wire.requestFrom(I2CAddress, numBytes);
		while ( Wire.available() ) // slave may send less than requested
		{
			result = Wire.read(); // receive a byte as a proper uint8_t
		}
		break;
 
	case SPI_MODE:
		// take the chip select low to select the device:
		digitalWrite(chipSelectPin, LOW);
		// send the device the register you want to read:
		SPI.transfer(offset | 0x80);  //Ored with "read request" bit
		// send a value of 0 to read the first byte returned:
		result = SPI.transfer(0x00);
		// take the chip select high to de-select:
		digitalWrite(chipSelectPin, HIGH);
		
		if( result == 0xFF )
		{
			//we've recieved all ones, report
			returnError = IMU_ALL_ONES_WARNING;
		}
		break;
 
	default:
		break;
	}
 
	*outputPointer = result;
	return returnError;
}

Kind regards,

Johnson

1 ACCEPTED SOLUTION

Accepted Solutions
JWu.12
Associate III

Hi Johnson,

>>how do i get the value of the 5'th bit [BIT5] which is TILT_IA from my reading ???

Since the function returns you a uint_8 value (typically in decimal format), you have to convert it into binary and then apply an and mask bin 0010000 that highlights the bit5 TILT_IA of the FUNC_SRC (53h) reg.

You can also find an official example of the use of the Tilt function for the LSM6DS3 on Github:

https://github.com/STMicroelectronics/STMems_Standard_C_drivers/blob/master/lsm6ds3_STdC/examples/lsm6ds3_tilt.c

View solution in original post

1 REPLY 1
JWu.12
Associate III

Hi Johnson,

>>how do i get the value of the 5'th bit [BIT5] which is TILT_IA from my reading ???

Since the function returns you a uint_8 value (typically in decimal format), you have to convert it into binary and then apply an and mask bin 0010000 that highlights the bit5 TILT_IA of the FUNC_SRC (53h) reg.

You can also find an official example of the use of the Tilt function for the LSM6DS3 on Github:

https://github.com/STMicroelectronics/STMems_Standard_C_drivers/blob/master/lsm6ds3_STdC/examples/lsm6ds3_tilt.c