Created
May 17, 2018 01:12
-
-
Save isundaylee/364c3a6ef6395f589c9bb89b21575142 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdint.h> | |
| #include <string.h> | |
| #include "app_timer.h" | |
| #include "nrf_delay.h" | |
| #include "nrf_drv_twi.h" | |
| #include "nrf_gpio.h" | |
| #include "nrf_log.h" | |
| #include "nrf_log_ctrl.h" | |
| #include "nrf_log_default_backends.h" | |
| #include "lsm9ds1.h" | |
| void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) | |
| { | |
| nrf_gpio_pin_set(4); | |
| NRF_BREAKPOINT_COND; | |
| for (;;) {} | |
| } | |
| void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name) | |
| { | |
| app_error_handler(0xDEADBEEF, line_num, p_file_name); | |
| } | |
| static void timers_init(void) | |
| { | |
| ret_code_t err_code = app_timer_init(); | |
| APP_ERROR_CHECK(err_code); | |
| } | |
| static void log_init(void) | |
| { | |
| ret_code_t err_code = NRF_LOG_INIT(NULL); | |
| APP_ERROR_CHECK(err_code); | |
| NRF_LOG_DEFAULT_BACKENDS_INIT(); | |
| } | |
| static const nrf_drv_twi_t twi = NRF_DRV_TWI_INSTANCE(0); | |
| static void twi_init() | |
| { | |
| const nrf_drv_twi_config_t config = { | |
| .scl = 8, | |
| .sda = 7, | |
| .frequency = NRF_DRV_TWI_FREQ_100K, | |
| .interrupt_priority = APP_IRQ_PRIORITY_HIGH, | |
| .clear_bus_init = false | |
| }; | |
| int ret = nrf_drv_twi_init(&twi, &config, NULL, NULL); | |
| APP_ERROR_CHECK(ret); | |
| nrf_drv_twi_enable(&twi); | |
| } | |
| lsm9ds1_t imu; | |
| static void lsm9ds1_test() | |
| { | |
| lsm9ds1_init(&imu, &twi); | |
| while (1) | |
| { | |
| int16_t accel_x, accel_y, accel_z; | |
| lsm9ds1_accel_read_all(&imu, &accel_x, &accel_y, &accel_z); | |
| NRF_LOG_INFO("Got reading: accel_x %d", accel_x); | |
| NRF_LOG_INFO("Got reading: accel_y %d", accel_y); | |
| NRF_LOG_INFO("Got reading: accel_z %d", accel_z); | |
| NRF_LOG_FLUSH(); | |
| nrf_delay_ms(20); | |
| } | |
| } | |
| int main(void) | |
| { | |
| nrf_gpio_cfg_output(4); | |
| // Initialize. | |
| log_init(); | |
| timers_init(); | |
| // Start execution. | |
| NRF_LOG_INFO("Hello, world!"); | |
| twi_init(); | |
| NRF_LOG_INFO("TWI successfullly initialized."); | |
| lsm9ds1_test(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What lsm9ds1.h file was being used for this?