鄙人才疏学浅,如有看不入眼的代码,烦请各位指教。
开发准备
在下开发时使用的SDK库为nRF5_SDK_17.0.2_d674dde,协议栈为s140_nrf52_7.0.1_softdevice.hex,路径为components/softdevicde/s140/hex。具体文件添加不再赘述,根据需要选择自己的驱动文件加入即可。相应资源也可以查看官方提供的文档说明查找,或者加入清风总群询问,清风可提供功能实现流程以及文件添加流程,以及SDK,实在找不到可以咨询鄙人。
注意:1.请不要使用中文路径,较多小白会使用中文路径以至于报错。
2.先了解好芯片的烧录流程以及使用设备乃至使用软件。nrf52832使用keil就可以烧录,接入jlink烧录器,选择sw接口,将4个引脚接入,能查找到jlink版本号以及芯片识别码就可以烧录。
串口的设置和打印
进图第一件事就是找好道具,先把printf和uart拉出来,有了串口才有了调试的资本。
- 【编译错误】 ”,. build\nrf5232 xxaa,.axf: Eror:16915E:Library zeports error: _use no sewihosting was requested, bnt asemihosting frutc was linked inNot enough information to list load addresses in the image map.“
-
我的解决办法是把printf改成NRF_LOG_INFO打印输出。网上的解决办法是Keil的设置里面勾选use MicroLIB。
- RTT打印浮点数,NRF_LOG_INFO无法打印浮点数
-
1) 添加串口打印;
2) 添加浮点数打印函数——NRF_LOG_FLOAT.
配置uart引脚
在这里使用11,12引脚复用为TX,RX,如下配置。
/**@brief Function for initializing the UART. */
static void uart_init(void)
{
#if 1
uint32_t rx_pin , tx_pin;
rx_pin = RX_PIN_NUMBER;//11
tx_pin = TX_PIN_NUMBER;//12
#endif
ret_code_t err_code;
app_uart_comm_params_t const comm_params =
{
.rx_pin_no = rx_pin,
.tx_pin_no = tx_pin,
.rts_pin_no = RTS_PIN_NUMBER,
.cts_pin_no = CTS_PIN_NUMBER,
.flow_control = APP_UART_FLOW_CONTROL_DISABLED,
.use_parity = false,
.baud_rate = UART_BAUDRATE_BAUDRATE_Baud115200
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_event_handler,
APP_IRQ_PRIORITY_LOWEST,
err_code);
APP_ERROR_CHECK(err_code);
//NRF_LOG_INFO("rx_pin = %d,tx_pin = %d",rx_pin,tx_pin);
}
设置浮点打印
#define NRF_LOG_ERROR(...) NRF_LOG_INTERNAL_ERROR(__VA_ARGS__)
#define NRF_LOG_WARNING(...) NRF_LOG_INTERNAL_WARNING( __VA_ARGS__)
#define NRF_LOG_INFO(...) NRF_LOG_INTERNAL_INFO( __VA_ARGS__)
#define NRF_LOG_DEBUG(...) NRF_LOG_INTERNAL_DEBUG( __VA_ARGS__)
/**
* @brief Macro to be used in a formatted string to a pass float number to the log.
*
* Use this macro in a formatted string instead of the %f specifier together with
* @ref NRF_LOG_FLOAT macro.
* Example: NRF_LOG_INFO("My float number" NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(f)))
*/
#define NRF_LOG_FLOAT_MARKER "%s%d.%02d"
/**
* @brief Macro for dissecting a float number into two numbers (integer and residuum).
*/
#define NRF_LOG_FLOAT(val) (uint32_t)(((val) < 0 && (val) > -1.0) ? "-" : ""), \
(int32_t)(val), \
(int32_t)((((val) > 0) ? (val) - (int32_t)(val) \
: (int32_t)(val) - (val))*100)
nrf自带的log_init
/**@brief Function for initializing the nrf log module.
*/
static void log_init(void)
{
ret_code_t err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);
NRF_LOG_DEFAULT_BACKENDS_INIT();
}
如此一来,串口打印就基本处理好了,可以试着打一些信息看看效果。
NRF_LOG_INFO("Template example started.");
NRF_LOG_INFO("\r\n[KYOHOON FOR world] www.kyohoon.com auther Andyi, email zhongweixiong@kyohoon.com \r\n Hello world, system start...\r\n")
复用NFC引脚
有的人举手:请问为什么P9,P10无法使用呢?
/* Configure NFCT pins as GPIOs if NFCT is not to be used in your code. If CONFIG_NFCT_PINS_AS_GPIOS is not defined,
two GPIOs (see Product Specification to see which ones) will be reserved for NFC and will not be available as
normal GPIOs. */
#if defined (CONFIG_NFCT_PINS_AS_GPIOS)
if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)){
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NRF_UICR->NFCPINS &= ~UICR_NFCPINS_PROTECT_Msk;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NVIC_SystemReset();
}
#endif
就在此处,只需要将其中的引脚修改,甚至注释掉这一段,就可以复用引脚了。
sdk.config.h配置
以上是一些必要的配置,请记得提前打开。
如有需求
研发类型的需求和讨论,如有需要请联系鄙人。京鸿科技有限公司邮箱:zhongweixiong@kyohoon.com,联系电话:15507589165 钟先生