/** * @brief Automatic test switch to LSE clock from HSI and return to HSI * @caller auto_test * @param None * @retval None */ void test_LSE(void) { /* Switch the clock to LSE */ LCD_GLASS_DisplayString("LSE"); CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); CLK_LSEConfig(CLK_LSE_ON); delay_ms(LSE_DELAY); if((CLK->ECKCR & CLK_ECKCR_LSERDY) == RESET) { LCD_GLASS_DisplayString("LSE"); delay_ms(LSE_DELAY); if((CLK->ECKCR & CLK_ECKCR_LSERDY) == RESET) { LCD_GLASS_DisplayString("LSE"); delay_ms(LSE_DELAY); if((CLK->ECKCR & CLK_ECKCR_LSERDY) == RESET) { /* Switch the clock to HSI*/ CLK_LSEConfig(CLK_LSE_OFF); CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_8); CLK_HSICmd(ENABLE); while (((CLK->ICKCR)& 0x02)!=0x02); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); while(1) { LCD_GLASS_ScrollSentence("LSE Not OK ",1,SCROLL_SPEED); //Press reset for exit KeyPressed = FALSE; } } } } /* Wait flag LSE ready */ while (!((CLK->ECKCR)& CLK_ECKCR_LSERDY)); /* Switch in LSE clock */ CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSE); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); LCD_GLASS_DisplayString("LSE OK"); /* Switch the clock to HSI */ CLK_LSEConfig(CLK_LSE_OFF); CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_8); CLK_HSICmd(ENABLE); while (((CLK->ICKCR)& 0x02)!=0x02); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); delay_ms(100); }
/** * @brief this function checks if a NDEF message is available * @par Parameters None * @retval none */ static void User_DisplayMessageActiveHaltMode ( uint8_t PayloadLength ) { //Switch the clock to LSE and disable HSI #ifdef USE_LSE CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSE); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); CLK_HSICmd(DISABLE); CLK->ECKCR &= ~0x01; #else CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSI); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); CLK_HSICmd(DISABLE); CLK->ECKCR &= ~0x01; #endif // disable interupt sim(); // To copy function DISPLAYRAM in RAM section DISPLAY #ifdef _COSMIC_ if (!(_fctcpy('D'))) while(1); #endif Display_Ram (); // Call in RAM // state_machine = STATE_VREF; #ifdef USE_HSI //Switch the clock to HSI CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16); CLK_HSICmd(ENABLE); while (((CLK->ICKCR)& 0x02)!=0x02); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); #else CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_2); // Select 2MHz HSE as system clock source CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE); // wait until the target clock source is ready while (((CLK->SWCR)& 0x01)==0x01); // wait until the target clock source is ready CLK_SYSCLKSourceSwitchCmd(ENABLE); #endif // enable interupt rim(); }
void LowPower_CLK_Config(void) { CLK_SYSCLKSourceSwitchCmd(ENABLE);//使能时钟切换 CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSI);//选择内部低速时钟作为时钟源 CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);//设置系统时钟分频 while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_LSI);//等待时钟稳定 CLK_HSICmd(DISABLE); //关闭原先的 CLK source CLK_HSEConfig(CLK_HSE_OFF); //关闭外部 CLK source }
/** * @brief Configure System Clock * @param None * @retval None */ static void CLK_Config(void) { /* Select HSE as system clock source */ CLK_SYSCLKSourceSwitchCmd(ENABLE); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE); /* system clock prescaler: 1*/ CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSE) {} }
/*********************************************************************** * @brief Configure System Clock * @param None * @retval None ************************************************************************/ static void CLK_Config(void) { // Select HSI as system clock source CLK_SYSCLKSourceSwitchCmd(ENABLE); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); // system clock prescaler: 1 CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSI) {} }
/** * @brief this function checks if a NDEF message is available * @par Parameters None * @retval none */ static void User_DisplayMessage (uint8_t message[],uint8_t PayloadLength ) { //Switch the clock to LSE and disable HSI #ifdef USE_LSE CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSE); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); CLK_HSICmd(DISABLE); CLK->ECKCR &= ~0x01; #else CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSI); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); CLK_HSICmd(DISABLE); CLK->ECKCR &= ~0x01; #endif LCD_GLASS_ScrollSentenceNbCar(message,30,PayloadLength+6); #ifdef USE_HSI //Switch the clock to HSI CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16); CLK_HSICmd(ENABLE); while (((CLK->ICKCR)& 0x02)!=0x02); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); #else CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_2); // Select 2MHz HSE as system clock source CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE); // wait until the target clock source is ready while (((CLK->SWCR)& 0x01)==0x01); // wait until the target clock source is ready CLK_SYSCLKSourceSwitchCmd(ENABLE); #endif }
/** * @brief Function to initialize the entry in low power and wait modes * @caller test low power mode * @param None * @retval None */ void LPR_init(void) { /*Switch the clock to LSE and disable HSI*/ #ifdef USE_LSE CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSE); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); CLK_HSICmd(DISABLE); #else CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSI); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); CLK_HSICmd(DISABLE); #endif /*Configure event for WAKEUP and FUNCTION, disable the interrupts*/ sim(); /* To copy function LPR_Ram in RAM section LPRUN*/ #ifdef _COSMIC_ if (!(_fctcpy('L'))) while(1); #endif LPR_Ram(); // Call in RAM /*Switch the clock to HSI*/ CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_8); CLK_HSICmd(ENABLE); while (((CLK->ICKCR)& 0x02)!=0x02); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); CLK_SYSCLKSourceSwitchCmd(ENABLE); while (((CLK->SWCR)& 0x01)==0x01); }
void clock_config(void) { CLK_HSICmd(ENABLE); CLK_RTCClockConfig(CLK_RTCCLKSource_HSI,CLK_RTCCLKDiv_64); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); while(CLK_GetFlagStatus(CLK_FLAG_HSIRDY)==RESET); CLK_PeripheralClockConfig(CLK_Peripheral_LCD, ENABLE); CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE); CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE); CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE); CLK_PeripheralClockConfig(CLK_Peripheral_TIM3, ENABLE); CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE); };
/** * @brief Configure peripherals Clock * @param None * @retval None */ static void CLK_Config(void) { /* High speed internal clock prescaler: 1 */ CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); /* Select HSE as system clock source */ CLK_SYSCLKSourceSwitchCmd(ENABLE); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE); while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSE) {} /* Enable TIM4 CLK */ CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE); }
/** * @brief Configure peripheral clock * @param None * @retval None */ static void CLK_Config(void) { /* Select HSE as system clock source */ CLK_SYSCLKSourceSwitchCmd(ENABLE); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE); /*High speed external clock prescaler: 1*/ CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_2); while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSE) {} /* Enable SPI clock */ CLK_PeripheralClockConfig(CLK_Peripheral_SPI1, ENABLE); /* Enable DMA clock */ CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE); }
void main(void) { deInitClock(); deInitGPIO(); CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16); initDigitalControls(); initAnalogControls(); GPIO_Init(GPIOF, GPIO_Pin_0, GPIO_Mode_In_FL_IT); EXTI_SetPinSensitivity(EXTI_Pin_0, EXTI_Trigger_Rising); enableInterrupts(); initMemory(); while (1) { halt(); } }
/** * @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; } } }