STMems_Standard_C_drivers
STMems_Standard_C_drivers copied to clipboard
How to make the code compatible for nrf52 nordic?
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?
Here is my approach with SPI on nRF52/LIS2DH12:
- 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
- Initialise function pointers in sensor initialisation: https://github.com/ruuvi/ruuvi.drivers.c/blob/2555fc5c9725747084b1ab7c52b29e4a4b9dedab/src/interfaces/acceleration/ruuvi_interface_lis2dh12.c#L156
- Implement functions for SPI RW: https://github.com/ruuvi/ruuvi.drivers.c/blob/2555fc5c9725747084b1ab7c52b29e4a4b9dedab/src/interfaces/spi/ruuvi_interface_spi_lis2dh12.c#L18
- 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.
Here is my approach with SPI on nRF52/LIS2DH12:
- 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
- Initialise function pointers in sensor initialisation: https://github.com/ruuvi/ruuvi.drivers.c/blob/2555fc5c9725747084b1ab7c52b29e4a4b9dedab/src/interfaces/acceleration/ruuvi_interface_lis2dh12.c#L156
- Implement functions for SPI RW: https://github.com/ruuvi/ruuvi.drivers.c/blob/2555fc5c9725747084b1ab7c52b29e4a4b9dedab/src/interfaces/spi/ruuvi_interface_spi_lis2dh12.c#L18
- 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