void SetCalibData(void){ /* Test user or factory temperature sensor calibration value */ if ( testUserCalibData() == ENABLE ) calibdata = *USER_CALIB_DATA; else if ( testFactoryCalibData() == ENABLE ) calibdata = *FACTORY_CALIB_DATA; else { calibdata.TS_CAL_COLD = DEFAULT_COLD_VAL; calibdata.TS_CAL_HOT = DEFAULT_HOT_VAL; writeCalibData(&calibdata); calibdata = *USER_CALIB_DATA; } }
int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32l1xx_md.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ /* Configure Clocks for Application need */ RCC_Configuration(); /* Configure RTC Clocks */ RTC_Configuration(); /* Set internal voltage regulator to 1.8V */ PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ; /* Enable debug features in low power modes (Sleep, STOP and STANDBY) */ #ifdef DEBUG_SWD_PIN DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE); #endif /* Configure SysTick IRQ and SysTick Timer to generate interrupts */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 500); /* Init I/O ports */ Init_GPIOs(); /* Initializes the LCD glass */ LCD_GLASS_Configure_GPIO(); LCD_GLASS_Init(); /* Display Welcome message */ LCD_GLASS_ScrollSentence(" ** TEMPERATURE SENSOR EXAMPLE ** ",1,SCROLL_SPEED); /* Disable SysTick IRQ and SysTick Timer */ SysTick->CTRL &= ~ ( SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk ); /* Test user or factory temperature sensor calibration value */ if ( testFactoryCalibData() == SUCCESS ) getFactoryTSCalibData(&calibdata); else if ( testUserCalibData() == SUCCESS ) calibdata = *USER_CALIB_DATA; else { /* User calibration or factory calibration TS data are not available */ calibdata.TS_CAL_1 = DEFAULT_COLD_VAL; calibdata.TS_CAL_2 = DEFAULT_HOT_VAL; writeCalibData(&calibdata); calibdata = *USER_CALIB_DATA; } /* Configure Wakeup from sleep using RTC event*/ configureWakeup(); /* Configure direct memory access for ADC usage*/ configureDMA(); /* Configure ADC for temperature sensor value conversion */ configureADC_Temp(); while(1) { /* Re-enable DMA and ADC conf and start Temperature Data acquisition */ acquireTemperatureData(); /* Stay in SLEEP mode untill the data are acquired by ADC */ __WFI(); /* for DEBUG purpose uncomment the following line and comment the __WFI call to do not enter STOP mode */ // while (!flag_ADCDMA_TransferComplete); /* Disable ADC, DMA and clock*/ powerDownADC_Temper(); /* Process mesured Temperature data - calculate average temperature value in °C */ processTempData(); if (flag_UserButton == TRUE) { clearUserButtonFlag(); if (CurrentlyDisplayed == Display_TemperatureDegC) CurrentlyDisplayed = Display_ADCval; else CurrentlyDisplayed = Display_TemperatureDegC; } if (CurrentlyDisplayed == Display_TemperatureDegC) { /* print average temperature value in °C */ sprintf(strDisp, "%d °C", temperature_C ); } else { /* print result of ADC conversion */ sprintf(strDisp, "> %d", tempAVG ); } LCD_GLASS_Clear(); LCD_GLASS_DisplayString( (unsigned char *) strDisp ); /* Enable RTC Wakeup */ RTC_WakeUpCmd(ENABLE); /* Clear WakeUp flag */ PWR_ClearFlag(PWR_FLAG_WU); /* Enter in wait for interrupt stop mode*/ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); RCC_Configuration(); // reinitialize clock /* After Wake up : Disable Wake up from RTC*/ RTC_WakeUpCmd(DISABLE); } }