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

LIS2DH12 - lis2dh12_data_read() constant value

Hi, I have use nrf driver_ext / LIS2DH12 sensor driver to read accelerometer data

I can able to link the driver with nrf_twi_sensor and nrf_twi_mngr code.

I can able to read the WHO_AM_I

but the lis2dh12_data_read() is not working properly for me .

How to config the sensor . is there and example code available to read the LIS2DH12 raw data.

i have used these lined in the code.

void acc_print_data()
{
	ret_code_t err_code;
 //       lis2dh12_data_t m_sample;

	err_code = lis2dh12_data_read(&m_lis2dh12, 0x00, m_sample, LIS2DH12_MIN_QUEUE_SIZE);
	APP_ERROR_CHECK(err_code);

	for (uint8_t i = 0; i < LIS2DH12_MIN_QUEUE_SIZE; i++)
        NRF_LOG_INFO("%d %d %d", m_sample[i].x, m_sample[i].y, m_sample[i].z);

}


int main(void)
{
    ret_code_t err_code;

    log_init();
    bsp_board_init(BSP_INIT_LEDS);

      lfclk_config();

    bsp_config();

    err_code = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(err_code);

    NRF_LOG_RAW_INFO("\r\nTWI master example started. \r\n");
    NRF_LOG_FLUSH();
    twi_config();
    err_code = lis2dh12_init(&m_lis2dh12);
	APP_ERROR_CHECK(err_code);
 
  // data acquisition configuration: 10HZ 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_10HZ, true, true, true, true, LIS2DH12_SCALE_2G, 0);
	err_code = lis2dh12_cfg_commit(&m_lis2dh12);
	APP_ERROR_CHECK(err_code);
        acc_print_data();
        	// FIFO configuration: enable FIFO, streaming mode, int1 pin used, 32 values watermark
	LIS2DH12_FIFO_CFG(m_lis2dh12, 1, LIS2DH12_STREAM, 0, LIS2DH12_MIN_QUEUE_SIZE);
	err_code = lis2dh12_cfg_commit(&m_lis2dh12);
	APP_ERROR_CHECK(err_code);

    
    while (true)
    {
        //nrf_pwr_mgmt_run();
        	// avoid accessing the registers to fast, value arbitrarily chosen
		nrf_delay_ms(1000);
                err_code = lis2dh12_who_am_i_read(&m_lis2dh12, print_identity, &m_data);
        APP_ERROR_CHECK(err_code);
		// debug: check FIFO_SRC register to see the FSS value rise
		//err_code = lis2dh12_fifo_src_read(&m_lis2dh12, 0x00, &m_data);
		//APP_ERROR_CHECK(err_code);
		//NRF_LOG_INFO("WTM: %d OVN: %d EMPTY: %d FSS: %2d ", (m_data & 0b10000000), (m_data & 0b01000000), (m_data & 0b00100000), (m_data & 0b0001111));

		//// do not try to access FIFO values if watermark was not reached yet
		//if (!data_available)
		//	continue;

		// collect and print the data
		//acc_print_data();
		// "reset" interrupt
		//data_available = 0;
		//nrf_drv_gpiote_out_toggle(PIN_OUT);
                		// avoid accessing the registers to fast, value arbitrarily chosen
		//nrf_delay_ms(500);
		// debug: check FIFO_SRC register to see the FSS value rise
		//err_code = lis2dh12_fifo_src_read(&m_lis2dh12, 0x00, &m_data);
		//APP_ERROR_CHECK(err_code);
		//NRF_LOG_INFO("WTM: %d OVN: %d EMPTY: %d FSS: %2d ", (m_data & 0b10000000), (m_data & 0b01000000), (m_data & 0b00100000), (m_data & 0b0001111));

		//// do not try to access FIFO values if watermark was not reached yet
		//if (!data_available)
		//	continue;

		// collect and print the data
		//acc_print_data();
		// "reset" interrupt
		//data_available = 0;

		NRF_LOG_FLUSH();
    }
    
}

Related