TEMP
1. 头文件路径
在KEIL中包含下面路径
nRF5_SDK_15.0.0_a53641a\modules\nrfx\hal\nrf_temp.h
2. 读取芯片内部温度值
- 包含
#include "nrf_temp.h"
头文件 - 在
main
函数中调用nrf_temp.h
头文件中的nrf_temp_init()
函数来初始化内部温度传感器 - 操作寄存器读取温度值
float tempGetValue(void)
{
float temp = 0;
NRF_TEMP->TASKS_START = 1; //启动温度采集
while (NRF_TEMP->EVENTS_DATARDY == 0); //等待采集完成
NRF_TEMP->EVENTS_DATARDY = 0; //清楚标志
temp = (nrf_temp_read() / 4.0); //读取温度原始值并转化为实际温度值(实际温度值为原始值的0.25℃的步进)
NRF_TEMP->TASKS_STOP = 1; //停止采集
return temp;
}
RNG
1. 导入rng模块
包含头文件#include "nrf_drv_rng.h"
在nRF_Drivers组中导入的文件:
nrf_drv_rng.c
位于nRF5_SDK_15.0.0_a53641a\integration\nrfx\legacy
nrfx_rng.c
位于nRF5_SDK_15.0.0_a53641a\modules\nrfx\drivers\src
nrf_queue.c
位于nRF5_SDK_15.0.0_a53641a\components\libraries\queue
2. 配置sdk_config.h
RNG_CONFIG_ERROR_CORRECTION
是否启用错误修正
// <e> NRFX_RNG_ENABLED - nrfx_rng - RNG peripheral driver
//==========================================================
#ifndef NRFX_RNG_ENABLED
#define NRFX_RNG_ENABLED 1
#endif
// <q> NRFX_RNG_CONFIG_ERROR_CORRECTION - Error correction
#ifndef NRFX_RNG_CONFIG_ERROR_CORRECTION
#define NRFX_RNG_CONFIG_ERROR_CORRECTION 1
#endif
// <o> NRFX_RNG_CONFIG_IRQ_PRIORITY - Interrupt priority
// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7
#ifndef NRFX_RNG_CONFIG_IRQ_PRIORITY
#define NRFX_RNG_CONFIG_IRQ_PRIORITY 7
#endif
// <e> NRFX_RNG_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef NRFX_RNG_CONFIG_LOG_ENABLED
#define NRFX_RNG_CONFIG_LOG_ENABLED 0
#endif
// <o> NRFX_RNG_CONFIG_LOG_LEVEL - Default Severity level
// <0=> Off
// <1=> Error
// <2=> Warning
// <3=> Info
// <4=> Debug
#ifndef NRFX_RNG_CONFIG_LOG_LEVEL
#define NRFX_RNG_CONFIG_LOG_LEVEL 3
#endif
// <o> NRFX_RNG_CONFIG_INFO_COLOR - ANSI escape code prefix.
// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White
#ifndef NRFX_RNG_CONFIG_INFO_COLOR
#define NRFX_RNG_CONFIG_INFO_COLOR 0
#endif
// <o> NRFX_RNG_CONFIG_DEBUG_COLOR - ANSI escape code prefix.
// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White
#ifndef NRFX_RNG_CONFIG_DEBUG_COLOR
#define NRFX_RNG_CONFIG_DEBUG_COLOR 0
#endif
// </e>
// </e>
// <e> RNG_ENABLED - nrf_drv_rng - RNG peripheral driver - legacy layer
//==========================================================
#ifndef RNG_ENABLED
#define RNG_ENABLED 1
#endif
// <q> RNG_CONFIG_ERROR_CORRECTION - Error correction
#ifndef RNG_CONFIG_ERROR_CORRECTION
#define RNG_CONFIG_ERROR_CORRECTION 1
#endif
// <o> RNG_CONFIG_POOL_SIZE - Pool size
#ifndef RNG_CONFIG_POOL_SIZE
#define RNG_CONFIG_POOL_SIZE 64
#endif
// <o> RNG_CONFIG_IRQ_PRIORITY - Interrupt priority
// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7
#ifndef RNG_CONFIG_IRQ_PRIORITY
#define RNG_CONFIG_IRQ_PRIORITY 7
#endif
// </e>
// <e> NRF_QUEUE_ENABLED - nrf_queue - Queue module
//==========================================================
#ifndef NRF_QUEUE_ENABLED
#define NRF_QUEUE_ENABLED 1
#endif
// <q> NRF_QUEUE_CLI_CMDS - Enable CLI commands specific to the module
#ifndef NRF_QUEUE_CLI_CMDS
#define NRF_QUEUE_CLI_CMDS 0
#endif
// </e>
3. RNG应用
- 初始化RNG
ret_code_t err_code;
err_code = nrf_drv_rng_init(NULL);
APP_ERROR_CHECK(err_code);
- 获取RNG向量组,返回向量组长度
uint8_t randomVectorGenerate(uint8_t *p_buff, uint8_t size)
{
uint32_t err_code;
uint8_t available;
nrf_drv_rng_bytes_available(&available);
uint8_t length = MIN(size, available);
err_code = nrf_drv_rng_rand(p_buff, length);
APP_ERROR_CHECK(err_code);
return length;
}
在调用函数之前定义一个数组用于存放生成的随机值,即可获取到指定长度的随机值。