Hello! I'm using nRF52832 with ms5803-14BA.
And I want to get this sensor's raw data form prom.
and my code is here
#include <stdio.h> #include "boards.h" #include "app_util_platform.h" #include "app_error.h" #include "nrf_drv_twi.h" #include "nrf_delay.h" #include "nrf_log.h" #include "nrf_log_ctrl.h" #include "nrf_log_default_backends.h" #define TWI_INSTANCE_ID 0 #define MPU_ADDR 0x0c #define MPU_REG_ZOUT_H 0x3F #define MPU_PWR_MNGM1 0x6B #define MPU_REG_WHO_AM_I 0x75 #define NORMAL_MODE 1 static volatile bool m_xfer_done = false; static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID); static uint8_t m_sample[16]; static uint8_t raw; static int16_t accel_x; static int16_t accel_y; static int16_t accel_z; static int i = 0; static int a = 0; void set_mode(void) { ret_code_t err_code; uint8_t reg[1] = {0x1E}; err_code = nrf_drv_twi_tx(&m_twi, 0x76, reg, sizeof(reg), false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); } __STATIC_INLINE void data_handler(uint8_t m_sample[]) { uint16_t coef_a = (m_sample[0]<<8) | m_sample[1]; uint16_t coef_b = (m_sample[2]<<8) | m_sample[3]; uint16_t coef_c = (m_sample[4]<<8) | m_sample[5]; uint16_t coef_d = (m_sample[6]<<8) | m_sample[7]; uint16_t coef_e = (m_sample[8]<<8) | m_sample[9]; uint16_t coef_f = (m_sample[10]<<8) | m_sample[11]; uint16_t coef_g = (m_sample[12]<<8) | m_sample[13]; uint16_t coef_h = (m_sample[14]<<8) | m_sample[15]; NRF_LOG_INFO("%d", coef_a); NRF_LOG_INFO("%d", coef_b); NRF_LOG_INFO("%d", coef_c); NRF_LOG_INFO("%d", coef_d); NRF_LOG_INFO("%d", coef_e); NRF_LOG_INFO("%d", coef_f); NRF_LOG_INFO("%d", coef_g); NRF_LOG_INFO("%d", coef_h); } void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context) { switch (p_event->type) { case NRF_DRV_TWI_EVT_DONE: if (p_event->xfer_desc.type == NRF_DRV_TWI_XFER_RX) { // nrf_delay_ms(50); data_handler(m_sample); // nrf_delay_ms(50); } m_xfer_done = true; break; default: break; } } void twi_init (void) { ret_code_t err_code; const nrf_drv_twi_config_t twi_mpu9250_config = { .scl = ARDUINO_SCL_PIN, .sda = ARDUINO_SDA_PIN, .frequency = NRF_DRV_TWI_FREQ_400K, .interrupt_priority = APP_IRQ_PRIORITY_HIGH, .clear_bus_init = false }; err_code = nrf_drv_twi_init(&m_twi, &twi_mpu9250_config, twi_handler, NULL); APP_ERROR_CHECK(err_code); nrf_drv_twi_enable(&m_twi); } static void read_sensor_data() { m_xfer_done = false; uint8_t reg[1] = {0xA0}; m_xfer_done = false; ret_code_t err_code = nrf_drv_twi_tx(&m_twi, 0x76, reg, 1, false); APP_ERROR_CHECK(err_code); while (m_xfer_done == false); //nrf_delay_ms(150); err_code = nrf_drv_twi_rx(&m_twi, 0x76, m_sample, sizeof(m_sample)); APP_ERROR_CHECK(err_code); //nrf_delay_ms(150); } int main(void) { APP_ERROR_CHECK(NRF_LOG_INIT(NULL)); NRF_LOG_DEFAULT_BACKENDS_INIT(); NRF_LOG_INFO("\r\nTWI sensor example started."); NRF_LOG_INFO("check to flush") NRF_LOG_FLUSH(); NRF_LOG_INFO("return flash") twi_init(); NRF_LOG_INFO("init check") set_mode(); int sample = 0; while (true) { nrf_delay_ms(250); NRF_LOG_INFO("\r\n sample number : %d", ++sample); do { __WFE(); }while (m_xfer_done == false); read_sensor_data(); NRF_LOG_FLUSH(); } } /** @} */
I don't know why the resultant value is 65535(which is 16bit saturation)
HELP ME ㅠㅠ