前言
温度传感器测量芯片DIE温度。通过触发START任务来启动TEMP。当温度测量完成后,一个数据将生成事件,并且可以从临时寄存器读取测量结果为了保证测量的准确性,必须在选择HFCLK晶体振荡器作为时钟。当温度测量完成后,将温度模拟电路的电源降下来可以节省电能。TEMP只支持一次性操作,这意味着必须显式地开始使用每个TEMP度量一开始的任务。
本节将介绍nRF51系列SOC片上温度传感器的使用,并通过串口把采集到的芯片内部的温度打印到PC端nRF51的ADC设计得比较简单,用于配置的寄存器只要一个。它有几个可配置的部分:
相关寄存器介绍
示例详解
基于硬件平台:nrf51822ek_tm开发板。
本示例所用的最小系统板原理图:
- 工程创建:
- 打开KEIL,新建一个空工程:Project->NewuVisionProject
工程名为nrfxx-temp确认后按下图选择芯片为nrf51822_xxAA->ok
在弹出的对话框中勾选CMSIS中的CORE;Device中的Startup(后面有nrf51Series字样的);在nrf_device中勾选nrf_gpio, nrf_uart, nrf_temp, nrf_delay,nrf_err并在nrf_Libraries中勾选app_error,nrf_assert模块。
OK之后工程自动生成如下代码:
新建一个空白文档,保存为main.c,并加入工程中:
配置工程,选择使用MicroLIB库,可以减小程序体积:
加入NRF51定义,并选择化等级3,可以减小程序体积,但仿真运行时可能会出现与代码顺序不一致现象:
调试工具选择J-LINK,并将接口设置为SW口勾选下载程序后自动复位及运行:
- 工程代码
- OK之后在man.c中加入如下代码:
把程序编译,可以看到串口助手中打印了以下输出内容: