1 基于J-Link的调试信息输出( 七 )


添加文件
在工程目录下添加 .h; .c 两个文件 , 这两个个文件可以直接从我的源码中复制过来 。
修改main.c
打开main.c文件将代码修改为如下代码
#include "nrf_delay.h"#include "nrf_log.h"#include "nrf_log_ctrl.h"#include "nrf_log_default_backends.h"#include "ws2812b.h"/*** @brief Function for application main entry.*/int main(void){NRF_LOG_INIT(NULL);NRF_LOG_DEFAULT_BACKENDS_INIT();WS2812B_init();tColor color = {.R = 0, .G = 0, .B = 0,};while (true){nrf_delay_ms(1000);color.R = 100;color.G = 0;color.B = 0;for(int i=0; i
将程序烧录到芯片后 , 16颗灯便会红、绿、蓝的颜色切换 。
6 三轴加速计的驱动
我们的加速计采用ST的 , 通过I2C连接到上 , 另外还把的两个可编程中断引脚也连接到上 , 进行状态检测 。
简介TWI
的I2C通信接口的名字并不叫I2C , 而是叫做 TWI(two-wire ) , 它是兼容I2C的 。在官方的SDK中我们要使用的TWI被封装为三层分别为:
我们使用TWI , 直接调用TIWIM层中的接口就可以了 。
工程建立
我们把RTT文件夹复制一份并重命名位Accel作为我们本节的工程文件夹 。
修改.h
打开.h文件 , 在其中添加下边的配置宏定义
// TWI transaction manager#define NRF_TWI_MNGR_ENABLED 1#define NRFX_TWI_ENABLED 1#define NRFX_TWI0_ENABLED 1
使能TWI模块 , 同时使能我们使用的TWI0
修改
打开文件 , 将 和 变量修改为如下代码
# Source files common to all targetsSRC_FILES += \$(PROJ_DIR)/main.c \$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52.S \$(SDK_ROOT)/modules/nrfx/mdk/system_nrf52.c \$(SDK_ROOT)/components/libraries/atomic/nrf_atomic.c \$(SDK_ROOT)/components/libraries/balloc/nrf_balloc.c \$(SDK_ROOT)/components/libraries/util/app_util_platform.c \$(SDK_ROOT)/components/libraries/experimental_memobj/nrf_memobj.c \$(SDK_ROOT)/components/libraries/experimental_log/src/nrf_log_backend_rtt.c \$(SDK_ROOT)/components/libraries/experimental_log/src/nrf_log_default_backends.c \$(SDK_ROOT)/components/libraries/experimental_log/src/nrf_log_frontend.c \$(SDK_ROOT)/components/libraries/experimental_log/src/nrf_log_str_formatter.c \$(SDK_ROOT)/components/libraries/experimental_log/src/nrf_log_backend_serial.c \$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c \$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \$(SDK_ROOT)/external/fprintf/nrf_fprintf.c \$(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c \\$(PROJ_DIR)/accel.c \$(PROJ_DIR)/LIS3DH/lis3dh_driver.c \$(SDK_ROOT)/components/libraries/twi_mngr/nrf_twi_mngr.c \$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_twi.c \$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_twi.c \$(SDK_ROOT)/components/libraries/queue/nrf_queue.c \$(SDK_ROOT)/components/libraries/util/app_error.c \$(SDK_ROOT)/components/libraries/util/app_error_weak.c \# Include folders common to all targetsINC_FOLDERS += \$(PROJ_DIR) \$(SDK_ROOT)/modules/nrfx \$(SDK_ROOT)/modules/nrfx/mdk \$(SDK_ROOT)/integration/nrfx \$(SDK_ROOT)/components/toolchain/cmsis/include \$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \$(SDK_ROOT)/components/libraries/atomic \$(SDK_ROOT)/components/libraries/balloc \$(SDK_ROOT)/components/libraries/delay \$(SDK_ROOT)/components/libraries/strerror \$(SDK_ROOT)/components/libraries/util \$(SDK_ROOT)/components/libraries/experimental_log/src \$(SDK_ROOT)/components/libraries/experimental_log \$(SDK_ROOT)/components/libraries/experimental_memobj \$(SDK_ROOT)/components/libraries/experimental_section_vars \$(SDK_ROOT)/external/fprintf \$(SDK_ROOT)/external/segger_rtt \\$(PROJ_DIR)/LIS3DH \$(SDK_ROOT)/modules/nrfx/hal \$(SDK_ROOT)/modules/nrfx/drivers/include \$(SDK_ROOT)/components/libraries/twi_mngr \$(SDK_ROOT)/components/libraries/queue \$(SDK_ROOT)/integration/nrfx/legacy \