/** * @brief Main program. * @param None * @retval None */ 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_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ /* System Clocks Configuration */ RCC_Config(); /* LCD GLASS Initialization */ LCD_GLASS_Init(); #ifdef USE_STM32L152D_EVAL LCD_GLASS_DisplayLogo(ENABLE); #endif /*Display " STM32L15 " string on LCD glass in scrolling mode*/ LCD_GLASS_ScrollString(LCD_String, SCROLL_NUM, SCROLL_SPEED); /* Infinite loop */ while (1) { } }
/** * @brief Configures the LCD Glass. LSI is used as LCD clock source * @param None * @retval None */ void LCD_Glass_Config(void) { /* Enable PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to the RTC */ PWR_RTCAccessCmd(ENABLE); /* Reset Backup Domain */ RCC_RTCResetCmd(ENABLE); RCC_RTCResetCmd(DISABLE); /* LSI Enable */ RCC_LSICmd(ENABLE); /* Wait till LSI is ready */ while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {} /* LCD Clock Source Selection: LSI */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); #ifdef USE_STM32L152_EVAL /* LCD GLASS Initialization */ LCD_GLASS_Init(); #endif }
/** * @brief Configure the LCD Glass. * @param None * @retval None */ void LCD_Glass_Config(void) { /* Enable PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to the RTC */ PWR_RTCAccessCmd(ENABLE); /* Reset Backup Domain */ RCC_RTCResetCmd(ENABLE); RCC_RTCResetCmd(DISABLE); /* LSE Enable */ RCC_LSEConfig(RCC_LSE_ON); /*Wait till LSE is ready */ while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {} /* LCD Clock Source Selection */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); /* Init LCD Glass */ LCD_GLASS_Init(); }
int main() { unsigned int k = 0; // used for counter unsigned short count = 0; char strDisp[20] ; // ### INITILIZATION ### // Enable the High Speed Internal (HSI) Clock RCC_HSI_enable(); // Select the HSI for the SYSCLK RCC_SYSCLK_HSI(); // Enable comparator clock LCD and PWR mngt RCC_LCD_enable(); RCC_PWR_enable(); // Enable SYSCFG RCC_SYSCFG_enable(); // Allow access to the RTC // Also selects the RTCCLK as LSE RTC_access_enable(); // LSE Enable, // this clock is needed for the RTCCLK and LCD RCC_LSE_enable(); // Initializes the LCD LCD_GLASS_Configure_GPIO(); LCD_GLASS_Init(); // configure PB6 as an output config_PB6_out(); // ### TOGGLE PB6, increment counter on LCD ### while(1) { k++; // Toggle at approximately 1 Hz if (k >= 10e5) { PB6_toggle(); //sprintf(strDisp, "%d", ++count); // decimal sprintf(strDisp, "%x", ++count); // hex //sprintf(strDisp, "%o", ++count); // octal LCD_GLASS_Clear(); LCD_GLASS_DisplayString((unsigned char *) strDisp); k = 0; // reset counter } } }
int main() //main function goes here { TIM_TimeBaseInitTypeDef tim4; //store initialize value for timer NVIC_InitTypeDef tim4interrupt; //store initialize value for interrupt RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE); //open clock for timer 4 TIM_TimeBaseStructInit(&tim4); //initialize tim value /* 1 sec->16,000,000 clock (ARR+1)*(PSC+1) = 16,000,000*1 ARR = 4000-1 PSC = 4000-1 */ tim4.TIM_Prescaler = 4000-1; tim4.TIM_Period = 4000-1; TIM_TimeBaseInit(TIM4,&tim4); //initialize tim4 value on timer 4 tim4interrupt.NVIC_IRQChannel = TIM4_IRQn; //timer 4 interrupt tim4interrupt.NVIC_IRQChannelCmd = ENABLE; //enable interrupt for timer 4 NVIC_Init(&tim4interrupt); //initialize interrupt by tim4interrupt value RCC_Configuration(); //config RCC for LCD RTC_Configuration(); //config RTC for LCD LCD_GLASS_Configure_GPIO(); //config io pin for LCD LCD_GLASS_Init(); //initialize LCD TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE); //config timer 4 interrupt TIM_ClearFlag(TIM4,TIM_FLAG_Update); //clear timer 4 interrupt flag TIM_Cmd(TIM4,ENABLE); //enable timer 4 while(1) //loop instruction goes here { } }
/** * @brief Description 外设初始化 * @param None * @retval None */ void PeripheralInit(void) { RCC_Config(); SysTick_Init(); TIM2_Configuration(); LED_GPIO_Config(); KEY_GPIO_Config(); EXTI15_10_Config(); General_GPIO_Config(); LCD_GLASS_Init(); USART1_Config(115200); // Delay_ms(10); //开启滴答定时 LCD_GLASS_Clear(); AVCC1_POWER(OFF); //关ADC1电源 BATTEST_POWER(OFF); //关电池电压检测电源 MODEL_PWRCTRL(ON); //开对外接口电源 ADC1_Init(); /* 8M串行flash W25Q64初始化 */ SPI_FLASH_Init(); I2C_GPIO_Config(); //rtc 初始化 rtc_init(); }
int main(void) { bool StanbyWakeUp ; float Current_STBY; /*!< 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 */ Int_CurrentSTBY = Current_Measurement(); /* Check if the StandBy flag is set */ if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET) { /* System resumed from STANDBY mode */ /* Clear StandBy flag */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); PWR_ClearFlag(PWR_FLAG_SB); StanbyWakeUp = TRUE; } else { StanbyWakeUp = FALSE; } PWR_PVDCmd(DISABLE); RCC_Configuration(); 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(); enableInterrupts(); /* Warning ! in TSL Init the sysTick interrupt is setted to: SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/ /* Init Touch Sensing configuration */ TSL_Init(); sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1; sMCKeyInfo[0].Setting.b.ENABLED = 1; sMCKeyInfo[0].DxSGroup = 0x00; /* Initializes the LCD glass */ LCD_GLASS_Init(); // EECE 337 Code -- Start int N; int f; char str[8]; N = 10; // Call to original factorial algorithm in C - for debugging //f = factorial_orig( N ); factorial(&f, N); // Copy result to f sprintf (str, "%X", f); //printf( "factorial of %i is %i\n", N, f); LCD_GLASS_DisplayString(str); // EECE 337 Code -- End return(0); }
static void prvConfigureLCD( void ) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable necessary clocks. */ RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, ENABLE ); RCC_APB1PeriphClockCmd( RCC_APB1Periph_LCD, ENABLE ); PWR_RTCAccessCmd( ENABLE ); RCC_LSEConfig( ENABLE ); RCC_RTCCLKConfig( RCC_RTCCLKSource_LSE ); RCC_RTCCLKCmd( ENABLE ); /* 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 ); LCD_GLASS_Init(); LCD_GLASS_DisplayString( "F'RTOS" ); }
int main(void) { bool StanbyWakeUp ; float Current_STBY; /*!< 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 */ Int_CurrentSTBY = Current_Measurement(); /* Check if the StandBy flag is set */ if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET) { /* System resumed from STANDBY mode */ /* Clear StandBy flag */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); PWR_ClearFlag(PWR_FLAG_SB); StanbyWakeUp = TRUE; } else { StanbyWakeUp = FALSE; } PWR_PVDCmd(DISABLE); RCC_Configuration(); 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(); enableInterrupts(); /* Warning ! in TSL Init the sysTick interrupt is setted to: SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/ /* Init Touch Sensing configuration */ TSL_Init(); sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1; sMCKeyInfo[0].Setting.b.ENABLED = 1; sMCKeyInfo[0].DxSGroup = 0x00; /* Initializes the LCD glass */ LCD_GLASS_Init(); while (1) { switch( State ) { case 0: //LED3 off and LED4 off blink = 0; GPIOB_ODR_value = 0x00000000; ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value; break; case 1: //LED3 on and LED4 off blink = 0; GPIOB_ODR_value = 0x00000080; ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value; break; case 2: //LED3 off and LED4 on blink = 0; GPIOB_ODR_value = 0x00000040; ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value; break; case 3: //LED3 and LED4 blink with 2 second period blink = 1; break; } if(blink == 1) { GPIOB_ODR_value = 0x000000C0; ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value; Delay(100); GPIOB_ODR_value = 0x00000000; ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value; Delay(100); } } return(0); }
/** * @brief Restore Demonstration context (GPIOs Configurations, peripherals,...). * @param None * @retval None */ void IDD_Measurement_RestoreContext(void) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; GPIOA->MODER = GPIOA_MODER; GPIOB->MODER = GPIOB_MODER; GPIOC->MODER = GPIOC_MODER; GPIOD->MODER = GPIOD_MODER; GPIOE->MODER = GPIOE_MODER; GPIOH->MODER = GPIOH_MODER; GPIOA->PUPDR = GPIOA_PUPDR; GPIOB->PUPDR = GPIOB_PUPDR; GPIOC->PUPDR = GPIOC_PUPDR; GPIOD->PUPDR = GPIOD_PUPDR; GPIOE->PUPDR = GPIOE_PUPDR; GPIOH->PUPDR = GPIOH_PUPDR; /* At this stage the system has resumed from STOP mode ---------------------*/ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Line = IDD_WAKEUP_EXTI_LINE; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = DISABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the EXTI Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = IDD_WAKEUP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE; NVIC_Init(&NVIC_InitStructure); /* Configure IDD_CNT_EN pin as output push-pull ----------------------------*/ GPIO_InitStructure.GPIO_Pin = IDD_CNT_EN_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_Init(IDD_CNT_EN_GPIO_PORT, &GPIO_InitStructure); /* Allow access to the RTC */ PWR_RTCAccessCmd(ENABLE); /*!< LSE Enable */ RCC_LSEConfig(RCC_LSE_ON); /*!< Wait till LSE is ready */ while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {} /*!< LCD Clock Source Selection */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); /* LCD GLASS Initialization */ LCD_GLASS_Init(); /* GPIO Configuration */ Demo_GPIOConfig(); /* Interrupt Configuration */ Demo_InterruptConfig(); /* Configure the systick */ Demo_SysTickConfig(); /*------------------- Drivers Initialization -------------------------------*/ /* Initialize the LEDs toggling */ Demo_LedShowInit(); /* Initialize the LCD */ STM32L152_LCD_Init(); /* If HSE is not detected at program startup */ if (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET) { /* Generate NMI exception */ SCB->ICSR |= SCB_ICSR_NMIPENDSET; } /* Initialize Wave player application */ WavePlayer_Init(); /* Initialize the Thermometer application */ LM75_Init(); /* Enable Leds toggling */ Demo_LedShow(ENABLE); /* COMP2 Configuration */ Demo_COMPConfig(); /* Enable Leds toggling */ Demo_LedShow(ENABLE); Demo_SysTickConfig(); }
/** * @brief Current measurement in different MCU modes: RUN/HALT/LowPower withouto LCD/LowPower with LCD * @caller main and ADC_Icc_Test * @param MCU state * @retval ADC value. */ u16 ADC_Icc_Test(u8 Mcu_State) { uint16_t res; uint8_t i; /* Test MCU state for configuration */ switch (Mcu_State) { /* test Run mode nothing to do */ case MCU_RUN: break; /* Low power mode */ case MCU_LPR: Halt_Init(); sim(); /* To prepare to start counter */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* To configure Low Power */ LPR_init(); break; /* Halt mode */ case MCU_HALT: /* Init for Halt mode */ Halt_Init(); sim(); /* To prepare to start counter */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Falling edge for start counter */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); delay_10us(1); /* MCU in halt during measurement */ /* Wake up by Interrupt done counter Input Port E pin 6 */ halt(); break; case MCU_LPR_LCD: PWR->CSR2 = 0x2; sim(); /* To configure GPIO for reduce current. */ GPIO_LowPower_Config(); /* To prepare to start counter */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* To configure Low Power */ LPR_init(); break; } sim(); /* re-start ADC chanel 24 for Current measurement */ ADC_Icc_Init(); /* Read ADC for current measurmeent */ /* initialize result */ res = 0; for(i=8; i>0; i--) { /* start ADC convertion by software */ ADC_SoftwareStartConv(ADC1); /* wait until end-of-covertion */ while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0 ); /* read ADC convertion result */ res += ADC_GetConversionValue(ADC1); } /* ICC_CNT_EN invalid */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); GPIO_Init(BUTTON_GPIO_PORT, USER_GPIO_PIN,GPIO_Mode_In_FL_IT); rim(); /* Disable ADC 1 for reduce current */ ADC_Cmd(ADC1, DISABLE); CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE); if (Mcu_State !=MCU_LPR_LCD) { CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE); LCD_GLASS_Init(); } return (res>>3); }
/** * @brief Main program * @param None * @retval None */ 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_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ /* RTC configuration -------------------------------------------------------*/ RTC_Config(); /* Configure the SysTick to generate an interrupt each 250 ms */ SysTickConfig(); /* LCD GLASS Initialization */ LCD_GLASS_Init(); /* Clear the LCD GLASS */ LCD_GLASS_Clear(); /* Configure STM32L152-EVAL LED1 and LED2 as Output push-pull */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); while (1) { /* Display " STM32L " string on LCD glass in scrolling mode */ LCD_GLASS_ScrollString(LCD_String, SCROLL_NUM, SCROLL_SPEED); /* Display String on the LCD */ #ifdef USE_STM32L152D_EVAL LCD_GLASS_DisplayString("STOPMOD"); #else LCD_GLASS_DisplayString("STOPMODE"); #endif /* Enable Wakeup Counter */ RTC_WakeUpCmd(ENABLE); /* Enter Stop Mode */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Enable Wakeup Counter */ RTC_WakeUpCmd(DISABLE); /* After wake-up from STOP reconfigure the system clock */ /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET) {} /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {} /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while (RCC_GetSYSCLKSource() != 0x0C) {} } }
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); } }
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(); uint8_t rxBuf[4]; uint8_t txBuf[16]; uint8_t chByte[2]; uint8_t chMainStep=MAIN_STEP_IDLE; int16_t* iCurentAdcValue=(int16_t*)chByte; // теперь тут будет лежать последнее измеренное число /* Configure RTC Clocks */ RTC_Configuration(); /* 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 */ conf_analog_all_GPIOS(); /* configure all GPIOs as analog input */ InitButton(); MesureCurInit(); LCD_GLASS_Init();/* Initializes the LCD glass */ // RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK , ENABLE); //RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK | P_GATE1_GPIO_PORT_CLK | /// P_GATE2_GPIO_PORT_CLK | N_GATE1_GPIO_PORT_CLK | // N_GATE2_GPIO_PORT_CLK , ENABLE); Delay.Init(); DbgUART.UART_Init(USART3); i2cMgr.SetDbgUART(&DbgUART); i2cMgr.Init(); calipers.Init(); calipers.Callback=CallBackCalipers; // Setup i2cCmd to write config data to ADC txBuf[0]=0x88; //Bits 3 and 2 control the ADS1100Тs data rate "1 0"= 16SPS I2C_command.Address=0x48; I2C_command.DataToRead.Length = 0; I2C_command.DataToRead.Buf=rxBuf; I2C_command.DataToWrite.Buf = txBuf; I2C_command.DataToWrite.Length = 1; I2C_command.Callback=CallBackI2C; i2cMgr.AddCmd(I2C_command); // Setup i2cCmd to read data from ADC I2C_command.Address=0x48; I2C_command.DataToRead.Length = 4; I2C_command.DataToRead.Buf=rxBuf; I2C_command.DataToWrite.Buf = txBuf; I2C_command.DataToWrite.Length = 0; I2C_command.Callback=CallBackI2C; /* Display Welcome message */ // LCD_GLASS_ScrollSentence((uint8_t*)" CELESTIA ONLINE ",1,SCROLL_SPEED); Delay.Reset(&TimeDelay); Delay.Reset(&DbgDelay); MesureCurStop(); char chI2cCounter=0; MesureCurUpward(); chflagI2C=1; while(1){ i2cMgr.Task(); calipers.Task(); switch (chMainStep) { case MAIN_STEP_IDLE: if (calipers.GetState()==SPI_END_RX) //при выходе из холостго режима пропускаем первый отсчет со штангена, чтобы ток в датчике { chMainStep=MAIN_STEP_WAIT_CALIPERS_START; DbgUART.SendPrintF("OUT IDLE \n"); MesureCurUpward(); // включаем ток chflagI2C=0; } break; case MAIN_STEP_WAIT_CALIPERS_START: if (calipers.GetState()==SPI_IDLE) // давно небыло посылок с штангена, { DbgUART.SendPrintF("IN IDLE \n"); chMainStep=MAIN_STEP_IDLE; // переходим в холостой режим MesureCurStop(); //отключаем ток в датчике. } if (calipers.GetState()==SPI_START_RX) // начало приема данных со штангена { //DbgUART.SendPrintF("IN I2C \n"); chMainStep=MAIN_STEP_WAIT_I2C; i2cMgr.AddCmd(I2C_command); } break; case MAIN_STEP_WAIT_I2C: if (chflagI2C==1) // закончилась работа с I2C { chMainStep=MAIN_STEP_WAIT_CALIPERS_END; MesureCurToggle(); // переключаем направление тока } break; case MAIN_STEP_WAIT_CALIPERS_END: if (calipers.GetState()==SPI_END_RX) // закончилcz прием данных о штангена { chByte[0]=rxBuf[1]; chByte[1]=rxBuf[0]; DbgUART.SendPrintF("ACD_VAL=%d \n",*iCurentAdcValue); LCD_GLASS_Clear(); tiny_sprintf(strDisp, " %d ", calipers.iSpiDataRx ); LCD_GLASS_DisplayString( (unsigned char *) strDisp ); DbgUART.SendPrintF("CALIPERS_VAL=%d \n",calipers.iSpiDataRx); DbgUART.SendPrintF("OUT I2CE \n"); chMainStep=MAIN_STEP_WAIT_CALIPERS_START; } break; } //switch // if (Delay.Elapsed(&DbgDelay,100)) DbgUART.SendPrintF("i2c flag=%d main_state=%d \n ",chflagI2C, chMainStep) ; /* if (chflagI2C==1) // закончилась работа с I2C { MesureCurToggle(); chflagI2C=0; } if (Delay.Elapsed(&DbgDelay,250)) { if (chI2cCounter<=10) { //MesureCurToggle(); chByte[0]=rxBuf[1]; chByte[1]=rxBuf[0]; DbgUART.SendPrintF("ACD_VAL=%d \n",*iCurentAdcValue); rxBuf[0]=0; rxBuf[1]=0; chI2cCounter++; //chflagI2C=0; i2cMgr.AddCmd(I2C_command); } } */ if (flag_UserButton == TRUE) { clearUserButtonFlag(); chI2cCounter=0; } } }
/** * @brief main entry point. * @par Parameters None * @retval void None * @par Required preconditions: None */ void main(void) { uint8_t PayloadLength, data_sensor, *bufMessage; /* deinit I/O ports */ DeInitClock(); DeInitGPIO(); /* Select HSI as system clock source */ #ifdef USE_HSI CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16); #else CLK_SYSCLKSourceSwitchCmd(ENABLE); /* Select 2MHz HSE as system clock source */ CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE); CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_4); CLK_HSICmd(DISABLE); #endif // Initializes the LCD glass LCD_GLASS_Init(); /* LED button init: GPIO set in push pull */ GPIO_Init( LED_GPIO_PORT, LED_GPIO_PIN, GPIO_Mode_Out_PP_Low_Fast); // set to 0 GPIOE->ODR &= ~LED_GPIO_PIN; /* USER button init: GPIO set in input interrupt active mode */ GPIO_Init( BUTTON_GPIO_PORT, USER_GPIO_PIN, GPIO_Mode_In_FL_IT); EXTI_SetPinSensitivity(EXTI_Pin_7, EXTI_Trigger_Falling); //* Init Bar on LCD all are OFF BAR0_OFF; BAR1_OFF; BAR2_OFF; BAR3_OFF; enableInterrupts(); //* At power on VDD diplays bufMessage = NDEFmessage; if (EEMenuState > STATE_TEMPMEAS) EEMenuState = STATE_CHECKNDEFMESSAGE; FLASH_Unlock(FLASH_MemType_Data ); state_machine = EEMenuState ; delayLFO_ms (1); if (EEInitial == 0) { User_WriteFirmwareVersion (); EEInitial =1; } while (1) { switch (state_machine) { case STATE_VREF: // measure the voltage available at the output of the M24LR04E-R Vref_measure(); delayLFO_ms (2); break; case STATE_CHECKNDEFMESSAGE: // read the NDEF message from the M24LR04E-R EEPROM and display it if it is found if (User_ReadNDEFMessage (&PayloadLength) == SUCCESS) User_DisplayMessage (bufMessage,PayloadLength); // User_DisplayMessageActiveHaltMode (PayloadLength); else User_DisplayMessage((uint8_t*)ErrorMessage,20); break; case STATE_TEMPMEAS: // read the ambiant tempserature from the STTS751 User_GetOneTemperature (&data_sensor); // display the temperature User_DisplayOneTemperature (data_sensor); delayLFO_ms (2); break; break; /* for safe: normaly never reaches */ default: LCD_GLASS_Clear(); LCD_GLASS_DisplayString("Error"); state_machine = STATE_VREF; break; } } }
/** * @brief main entry point. * @par Parameters None * @retval void None * @par Required preconditions: None */ void main(void) { uint8_t PayloadLength, data_sensor, *bufMessage; /* deinit I/O ports */ DeInitClock(); DeInitGPIO(); /* Select HSI as system clock source */ #ifdef USE_HSI CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16); #else CLK_SYSCLKSourceSwitchCmd(ENABLE); /* Select 2MHz HSE as system clock source */ CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE); CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_4); CLK_HSICmd(DISABLE); #endif // Initializes the LCD glass LCD_GLASS_Init(); /* LED button init: GPIO set in push pull */ GPIO_Init( LED_GPIO_PORT, LED_GPIO_PIN, GPIO_Mode_Out_PP_Low_Fast); // set to 0 GPIOE->ODR &= ~LED_GPIO_PIN; /* USER button init: GPIO set in input interrupt active mode */ GPIO_Init( BUTTON_GPIO_PORT, USER_GPIO_PIN, GPIO_Mode_In_FL_IT); EXTI_SetPinSensitivity(EXTI_Pin_7, EXTI_Trigger_Falling); //* Init Bar on LCD all are OFF BAR0_OFF; BAR1_OFF; BAR2_OFF; BAR3_OFF; enableInterrupts(); //* At power on VDD diplays bufMessage = NDEFmessage; if (EEMenuState > STATE_TEMPMEAS) EEMenuState = STATE_CHECKNDEFMESSAGE; FLASH_Unlock(FLASH_MemType_Data ); state_machine = EEMenuState ; delayLFO_ms (1); if (EEInitial == 0) { User_WriteFirmwareVersion (); EEInitial =1; } while (1) { switch (state_machine) { case STATE_VREFF: // measure the voltage available at the output of the M24LR04E-R Vref_measure(); delayLFO_ms (2); //turn on led GPIO_SetBits(GPIOE, GPIO_Pin_6); break; case STATE_VBIO: //measure the output voltage of biosensor through Pin 7 Port E CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE); ADC_DeInit(ADC1); ADC_VrefintCmd(ENABLE); delay_10us(3); GPIO_DeInit(GPIOE); GPIO_Init(GPIOE,GPIO_Pin_7 ,/*GPIO_Mode_In_FL_No_IT*/GPIO_Mode_In_PU_No_IT); ADC_Cmd(ADC1, ENABLE); ADC_Init(ADC1, ADC_ConversionMode_Single,ADC_Resolution_12Bit, ADC_Prescaler_1); ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels, ADC_SamplingTime_9Cycles); ADC_ChannelCmd(ADC1, ADC_Channel_3, ENABLE); delay_10us(3); // Important delay res = 0; res_2 = 0; i=0; for(i=8; i>0; i--) { /* start ADC convertion by software */ ADC_SoftwareStartConv(ADC1); /* wait until end-of-covertion */ while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0 ); /* read ADC convertion result */ res += ADC_GetConversionValue(ADC1); } /* de-initialize ADC*/ ADC_VrefintCmd(DISABLE); ADC_DeInit(ADC1); /* disable SchmittTrigger for ADC_Channel_24, to save power */ ADC_SchmittTriggerConfig(ADC1, ADC_Channel_3, DISABLE); CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE); ADC_ChannelCmd(ADC1, ADC_Channel_3, DISABLE); res = res>>3; P_VREFINT_Factory = VREFINT_Factory_CONV_ADDRESS; #ifdef VREFINT_FACTORY_CONV if ((*P_VREFINT_Factory>VREFINT_Factory_CONV_MIN ) && (*P_VREFINT_Factory<VREFINT_Factory_CONV_MAX )) { /* If the value exists: Adds the hight byte to FullVREF_FACTORY */ FullVREF_FACTORY = VREFINT_Factory_CONV_MSB; FullVREF_FACTORY += *P_VREFINT_Factory; res_2 = (float)(FullVREF_FACTORY*VDD_FACTORY); res_2 /= res; } else { res_2 = (VREF/res) * ADC_CONV; // usally res>>3 } #else /* We use the theorcial value */ res_2 = (VREF/res) * ADC_CONV; #endif /* Vdd_appli in mV */ res_2*= 1000L; convert_into_char (res_2, tab); /* To add unit and decimal point */ tab[5] = 'V'; tab[4] = ' '; tab[1] |= DOT; /* To add decimal point for display in volt */ tab[0] = ' '; LCD_GLASS_DisplayStrDeci(tab); delayLFO_ms (2); //LCD_GLASS_DisplayString("V BIO"); break; case STATE_CHECKNDEFMESSAGE: // read the NDEF message from the M24LR04E-R EEPROM and display it if it is found if (User_ReadNDEFMessage (&PayloadLength) == SUCCESS) User_DisplayMessage (bufMessage,PayloadLength); // User_DisplayMessageActiveHaltMode (PayloadLength); else User_DisplayMessage(ErrorMessage,20); break; case STATE_TEMPMEAS: // read the ambiant tempserature from the STTS751 User_GetOneTemperature (&data_sensor); // display the temperature User_DisplayOneTemperature (data_sensor); delayLFO_ms (2); break; break; /* for safe: normaly never reaches */ default: LCD_GLASS_Clear(); LCD_GLASS_DisplayString("Error"); state_machine = STATE_VREFF; break; } } }
/*--------------------------------------------------------------------------- Main program start here *---------------------------------------------------------------------------*/ int main() { GPIO_InitTypeDef pa0; RCC_RTC_Configuration(); LCD_GLASS_Init(); LCD_GLASS_Configure_GPIO(); init_USART(); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); GPIO_StructInit(&pa0); pa0.GPIO_Mode = GPIO_Mode_IN; pa0.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOA,&pa0); while(1) { if( GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 1 && state == 0) { count++; sprintf(DataSendToServer,"GET /cpe312/index.php?Name=TESTING_%d HTTP/1.1\r\nHost: markdang.lnw.mn\r\n\r\n",count); // Test AT startup send_data("AT\r\n"); wait_data("OK"); // Restart module send_data("AT+RST\r\n"); wait_data("ready"); display("OK RST"); // Set Station & softAP Mode send_data("AT+CWMODE_CUR=3\r\n"); wait_data("OK"); display("STA+AP"); // Set Station & softAP Mode send_data("AT+CWJAP_CUR=\"CPE312\",\"25033333\"\r\n"); wait_data("OK"); display("SET AP"); // Set TCP , Address & Port : Check data http://markdang.lnw.mn/cpe312/show_data.php send_data("AT+CIPSTART=\"TCP\",\"markdang.lnw.mn\",80\r\n"); wait_data("CONNECT"); display("SETTCP"); length = strlen(DataSendToServer); // find length of data sprintf(nbr_DataSendToServer, "AT+CIPSEND=%d\r\n", length); // Set data size // Send length of data to server send_data(nbr_DataSendToServer); wait_data(">"); display("SetLEN"); // Send data to server send_data(DataSendToServer); wait_data("SEND OK"); display("SENDOK"); // Close AP send_data("AT+CWQAP\r\n"); wait_data("OK"); display("Close"); state = 1; } else if ( GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0 && state == 1) { state = 0; } display("ready "); } }
/** * @brief Current measurement in different MCU modes: * RUN/SLEEP/LowPower/STANDBY with/without RTC * @caller main and ADC_Icc_Test * @param MCU state * @retval ADC value. */ uint16_t ADC_Icc_Test(uint8_t Mcu_State) { GPIO_InitTypeDef GPIO_InitStructure; uint16_t adc_measure; uint32_t i; RCC_TypeDef SavRCC; /* Reset UserButton State */ UserButton = FALSE; /* Start counter */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Disable the RTC Wakeup Interrupt */ RTC_ITConfig(RTC_IT_WUT, DISABLE); /* Disable LCD */ LCD_Cmd(DISABLE); /* wait until LCD disable */ while (LCD_GetFlagStatus(LCD_FLAG_ENS) == SET); /*Reset Idd-WakeUP flag*/ Idd_WakeUP = FALSE; /* Set IO in lowpower configuration*/ GPIO_LowPower_Config(); /*Disable fast wakeUp*/ PWR_FastWakeUpCmd(DISABLE); /* Test MCU state for configuration */ switch (Mcu_State) { /* Run mode : Measurement Measurement performed with MSI 4 MHz without RTC*/ case MCU_RUN: /* switch on MSI clock */ SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ; /* shitch on MSI clock */ Config_RCC(&SavRCC); SysTick->CTRL = 0; RCC->APB1ENR = 0; /* To run nops during measurement: it's the best case for low current */ for (i=0;i<0xffff;i++) { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } break; /* SLEEP mode : Measurement performed with MSI 4 MHz without RTC in WFI mode*/ case MCU_SLEEP: SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ; Config_RCC(&SavRCC); Config_Systick_50ms(); Delay(1); /* Request Wait For Interrupt */ PWR_EnterSleepMode(PWR_Regulator_ON,PWR_SLEEPEntry_WFI); break; /* RUN LOW POWER mode : Measurement performed with MSI 32 Khz without RTC */ case MCU_LP_RUN: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable The ultra Low Power Mode */ PWR_UltraLowPowerCmd(ENABLE); /* Save the RCC configuration registers */ Config_RCC(&SavRCC); /* Stop the sys tick in order to avoid IT */ SysTick->CTRL = 0; #ifdef TESTINRAM SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; PWR_EnterLowPowerRunMode(ENABLE); while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ; DisableInterrupts(); EnterLPRUNModeRAM(); EnableInterrupts(); #else /* Swith in MSI 32KHz */ SetHSICLKToMSI(RCC_MSIRange_64KHz,DIV2,NoRTC) ; PWR_EnterLowPowerRunMode(ENABLE); while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ; /* Launch the counter */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* To run the nop during measurement: it's the best case for low current until counter reach detected by IT --> Idd_WakeUP */ do{ __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } while (Idd_WakeUP == FALSE ); #endif PWR_EnterLowPowerRunMode(DISABLE); while(PWR_GetFlagStatus(PWR_FLAG_REGLP) != RESET) ; break; /* SLEEP LOW POWER mode Measurement done to MSI 32 Khz without RTC */ case MCU_LP_SLEEP: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); /* To save the RCC configuration registers */ Config_RCC(&SavRCC); /* To stop the sys tick for avoid IT */ SysTick->CTRL = 0; /* Swith in MSI 32KHz */ SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; #ifdef TESTINRAM DisableInterrupts(); EnterLPSLEEPModeRAM(); EnableInterrupts(); #else /* Falling edge for start counter */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Request Wait For Interrupt */ PWR_EnterSleepMode(PWR_Regulator_LowPower,PWR_SLEEPEntry_WFI); #endif break; /* STOP modes Measurement done to MSI 32 Khz without or with RTC */ case MCU_STOP_NoRTC: case MCU_STOP_RTC: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); /* To save the RCC configuration registers */ Config_RCC(&SavRCC); /* To stop the sys tick for avoid IT */ SysTick->CTRL = 0; /* Swith in MSI 32KHz */ if( Mcu_State == MCU_STOP_NoRTC ) SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; else SetHSICLKToMSI(RCC_MSIRange_0,DIV2,WITHRTC) ; /* Falling edge for start counter */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Request Wait For Interrupt */ PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI); break; /* Standby mode without RTC Measurement done to MSI 32 Khz without RTC */ case MCU_STBY: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); RTC_OutputTypeConfig(RTC_OutputType_PushPull); RTC_OutputConfig(RTC_Output_WakeUp,RTC_OutputPolarity_High); /* To configure PC13 WakeUP output */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 ; //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_Init( GPIOC, &GPIO_InitStructure); // GPIO_Init( GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOC, GPIO_PinSource13,GPIO_AF_RTC_AF1) ; //GPIO_PinAFConfig(GPIOA, GPIO_PinSource0,GPIO_AF_RTC_AF1) ; Config_RCC(&SavRCC); SysTick->CTRL = 0; /* Swith in MSI 32KHz */ SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; PWR_WakeUpPinCmd(PWR_WakeUpPin_1,ENABLE); PWR_UltraLowPowerCmd(ENABLE); PWR_EnterSTANDBYMode(); /* Stop here WakeUp EXIT on RESET */ break; } SetHSICLK(); Config_Systick(); RCC->AHBENR = SavRCC.AHBENR; PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ; /* Read ADC for current measurmeent */ adc_measure = Current_Measurement(); /* ICC_CNT_EN Hi */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); UserButton = TRUE; /* To restore RCC registers */ RCC->APB1ENR = SavRCC.APB1ENR; RCC->APB2ENR = SavRCC.APB2ENR; RCC->AHBLPENR = SavRCC.AHBLPENR; RCC->APB1LPENR = SavRCC.APB1LPENR; RCC->APB2LPENR = SavRCC.APB2LPENR; /* Need to reinit RCC for LCD*/ RCC_Configuration(); PWR_EnterLowPowerRunMode(DISABLE); /* Disable Ultra low power mode */ PWR_UltraLowPowerCmd(DISABLE); /* Disable FLASH during SLeep LP */ FLASH_SLEEPPowerDownCmd(DISABLE); Restore_GPIO_Config(); /* Clear Wake Up flag */ PWR_ClearFlag(PWR_FLAG_WU); /* Enable PVD */ PWR_PVDCmd(ENABLE); LCD_GLASS_Init(); return (adc_measure); }
int main(void) { int i; RCC_Configuration(); //????????????? NVIC_Configuration(); LED_Config(); TIM7_Configuration(10) ; RCC_Config(); ADC_initial(); UART1_Init(); UART1_Config(9600); UART1_Cmd(ENABLE); UART1_Write("stm start",9); LCD_GLASS_Configure_GPIO(); LCD_GLASS_Init(); while (1) { int wdt=0; int adc_wdt=0; double adc=0; //// solution 2 working String i=0; memcpy(buff2,buff, strlen(buff)); // ? buff ??? buff2 memset(buff, 0, strlen(buff)); // ?? buff ??????? while(1) { if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE) != RESET) { char c = USART_ReceiveData(USART1); i=i+1; if(c == '\r') break; else if (c == '\n') break; else sprintf (buff, "%s%c", buff,c); }else { wdt++; adc_wdt++; if(adc_wdt%100==0) { adc=(adc*99.0+GetADC())/100.0; } if(adc_wdt>10000) { adc_wdt=0; LCDPrint(" %0.1f ",adc); } if(wdt==50) { wdt=0; for(i=0;i<4;i++) { if(flag[i]==0) { LED[i]++; if(LED[i]>300) { flag[i]=1; } }else { LED[i]--; if(LED[i]==0) { flag[i]=0; } } } } } } /* strcat(buff,"\n"); UART1_Write(buff, strlen(buff)); Lcd_print(buff); */ // UART1_Write(")",1); USART_ClearFlag(USART1, USART_FLAG_RXNE); } }
int main(void) { bool StanbyWakeUp ; float Current_STBY; /*!< 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 */ Int_CurrentSTBY = Current_Measurement(); /* Check if the StandBy flag is set */ if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET) { /* System resumed from STANDBY mode */ /* Clear StandBy flag */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); PWR_ClearFlag(PWR_FLAG_SB); StanbyWakeUp = TRUE; } else { StanbyWakeUp = FALSE; } PWR_PVDCmd(DISABLE); RCC_Configuration(); 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(); enableInterrupts(); /* Warning ! in TSL Init the sysTick interrupt is setted to: SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/ /* Init Touch Sensing configuration */ TSL_Init(); sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1; sMCKeyInfo[0].Setting.b.ENABLED = 1; sMCKeyInfo[0].DxSGroup = 0x00; /* Initializes the LCD glass */ LCD_GLASS_Init(); // EECE 337 Code -- Start char str[50]; // Used to display results unsigned int delay_time = 5000; // Will delay for 5 seconds const unsigned int numItems = 10; // # items in array int MyArray[10] = { 365, 245, -499, 0, 23, 8, 200, -4, -50, 25 }; int minimum = 0; // Will hold minimum value int maximum = 0; // Will hold maximum value // Call Function to obtain Min and Max values from array min_max(MyArray, numItems, &minimum, &maximum); // Copy min result to str sprintf (str, "%d", minimum); // Display on LCD LCD_GLASS_DisplayString(str); // Pause for 5 seconds Delay(delay_time); // Clear LCD LCD_GLASS_Clear(); // Copy max result to str sprintf (str, "%d", maximum); // Display on LCD LCD_GLASS_DisplayString(str); // Pause for 5 seconds Delay(delay_time); // EECE 337 Code -- End return(0); }