User_Temperature.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*********************************************************************
  2. *
  3. * 文件名: User_temperature.c
  4. * 功能描述:设备以及芯片温度查询
  5. * 作者: 陈俊超
  6. * 时间:2020-12-11
  7. *
  8. ********************************************************************/
  9. #include "nrf.h"
  10. #include "nrf_temp.h"
  11. #include "User_temperature.h"
  12. /********************** 变量区 **************************************/
  13. /********************** 函数功能区 **************************************/
  14. /**********************************************************
  15. * 函数名字:Acquire_nrf_temp
  16. * 函数作用:获取NRF内部的温度
  17. * 函数参数:无
  18. * 函数返回值:无
  19. ***********************************************************/
  20. uint8_t Acquire_nrf_temp(void)
  21. {
  22. int32_t volatile temp;
  23. NRF_TEMP->TASKS_START = 1; /** Start the temperature measurement. */
  24. /* 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. */
  25. /*lint -e{845} // A zero has been given as right argument to operator '|'" */
  26. while (NRF_TEMP->EVENTS_DATARDY == 0)
  27. {
  28. // Do nothing.
  29. }
  30. NRF_TEMP->EVENTS_DATARDY = 0;
  31. /**@note Workaround for PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register. */
  32. temp = (nrf_temp_read() / 4);
  33. /**@note Workaround for PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs. */
  34. NRF_TEMP->TASKS_STOP = 1; /** Stop the temperature measurement. */
  35. return temp;
  36. }
  37. /**********************************************************
  38. * 函数名字:User_temperature_init
  39. * 函数作用:温度查询初始化
  40. * 函数参数:无
  41. * 函数返回值:无
  42. ***********************************************************/
  43. void User_temperature_init(void)
  44. {
  45. nrf_temp_init();
  46. }