2024-10-09 08:03 AM
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:
Thanks
Chris
2024-11-08 07:15 AM
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.
2024-11-11 01:51 PM - edited 2024-11-11 01:52 PM
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:
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