hi...
i want to read the external accelerometer sensor using i2c in nRF52832 ..how to do ?
hi...
i want to read the external accelerometer sensor using i2c in nRF52832 ..how to do ?
Hi... Amanda
i tried .. but i am getting constantly 0 as a value . see the code
#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" /* TWI instance ID. */ #define TWI_INSTANCE_ID 0 /* Common addresses definition for temperature sensor. */ /* Mode for LM75B. */ #define NORMAL_MODE 0U /* Indicates if operation on TWI has ended. */ static volatile bool m_xfer_done = false; /* TWI instance. */ static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID); /* Buffer for samples read from temperature sensor. */ static uint8_t m_sample; uint32_t device_addr =0x4C ; uint32_t register_addr= 0x00; uint8_t *p_data; void twi_init (void) { ret_code_t err_code; const nrf_drv_twi_config_t twi_config = { .scl = ARDUINO_SCL_PIN, .sda = ARDUINO_SDA_PIN, .frequency = NRF_DRV_TWI_FREQ_100K, .interrupt_priority = APP_IRQ_PRIORITY_HIGH, .clear_bus_init = false }; err_code = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL); APP_ERROR_CHECK(err_code); if (NRF_SUCCESS == err_code) { nrf_drv_twi_enable(&m_twi); NRF_LOG_INFO("TWI init success..."); } } static void read_register() { ret_code_t err_code; nrf_drv_twi_t twi_instance; uint32_t device_addr =0x4C ; uint32_t register_addr= 0x00; uint8_t *p_data; uint8_t bytes; bool no_stop; err_code = nrf_drv_twi_tx(&twi_instance, device_addr, ®ister_addr, 1, no_stop); APP_ERROR_CHECK(err_code); if(err_code != NRF_SUCCESS) { return err_code; } err_code = nrf_drv_twi_rx(&twi_instance, device_addr, p_data, bytes); return err_code; } 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_FLUSH(); twi_init(); read_register(); while (1) { nrf_delay_ms(500); NRF_LOG_INFO("\r\nTWI ."); printf("p_data:%d",p_data); NRF_LOG_INFO("P_data:%d",p_data); NRF_LOG_FLUSH(); } }