芯片内部温度检测

工程下载地址

附件是基于Nr51822平台的简单演示代码,读取芯片内部温度,通过串口打印出来。适合初学者。

int main(void)
{
    ppi_timer_init();
    ppi_init();
    start_ppi();

    simple_uart_config(0xff,9,0xff,11,false);
    uart_exit();
    m_temp_init();
    
    
    while(1)
    {
        task_temperature();
    }
}


void m_temp_init(void)
{
    nrf_temp_init();
}



void task_temperature(void)
{
    char buf[30];
    uint8_t len;
    int32_t volatile temp;
    NRF_TEMP->TASKS_START = 1; /** Start the temperature measurement. */

    /* Busy wait while temperature measurement is not finished, you can skip waiting if you enable interrupt for DATARDY event and read the result in the interrupt. */
    /*lint -e{845} // A zero has been given as right argument to operator '|'" */
    while (NRF_TEMP->EVENTS_DATARDY == 0)
    {
        // Do nothing.
    }
    NRF_TEMP->EVENTS_DATARDY    = 0;

    /**@note Workaround for PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register. */
    temp                        = nrf_temp_read();

    /**@note Workaround for PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs. */
    NRF_TEMP->TASKS_STOP        = 1; /** Stop the temperature measurement. */

    sprintf(buf,"%d.%d C\r\n",temp/4,temp%4*25);
    simple_uart_putstring((const uint8_t*)buf);

    nrf_delay_ms(1000);

}


效果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值