您当前的位置: 首页 >  仙剑情缘

NRF52832 temperature for sdk 15.2.0

仙剑情缘 发布时间:2018-11-02 09:33:52 ,浏览量:4

1.引入头文件

#include "nrf_temp.h"

2.定义变量

int32_t volatile temp;

3.在主函数中的处理

/**
 * @brief Function for main application entry.
 */
int main(void)
{
    uint32_t err_code;
    
    bsp_board_init(BSP_INIT_LEDS);

    const app_uart_comm_params_t comm_params =
      {
          RX_PIN_NUMBER,
          TX_PIN_NUMBER,
          RTS_PIN_NUMBER,
          CTS_PIN_NUMBER,
          UART_HWFC,
          false,
#if defined (UART_PRESENT)
          NRF_UART_BAUDRATE_115200
#else
          NRF_UARTE_BAUDRATE_115200
#endif
      };

    APP_UART_FIFO_INIT(&comm_params,
                         UART_RX_BUF_SIZE,
                         UART_TX_BUF_SIZE,
                         uart_error_handle,
                         APP_IRQ_PRIORITY_LOWEST,
                         err_code);

    APP_ERROR_CHECK(err_code);
 

    while (true)
    {
        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;  // clear flag
        
        /**@note Workaround for PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register. */
        temp = nrf_temp_read()/4;
        /**@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. */
        
        printf("temp is %d\n",temp);
        nrf_delay_ms(1000);
    }

}

关注
打赏
查看更多评论

仙剑情缘

暂无认证

  • 4浏览

    0关注

    138博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录