#include "misc.h" #include "stm32l1xx_i2c.h" #include "stm32l1xx_adc.h" #include "stm32l1xx_lcd.h" #include "stm32l1xx_rcc.h" #include "stm32l1xx_rtc.h" #include "stm32l1xx_exti.h" #include "stm32l1xx_pwr.h" #include "stm32l1xx_syscfg.h" #include "stm32l1xx_dbgmcu.h" #include "stm32l1xx_dma.h" #include "stm32l1xx_tim.h" /* Touch sensing driver headers */ #include "stm32_tsl_api.h" #include "stm32l15x_tsl_ct_acquisition.h" /* discovery board and specific drivers headers*/ #include "discover_board.h" #include "icc_measure.h" #include "discover_functions.h" #include "stm32l_discovery_lcd.h" #include "stm32_tsl_timebase.h" #include "i2c_tsensor.h" /* Private variables ---------------------------------------------------------*/ static uint16_t TempCelsiusDisplay[6]; static int32_t TempValue = 0; uint8_t i = 0; static volatile uint32_t TimingDelay; extern unsigned char Bias_Current; /* Bias Current stored in E²Prom used for ICC mesurement precision */ extern uint8_t t_bar[2]; /* LCD bar graph: used for displaying active function */ extern bool Auto_test; /* Auto_test activation flag: set by interrupt handler if user button is pressed for a few seconds */ extern bool Idd_WakeUP; /* */ extern volatile bool KeyPressed; /* */ extern bool UserButton; /* Set by interrupt handler to indicate that user button is pressed */ uint8_t state_machine; /* Machine status used by main() wich indicats the active function, set by user button in interrupt handler */ uint16_t Int_CurrentSTBY; /* */ /*******************************************************************************/ /** * @brief main entry point. * @par Parameters None * @retval void None * @par Required preconditions: None */ int main(void) { /* Configure Clocks for Application need */ RCC_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) ; /* Init I/O ports */ Init_GPIOs(); /* Initializes ADC */ ADC_Icc_Init(); /* Enable General interrupts */ enableInterrupts(); /* Init Touch Sensing configuration */ TSL_Init(); /* Initializes the LCD glass */ LCD_GLASS_Init(); while (1) { LM75_Init(); /* Get double of Temperature value */ TempValue = LM75_ReadTemp(); if (TempValue <= 1023) { /* Positive temperature measured */ TempValue *= 125; convert_into_char(TempValue, TempCelsiusDisplay); TempCelsiusDisplay[1] |= DOT; TempCelsiusDisplay[4] = '°'; TempCelsiusDisplay[5] = 'C'; for(i=2; i<5;i++) //odstranenie 0 { if ( TempCelsiusDisplay[i] == '0') { TempCelsiusDisplay[i] = ' '; } } } else { /* Negative temperature measured */ TempValue = 2048 - TempValue; TempValue *= 12.5; convert_into_char(TempValue, TempCelsiusDisplay); TempCelsiusDisplay[0] = '-'; TempCelsiusDisplay[2] |= DOT; TempCelsiusDisplay[4] = '°'; TempCelsiusDisplay[5] = 'C'; for(i=3; i<5;i++) //odstranenie 0 { if ( TempCelsiusDisplay[i] == '0') { TempCelsiusDisplay[i] = ' '; } } } /* Display Celsius value on LCD */ LCD_GLASS_DisplayStrDeci(TempCelsiusDisplay); Delay(30); } } /** * @brief Configures the different system clocks. * @param None * @retval None */ void RCC_Configuration(void) { /* Enable HSI Clock */ RCC_HSICmd(ENABLE); /*!< Wait till HSI is ready */ while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET); /* Set HSI as sys clock*/ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); /* Set MSI clock range to ~4.194MHz*/ RCC_MSIRangeConfig(RCC_MSIRange_6); /* Enable the GPIOs clocks */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC| RCC_AHBPeriph_GPIOD| RCC_AHBPeriph_GPIOE| RCC_AHBPeriph_GPIOH, ENABLE); /* Enable comparator, LCD and PWR mngt clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_COMP | RCC_APB1Periph_LCD | RCC_APB1Periph_PWR,ENABLE); /* Enable ADC & SYSCFG clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_SYSCFG , ENABLE); /* Allow access to the RTC */ PWR_RTCAccessCmd(ENABLE); /* Reset RTC Backup Domain */ RCC_RTCResetCmd(ENABLE); RCC_RTCResetCmd(DISABLE); /* LSE Enable */ RCC_LSEConfig(RCC_LSE_ON); /* Wait until LSE is ready */ while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET); /* RTC Clock Source Selection */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); /* Enable the RTC */ RCC_RTCCLKCmd(ENABLE); /*Disable HSE*/ RCC_HSEConfig(RCC_HSE_OFF); if(RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET ) { /* Stay in infinite loop if HSE is not disabled*/ while(1); } } /** * @brief To initialize the I/O ports * @caller main * @param None * @retval None */ void Init_GPIOs (void) { /* GPIO, EXTI and NVIC Init structure declaration */ GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Configure User Button pin as input */ GPIO_InitStructure.GPIO_Pin = USERBUTTON_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(USERBUTTON_GPIO_PORT, &GPIO_InitStructure); /* Select User Button pin as input source for EXTI Line */ SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0); /* Configure EXT1 Line 0 in interrupt mode trigged on Rising edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line0 ; // PA0 for User button AND IDD_WakeUP EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable and set EXTI0 Interrupt to the lowest priority */ NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Configure the LED_pin as output push-pull for LD3 & LD4 usage*/ GPIO_InitStructure.GPIO_Pin = LD_GREEN_GPIO_PIN | LD_BLUE_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(LD_GPIO_PORT, &GPIO_InitStructure); /* Force a low level on LEDs*/ GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN); GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN); /* Counter enable: GPIO set in output for enable the counter */ GPIO_InitStructure.GPIO_Pin = CTN_CNTEN_GPIO_PIN; GPIO_Init( CTN_GPIO_PORT, &GPIO_InitStructure); /* To prepare to start counter */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Configure Port A LCD Output pins as alternate function */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_8 | GPIO_Pin_9 |GPIO_Pin_10 |GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_Init( GPIOA, &GPIO_InitStructure); /* Select LCD alternate function for Port A LCD Output pins */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource1,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource2,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource3,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource8,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource9,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource10,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource15,GPIO_AF_LCD) ; /* Configure Port B LCD Output pins as alternate function */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 \ | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_Init( GPIOB, &GPIO_InitStructure); /* Select LCD alternate function for Port B LCD Output pins */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource3,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource4,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource5,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource8,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource9,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource10,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource11,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource12,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource13,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource14,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource15,GPIO_AF_LCD) ; /* Configure Port C LCD Output pins as alternate function */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_6 \ | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |GPIO_Pin_11 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_Init( GPIOC, &GPIO_InitStructure); /* Select LCD alternate function for Port B LCD Output pins */ GPIO_PinAFConfig(GPIOC, GPIO_PinSource0,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource1,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource2,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource3,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource6,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource7,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource8,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource9,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource10,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource11,GPIO_AF_LCD) ; /* Configure ADC (IDD_MEASURE) pin as Analogue */ GPIO_InitStructure.GPIO_Pin = IDD_MEASURE ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_Init( IDD_MEASURE_PORT, &GPIO_InitStructure); } /** * @brief Inserts a delay time. * @param nTime: specifies the delay time length, in 10 ms. * @retval None */ void Delay(uint32_t nTime) { TimingDelay = nTime; while(TimingDelay != 0); } /** * @brief Decrements the TimingDelay variable. * @caller SysTick interrupt Handler * @param None * @retval None */ void TimingDelay_Decrement(void) { if (TimingDelay != 0x00) TimingDelay--; } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1); } #endif /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/