STMems_Standard_C_drivers icon indicating copy to clipboard operation
STMems_Standard_C_drivers copied to clipboard

How to make the code compatible for nrf52 nordic?

Open dimitraNats opened this issue 9 months ago • 1 comments

Device part numbers

I want to use LSM6DSOX on nRF52832 board of Nordic, and use I2C communication.

Question

I have trouble in making the code compatible for nrf52 and use twi module. Has anyone tried something similar or for another component maybe and have any ideas on how to achieve this?

dimitraNats avatar May 13 '24 09:05 dimitraNats

Here is my approach with SPI on nRF52/LIS2DH12:

  1. Define a structure for sensor in application, structure includes stmdev_ctx_t: https://github.com/ruuvi/ruuvi.drivers.c/blob/master/src/interfaces/acceleration/ruuvi_interface_lis2dh12.h#L157
  2. Initialise function pointers in sensor initialisation: https://github.com/ruuvi/ruuvi.drivers.c/blob/2555fc5c9725747084b1ab7c52b29e4a4b9dedab/src/interfaces/acceleration/ruuvi_interface_lis2dh12.c#L156
  3. Implement functions for SPI RW: https://github.com/ruuvi/ruuvi.drivers.c/blob/2555fc5c9725747084b1ab7c52b29e4a4b9dedab/src/interfaces/spi/ruuvi_interface_spi_lis2dh12.c#L18
  4. Call STM driver: https://github.com/ruuvi/ruuvi.drivers.c/blob/2555fc5c9725747084b1ab7c52b29e4a4b9dedab/src/interfaces/acceleration/ruuvi_interface_lis2dh12.c#L95

You can get away with a lot less of abstraction if you don't need to support various combinations of MCUs, sensors and buses.

ojousima avatar May 13 '24 09:05 ojousima

Here is my approach with SPI on nRF52/LIS2DH12:

  1. Define a structure for sensor in application, structure includes stmdev_ctx_t: https://github.com/ruuvi/ruuvi.drivers.c/blob/master/src/interfaces/acceleration/ruuvi_interface_lis2dh12.h#L157
  2. Initialise function pointers in sensor initialisation: https://github.com/ruuvi/ruuvi.drivers.c/blob/2555fc5c9725747084b1ab7c52b29e4a4b9dedab/src/interfaces/acceleration/ruuvi_interface_lis2dh12.c#L156
  3. Implement functions for SPI RW: https://github.com/ruuvi/ruuvi.drivers.c/blob/2555fc5c9725747084b1ab7c52b29e4a4b9dedab/src/interfaces/spi/ruuvi_interface_spi_lis2dh12.c#L18
  4. Call STM driver: https://github.com/ruuvi/ruuvi.drivers.c/blob/2555fc5c9725747084b1ab7c52b29e4a4b9dedab/src/interfaces/acceleration/ruuvi_interface_lis2dh12.c#L95

You can get away with a lot less of abstraction if you don't need to support various combinations of MCUs, sensors and buses.

Thank you very much! This helped a lot and now I can read data as expected

dimitraNats avatar May 14 '24 12:05 dimitraNats