123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- /********************** 头文件 *************************/
- #include "main.h"
- #include "User_Sleep.h"
- /********************** 变量区 *************************/
- /********************** 函数声明区 *************************/
- /********************** 系统函数区 *************************/
- void clocks_start( void )
- {
- NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
- NRF_CLOCK->TASKS_HFCLKSTART = 1;
- while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
- }
- void saadc_gpio_init(void)
- {
- nrf_gpio_cfg(
- 7,
- NRF_GPIO_PIN_DIR_OUTPUT,
- NRF_GPIO_PIN_INPUT_DISCONNECT,
- NRF_GPIO_PIN_NOPULL,
- NRF_GPIO_PIN_S0S1,
- NRF_GPIO_PIN_NOSENSE);
- }
- void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
- {
- }
- //saadc?????
- void saadc_init(void)
- {
- ret_code_t err_code;
- //??SAADC??????
- //????????????????????????
- //?????????????
- nrf_saadc_channel_config_t saadc_0 = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN3);//????NRF_SAADC_INPUT_AIN2
- //???SAADC,????????,???????????
- //??????????,??nrf_drv_saadc_init()??????????
- //???????????,???????
- err_code=nrf_drv_saadc_init(NULL,saadc_callback);
- APP_ERROR_CHECK(err_code);
- //???SAADC??0
- err_code = nrf_drv_saadc_channel_init(0, &saadc_0);
- APP_ERROR_CHECK(err_code);
- saadc_gpio_init();
- }
- unsigned char adc_convert_to_power(short adcvalue)
- {
- const unsigned short list[3][12]={
- {100,90,80,70,60,50,40,30,20,10,5,0},
- {4200,4060,3980,3870,3820,3790,3770,3740,3680,3450,3000},
- {678,651,640,629,621,610,606,603,600,586,548,470}
- };
- if(adcvalue>list[2][0])return 100;
- if(adcvalue<=list[2][11])return 0;
- for(int i=0;i<11;i++)
- {
- if((adcvalue > list[2][i+1]) && (adcvalue <= list[2][i]))
- {
- return (list[0][i]-list[0][i+1])*(adcvalue-list[2][i+1])/(list[2][i]-list[2][i+1]) + list[0][i+1];
- }
- }
- return 100;
- }
- //?????????
- unsigned char Acquire_nrf_temp(void)
- {
- 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() / 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. */
- return temp;
- }
- extern uint16_t h_press;
- void AcquireTempPower(void)
- {
- nrf_saadc_value_t saadc_val;
- nrf_drv_saadc_sample_convert(0,&saadc_val); //4.2=678
- pm.power=adc_convert_to_power(saadc_val);
- pm.inner_temperature=Acquire_nrf_temp();
- pm.pressure[2]=(h_press&0xff00)>>8;
- pm.pressure[3]=h_press&0x00ff;
- }
- int main(void)
- {
- uint32_t err_code;
- gpio_init(); //初始化IO
- bsp_uart_init(); //初始化串口
-
- twi_master_init();
- nrf_delay_ms(100);
- MSE5611_Config();
- MPU6050_Init_reg();
-
- err_code = NRF_LOG_INIT(NULL);
- APP_ERROR_CHECK(err_code);
- NRF_LOG_DEFAULT_BACKENDS_INIT();
- clocks_start();
- err_code = bsp_esb_init(); //初始化esb
- APP_ERROR_CHECK(err_code);
- err_code = nrf_esb_start_rx();
- APP_ERROR_CHECK(err_code);
-
- time_init(); //?????
- saadc_init(); //???ADC????
- nrf_temp_init();//?????????
- //nrf_gpio_pin_write(MT_EN,0);
- //IntoSystemOffMode();
- while (true)
- {
- // nrf_gpio_pin_toggle(LED);
- AcquireTempPower();
- nrf_delay_ms(1000);
- }
- }
- /*lint -restore */
|