This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Issues working with lis2dh12 in FIFO mode

Hi

I'm working on a project interfacing the nRF52840 board with the lis2dh12 accelerometer

I'm using SDK 15.3, basing my code on the provided driver and information I've found here

I've used the TWI manager configuration native to the example

the issue I'm encountering is that it seems like the accelerometer stops collecting data after the first time I'm reading from it

the datasheet states that in FIFO mode, it requires a reset to reenable FIFO mode

I thought that calling LIS2DH12_FIFO_CFG and committing the configuration to the device will do the trick, but it doesn't seem to fix the issue

my configuration:

const nrf_drv_twi_config_t twi_instance_config = {
		.scl				= ACC_SCL,
		.sda				= ACC_SDA,
		.frequency			= NRF_DRV_TWI_FREQ_100K,
		.interrupt_priority	= APP_IRQ_PRIORITY_HIGH,
		.clear_bus_init		= false
	};

	errorCode = nrf_twi_mngr_init(&m_nrf_twi_mngr, &twi_instance_config);
	APP_ERROR_CHECK(errorCode);

	errorCode = nrf_twi_sensor_init(&m_nrf_twi_sensor);
	APP_ERROR_CHECK(errorCode);

	errorCode = lis2dh12_init(&m_lis2dh12);
	APP_ERROR_CHECK(errorCode);

	// data acquisition configuration: 100HZ sample rate, low power mode, x axis, y axis, z axis, values in range -2g <-> +2g, disable high resolution mode (in this case step size is 256)
	LIS2DH12_DATA_CFG(m_lis2dh12, LIS2DH12_ODR_100HZ, false, true, true, true, LIS2DH12_SCALE_2G, false);
	errorCode = lis2dh12_cfg_commit(&m_lis2dh12);
	APP_ERROR_CHECK(errorCode);

	// FIFO configuration: enable FIFO, FIFO mode, int1 pin used, 32 values watermark
	LIS2DH12_FIFO_CFG(m_lis2dh12, true, LIS2DH12_FIFO, false, LIS2DH12_MIN_QUEUE_SIZE);
	errorCode = lis2dh12_cfg_commit(&m_lis2dh12);
	APP_ERROR_CHECK(errorCode);

	// interrupt configurataion:
	LIS2DH12_INT1_PIN_CFG(m_lis2dh12, false, enableInterrupts, false, false, false, enableInterrupts, true, false);
	errorCode = lis2dh12_cfg_commit(&m_lis2dh12);
	APP_ERROR_CHECK(errorCode);

and after data read is finished, I'm using the same call to LIS2DH12_FIFO_CFG with the same configuration

Is there something I'm missing here?

Is there any example code working with FIFO mode?

any and all help would be appreciated

Parents Reply
  • The code Mojo showed you is a generic lis2dh12 driver.  It works with both i2c and spi.  It works with any mcu from nRF5x series to STM32.  

    Here is how to use with i2c. 

    static const I2CCFG s_I2cCfg = {
    	.DevNo = I2C_DEVNO,
    	.Pins = {
    		{I2C_SDA_PORT, I2C_SDA_PIN, I2C_SDA_PINOP, IOPINDIR_BI, IOPINRES_PULLUP, IOPINTYPE_NORMAL},	// SDA
    		{I2C_SCL_PORT, I2C_SCL_PIN, I2C_SCL_PINOP, IOPINDIR_OUTPUT, IOPINRES_PULLUP, IOPINTYPE_NORMAL},	// SCL
    	},
    	.Rate = 100000,
    	.Mode = I2CMODE_MASTER,
    	.MaxRetry = 5,
    };
    
    I2C g_I2c;
    
    static const ACCELSENSOR_CFG s_AccelCfg = {
    	.DevAddr = LIS2DH12_I2C_DEVADDR,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 10000,
    	.Scale = 2,
    	.bInter = true,
    };
    
    AccelLis2dh12 g_Accel;
    
    void main()
    {
       g_I2C.Init(s_I2cCfg);
       g_Accel.Init(s_AccelCfg, &g_I2C);
    }

    To use with SPI, replace the I2C object with SPI object. As simple as that.

    That driver works with fifo mode. you can cherry pick the code you need.

    Other example using an Invensense IMU and stream it to Thingy App using the same SPI & I2C interface object. 

    github.com/.../BlueIOThingy

    Other sensor example including BMI160 with same SPI, I2C interface.

    https://github.com/IOsonata/IOsonata/blob/master/exemples/sensor/mot_sensor_demo.cpp

    You can browse the repo for more examples

Children
No Data
Related