dipk11
Junior Member level 2
I have interfaced Lis3dh on my nrf52 board using i2c interface. I am able to communicate with the accelerometer and get some x,y,z reading.This data is later sent to an app over BLE. I have tried 6.3.2 section from the application notes AN3308 of the LIS3DH sensor. I have tried to change the sensitivity and the threshold but still no change. I am using latched mode of the interrupt and reading the status register once the interrupt flag is set.
I constantly get interrupts even without shaking the device. Also i have noticed that the data makes no sense, it keeps on fluctuating even at rest.
I have noticed that, if i dont use latched interrupt, the interrupt doesnt occur.
Below is the main file code of my project. I do all the initialisations and accelerometer configuration, then go in an infinite loop for the interrupt yo occur. I set a flag interruptFlag in the ISR of INT1 pin. This flag is being polled in the main loop.
Below is the data configuration function for the Lis3dh
Please let me know if i have done any wrong settings. Also the delay between the data configuration is not mentioned in the DS as well as Application notes.
I constantly get interrupts even without shaking the device. Also i have noticed that the data makes no sense, it keeps on fluctuating even at rest.
I have noticed that, if i dont use latched interrupt, the interrupt doesnt occur.
Below is the main file code of my project. I do all the initialisations and accelerometer configuration, then go in an infinite loop for the interrupt yo occur. I set a flag interruptFlag in the ISR of INT1 pin. This flag is being polled in the main loop.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 int main(void) { uint32_t err_code; int j=0; bool state =false; nrf_gpio_cfg_input(13, NRF_GPIO_PIN_PULLDOWN); //Pin 13 for interrupt pin uint8_t uiStatus=0; // Initialize. log_init(); power_management_init(); ble_stack_init(); advertising_init(); gpio_init(); //interrupt pin INT1 initialisation for change in state event twi_init(); //i2c initialisation data_Configuration(); //configure the LIS3dh nrf_delay_ms(500); read_Status_Reg(); NRF_LOG_INFO("Waiting for interrupt"); // Enter main loop. for (;;) { nrf_delay_ms(50); write_interrupt_cfg(); nrf_delay_ms(50); if (interruptFlag) { interruptFlag=false; // read_Ref_Reg(); //read reference register // nrf_delay_ms(500); read_Status_Reg(); //read status register nrf_delay_ms(500); read_sensor_data(); //read sensor data registers-all 6 for (int i = 8; i < 14; i++) { ble_data[i]=dataArray[j]; j++; } sd_ble_gap_adv_stop(m_adv_handle); //manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER; manuf_specific_data.data.p_data = (uint8_t *)ble_data; manuf_specific_data.data.size = 14; advdata.name_type = BLE_ADVDATA_NO_NAME; advdata.p_manuf_specific_data = &manuf_specific_data; ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len); sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params); advertising_start(); for (int i = 8; i < 14; i++) { NRF_LOG_INFO("Data %d %d", i, ble_data[i]); NRF_LOG_PROCESS(); } } idle_state_handle(); } }
Below is the data configuration function for the Lis3dh
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 void data_Configuration(void) { ret_code_t err_code; nrf_delay_ms(500); /* Writing to CTRL_REG1 to use all 3 axis----1Hz Normal Mode. */ uint8_t reg1[2] = {CTRL_REG1, 0x57}; err_code = nrf_drv_twi_tx(&m_twi, LIS3DH_ADDR, reg1, sizeof(reg1), false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); nrf_delay_ms(500); uint8_t reg2[2] = {CTRL_REG2, 0x00}; //no high pass filter err_code = nrf_drv_twi_tx(&m_twi, LIS3DH_ADDR, reg2, sizeof(reg2), false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); nrf_delay_ms(500); uint8_t reg3[2] = {CTRL_REG3, 0x40}; //interrupt on int1 err_code = nrf_drv_twi_tx(&m_twi, LIS3DH_ADDR, reg3, sizeof(reg3), false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); nrf_delay_ms(500); uint8_t reg4[2] = {CTRL_REG4, 0x00}; // +/- 2g, LSB first, err_code = nrf_drv_twi_tx(&m_twi, LIS3DH_ADDR, reg4, sizeof(reg4), false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); nrf_delay_ms(500); uint8_t reg_Ref[2] = {REFERENCE, 0x00}; //reference reg err_code = nrf_drv_twi_tx(&m_twi, LIS3DH_ADDR, reg_Ref, sizeof(reg_Ref), false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); nrf_delay_ms(500); uint8_t reg5[2] = {CTRL_REG5, 0x08}; // interrupt request latched err_code = nrf_drv_twi_tx(&m_twi, LIS3DH_ADDR, reg5, sizeof(reg5), false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); nrf_delay_ms(500); uint8_t reg6[2] = {CTRL_REG6, 0x00}; err_code = nrf_drv_twi_tx(&m_twi, LIS3DH_ADDR, reg6, sizeof(reg6), false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); nrf_delay_ms(1000); uint8_t reg_ths[2] = {INT1_THS,0x10}; // threshold 250mg err_code = nrf_drv_twi_tx(&m_twi, LIS3DH_ADDR, reg_ths, sizeof(reg_ths), false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); nrf_delay_ms(1000); uint8_t reg_int[2] = {INT1_DURATION, 0x00}; // duration =0 err_code = nrf_drv_twi_tx(&m_twi, LIS3DH_ADDR, reg_int, sizeof(reg_int), false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); nrf_delay_ms(1000); uint8_t reg_int_cfg[2] = {INT1_CFG, 0x3F}; // AOI=0 and x,y,z events err_code = nrf_drv_twi_tx(&m_twi, LIS3DH_ADDR, reg_int_cfg, sizeof(reg_int_cfg), false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); }
Please let me know if i have done any wrong settings. Also the delay between the data configuration is not mentioned in the DS as well as Application notes.
Last edited by a moderator: