Hi,
I would like to read data from sensor and send it over BLE to nRF connect. Unfortunaly, something went wrong while reading the data by TWIM.
I´m using SDK16.
I would like to read 12 Bytes from a Sensor and store this in a Puffer. After this, I send the Puffer ober BLE to nRF connect. So the procedure should be:
- determine Sensor
- determine start register
- read 12 Bytes, starting at start register
- send 12 Bytes ober Bluetooth Low Energy
I think someting goes wrong by collecting the data over TWIM. For doing this, I use the following functions to determine the correct Sensor:
void ICM20948_set_mode(void) { ret_code_t err_code; /* Sensor on */ uint8_t reg3[2] = {0x06, 0x01}; nrfx_twim_xfer_desc_t normal_mode_config = NRFX_TWIM_XFER_DESC_TX(ICM20948_ADDR, reg3, sizeof(reg3)); err_code = nrfx_twim_xfer(&m_twim, &normal_mode_config, NULL); while (m_xfer_done == false); /* Register choose */ uint8_t reg4[1] = {0x2D}; // Since this register there are 12 Bytes we would have to read m_xfer_done = false; nrfx_twim_xfer_desc_t temp_reg_write = NRFX_TWIM_XFER_DESC_TX(ICM20948_ADDR, reg4, sizeof(reg4)); err_code = nrfx_twim_xfer(&m_twim, &normal_mode_config, NULL); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); }
After determine the correct sensor and correct register, I would like to read 12 Bytes from the register and send it by bluetooth.:
static void read_sensor_data() { m_xfer_done = false; nrfx_twim_xfer_desc_t lm75b_reading = NRFX_TWIM_XFER_DESC_RX(ICM20948_ADDR, &m_sample[0], sizeof(m_sample)); /* Read 12 bytes from the specified address - skip 3 bits dedicated for fractional part of temperature. */ ret_code_t err_code = nrfx_twim_xfer(&m_twim, &lm75b_reading, NULL); APP_ERROR_CHECK(err_code); // Send data over Bluetooth //nrf_delay_ms(100); uint32_t err_code2; uint16_t length = (uint16_t)12; err_code2 = ble_nus_data_send(&m_nus, m_sample, &length, m_conn_handle); if ((err_code2 != NRF_ERROR_INVALID_STATE) && (err_code2 != NRF_ERROR_RESOURCES) && (err_code2 != NRF_ERROR_NOT_FOUND)) { APP_ERROR_CHECK(err_code2); } }
Unfortunaly, there are not the correct sensor values on nRF connect app. For analyzing, I attached the hole project for you too.
It would be great, if someone could have a look to my functions I use.
Thanks in advance.
Simon