Hi, I'm a beginner of Firmware Engineering and facing an issue on programming of sensor module.
I am using a sensor as IIS2DLPC made by STM, and board is nrf52840 dk board.
I'm using twi SDK as 15.3.0 version
This is what I'm using as function to get data from sensor
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len) { nrf_twi_sensor_reg_read(&m_nrf_twi_sensor, II_ADDR, reg, NULL, bufp, len); NRF_LOG_INFO("TWI event number: %d", (int)m_twi_evt_counter); m_twi_evt_counter++; return 0; }
and while I'm using this function in sensor initializing, it works well
void platform_init(void) { ret_code_t err_code; iis2dlpc_device_id_get(&dev_ctx, &whoamI); // do { // if(whoamI != IIS2DLPC_ID){ // printf("\r\ndevice_id_get failed\r\n"); // } // nrf_delay_ms(400); // iis2dlpc_device_id_get(&dev_ctx, &whoamI); // } while(whoamI != IIS2DLPC_ID); iis2dlpc_reset_set(&dev_ctx, PROPERTY_ENABLE); do { iis2dlpc_reset_get(&dev_ctx, &rst); } while (rst); iis2dlpc_block_data_update_set(&dev_ctx, PROPERTY_ENABLE); iis2dlpc_full_scale_set(&dev_ctx, IIS2DLPC_16g); iis2dlpc_filter_path_set(&dev_ctx, IIS2DLPC_LPF_ON_OUT); iis2dlpc_filter_bandwidth_set(&dev_ctx, IIS2DLPC_ODR_DIV_10); iis2dlpc_power_mode_set(&dev_ctx, IIS2DLPC_HIGH_PERFORMANCE_LOW_NOISE); iis2dlpc_data_rate_set(&dev_ctx, IIS2DLPC_XL_ODR_100Hz); printf("\r\nall settings are completed\r\n"); err_code = app_timer_create(&m_timer_II, APP_TIMER_MODE_REPEATED, timer_handler_II); APP_ERROR_CHECK(err_code); err_code = app_timer_start(m_timer_II, APP_TIMER_TICKS(400), NULL); APP_ERROR_CHECK(err_code); }
but when I use it with app_timer function, it goes to error which I explained on the subject of this ticket.
following code is call_back function of timer
void timer_handler_II(void * p_context) { uint8_t reg_init; iis2dlpc_flag_data_ready_get(&dev_ctx, ®_init); if(reg_init) { memset(data_raw_acceleration[0].u8bit, 0x00, 3 * sizeof(int16_t)); memset(data_raw_acceleration[1].u8bit, 0x00, 3 * sizeof(int16_t)); memset(data_raw_acceleration[2].u8bit, 0x00, 3 * sizeof(int16_t)); iis2dlpc_acceleration_raw_get(&dev_ctx, data_raw_acceleration[0].u8bit); iis2dlpc_acceleration_rawY_get(&dev_ctx, data_raw_acceleration[1].u8bit); iis2dlpc_acceleration_rawZ_get(&dev_ctx, data_raw_acceleration[2].u8bit); acceleration_mg[0] = iis2dlpc_from_fs16_lp1_to_mg(data_raw_acceleration[0].i16bit[0]); acceleration_mg[1] = iis2dlpc_from_fs16_lp1_to_mg(data_raw_acceleration[1].i16bit[0]); acceleration_mg[2] = iis2dlpc_from_fs16_lp1_to_mg(data_raw_acceleration[2].i16bit[0]); current_value[0] = (int)(acceleration_mg[0]); current_value[1] = (int)(acceleration_mg[1]); current_value[2] = (int)(acceleration_mg[2]); strcpy(difference0,dto62(current_value[0]-previous_value[0])); strcpy(difference1,dto62(current_value[1]-previous_value[1])); strcpy(difference2,dto62(current_value[2]-previous_value[2])); sprintf(m_buffer, "%s %s %s", difference0, difference1, difference2); printf("%s\r\n",m_buffer); } else { printf("can't read reg data\r\n"); } for(int i=0; i<3; i++) { previous_value[i] = current_value[i]; } }
and this is the error code on J-LINK RTT viewer
and can't get data at all (0 0 0)
(above data are from GPIO pins with another timer)
If you need more specific information to solve my issue, let me know what should I show you.
hope I can solve this issue asap. Thanks for reading my ticket.