Skip to main content
Associate
October 9, 2024
Question

h3lis331dl trigger and data

  • October 9, 2024
  • 1 reply
  • 911 views

Hi,

I am using h3lis331dl accelerometer with imx8mp and also using the default st_accel and st_accel_i2c drivers in Linux. Most of the part works correctly. 

I am using udevadm to monitor the trigger in C# code.

/bin/udevadm monitor iio:device0

This works when I manually trigger with the command "sudo udevadm trigger /sys/bus/iio/devices/iio:device0"

Is it the right way to monitor the trigger/interrupt?

Also, in_accel_*_raw and in_accel_*_scale files are available in /sys/bus/iio/devices/iio:device0 directory. How can I calculate the acceleration with the raw, scale and mount_matrix? 

Could someone please help me?

Here is the device tree node:

 

accelerometer@19 {
compatible = "st,h3lis331dl-accel"; 
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_accel>;
reg = <0x19>;
        st,drdy-int-pin = <1>;
vdd-supply = <&reg_board>;
vddio-supply = <&reg_board>; 
interrupt-parent = <&gpio3>;
interrupts = <29 IRQ_TYPE_LEVEL_HIGH>, <28 IRQ_TYPE_LEVEL_HIGH>;
};

Thanks

Chris

1 reply

Federica Bossi
Technical Moderator
November 8, 2024

Hi @CHRISTOA ,

 

The drivers you are using are not ours and thus we can't support you.

However you can look at those and I can help you if you have any further questions.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
CHRISTOAAuthor
Associate
November 11, 2024

Hi @Federica Bossi,

Thank you for your help. I have included your drivers into our Yocto build and now h3lis331dl (st_h3lis331dl, st_h3lis331dl_i2c, st_h3lis331dl_spi) drivers are loading correctly.

Also, I am able to read the data. But I am getting the interrupt continuously. I am getting the interrupt only once during startup and after that nothing happens.

Here is my device tree:

accelerometer@19 {
compatible = "st,h3lis331dl";
reg = <0x19>;
        st,drdy-int-pin = <1>;
vdd-supply = <&reg_board>;
vddio-supply = <&reg_board>; 
interrupt-parent = <&gpio4>;
interrupts = <24 IRQ_TYPE_EDGE_FALLING>, <26 IRQ_TYPE_EDGE_FALLING>;
};

Sample C# Code:

_i2cDevice = I2cDevice.Create(new I2cConnectionSettings(ACCELEROMETER_I2C_BUS, ACCELEROMETER_I2C_REGISTER));


_i2cDevice?.Write(new byte[] { 0x25, 0x02 });
_i2cDevice?.Write(new byte[] { 0x20, 0x57 });
_i2cDevice?.Write(new byte[] { 0x22, 0x40 });
_i2cDevice?.Write(new byte[] { 0x23, 0x00 });
_i2cDevice?.Write(new byte[] { 0x24, 0x08 });
_i2cDevice?.Write(new byte[] { 0x33, 0x02 });
_i2cDevice?.Write(new byte[] { 0x32, 0x01 });
_i2cDevice?.Write(new byte[] { 0x30, 0x2a });

_gpioController = new(PinNumberingScheme.Logical, new LibGpiodDriver(3));
_gpioController.OpenPin(ACCELEROMETER_GPIO_PIN, PinMode.Input);
_gpioController.RegisterCallbackForPinValueChangedEvent(ACCELEROMETER_GPIO_PIN, PinEventTypes.Falling | PinEventTypes.Rising, PinChangeEventHandler);

private void PinChangeEventHandler(object sender, PinValueChangedEventArgs pinValueChangedEventArgs)
{
_logger.LogInformation($"AccelerometerService::PinChangeEventHandler:{pinValueChangedEventArgs.ChangeType}");

if (pinValueChangedEventArgs.ChangeType == PinEventTypes.Rising)
{
try
{
Vector3 acceleration = (Vector3)_accelerometer?.Acceleration;
_accel = Math.Sqrt(acceleration.X * acceleration.X + acceleration.Y * acceleration.Y + acceleration.Z * acceleration.Z);
_logger.LogInformation($"X:{acceleration.X:0.0000} Y:{acceleration.Y:0.0000} Z:{acceleration.Z:0.0000} G:{_accel:0.0000}".PadRight(30));
}
catch (Exception e)
{
_logger.LogInformation(e.Message);
}
}
else
{
_logger.LogInformation("AccelerometerService::PinChangeEventHandler Released");
}
}

Can you please help me how to get the interrupt correctly?

Thanks

Chris