Shop OBEX P1 Docs P2 Docs Learn Events
LSM9DS1 example from ST's C driver library working with Fastspin's FlexC — Parallax Forums

LSM9DS1 example from ST's C driver library working with Fastspin's FlexC

RaymanRayman Posts: 13,861
edited 2020-10-04 19:04 in Propeller 2
Here's another example of how nice Fastspin's FlexC C compiler is to work with...

The LSM9DS1 is a 9DOF MEMS device from ST with 3-axis accelerometer, 3-axis gyro and 3-axis magnetometer, all in one device.

By just adding in P2 specific i2c code got the code ST's C library to run.
There are a lot of other driver that that will presumable also work: https://github.com/STMicroelectronics/STMems_Standard_C_drivers

One great thing is that I was able to use the Spin2 i2c driver from OBEX (Thanks @JonnyMac !).
Being able to use .Spin2 code directly as if it were a C++ class is a really, really nice feature of FlexC.

The self-test code just says some stuff and then pass at the end. But, the "lsm9ds1_read_data_polling_P2.c" example is perfect for my needs.
Gives floating point output in units of mg, mdps and mG (Screenshot attached).
It runs very fast, I had to put in a pause so I could actually read the output in between samples...

Code attached.
979 x 512 - 48K

Comments

  • Very nice to know that FastSpin is okay with Spin2 code that includes inline PASM. Well done, @ersmith.
  • RaymanRayman Posts: 13,861
    edited 2020-10-04 19:30
    BTW: Working on this code in Visual Studio is great.
    Here's a screen shot of a part the code that I added to read and write over I2C using the Spin2 object.

    VS has really cool features like "peak definition" and great search options that save a lot of time figuring things out...
    1654 x 1516 - 204K
Sign In or Register to comment.