コード例 #1
0
ファイル: sysfunction.c プロジェクト: eseawind/touchCabinet
/*设置系统时间*/
void SysSetTime(FUN_BLOCK **funBlock)
{
	DIS_SING *sing_temp;

	GetSubFunBlock(&pfunSubBlock);
	sing_temp = (DIS_SING *)(pfunSubBlock->current_display);
	pfunSubBlock->data_type = ZINUM;//显示属性

	RTC_ITConfig(RTC_IT_SEC, DISABLE);	//关RTC中断,防止systmtime被修改
	strcpy(sing_temp->y2 ,  "请输入时间");
	/*取得VIRTUAL_NUM_LENGTH位数的箱门数*/
	if(CANCEL == KeyDisplay(pfunSubBlock , 10))
	{
		FreeMem();
		return;
	}
	/*读取时间值*/
	systmtime.tm_year = 2000 + (sing_temp->y3[0]-'0')*10 + sing_temp->y3[1]-'0';
	systmtime.tm_mon = (sing_temp->y3[2]-'0')*10 + sing_temp->y3[3]-'0';
	systmtime.tm_mday = (sing_temp->y3[4]-'0')*10 + sing_temp->y3[5]-'0';
	systmtime.tm_hour = (sing_temp->y3[6]-'0')*10 + sing_temp->y3[7]-'0';
	systmtime.tm_min = (sing_temp->y3[8]-'0')*10 + sing_temp->y3[9]-'0';
	memset(sing_temp->y3 , 0 , 10);
	/*写入时间*/
	RTC_Configuration();
	Time_Adjust(&systmtime);//写入系统时间
	BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);

	strcpy(sing_temp->y2 ,  "系统时间修改成功");
	DisplaySubBlock(pfunSubBlock);
		
	FreeMem();
}
コード例 #2
0
ファイル: rtc.c プロジェクト: nodeboy/nodeboyRepo
void rt_hw_rtc_init(void)
{
    rtc.type	= RT_Device_Class_RTC;
    if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
    {
        rt_kprintf("rtc is not configured\n");
        rt_kprintf("please configure with set_date and set_time\n");
        if ( RTC_Configuration() != 0)
        {
            rt_kprintf("rtc configure fail...\r\n");
            return ;
        }
    }
    else
    {
        /* Wait for RTC registers synchronization */
        RTC_WaitForSynchro();
    }

    /* register rtc device */
    rtc.init 	= RT_NULL;
    rtc.open 	= rt_rtc_open;
    rtc.close	= RT_NULL;
    rtc.read 	= rt_rtc_read;
    rtc.write	= RT_NULL;
    rtc.control = rt_rtc_control;

    /* no private */
    rtc.user_data = RT_NULL;

    rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);

    return;
}
コード例 #3
0
/**
  * @brief  Apllication Initialisation Routine
  * @param  None
  * @retval : None
  */
void ApplicationInit(void)
{
  /* System Clocks Configuration */
  RCC_Configuration();
  /*Enables the clock to Backup and power interface peripherals    */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP | RCC_APB1Periph_PWR,ENABLE);
  
  /* SysTick Configuration*/
  SysTickConfig();
  
  /*Initialisation of TFT LCD */
  STM3210B_LCD_Init();
  
  /* Unlock the Flash Program Erase controller */
  FLASH_Unlock();
  /*RTC_NVIC Configuration */
  RTC_NVIC_Configuration();
  
  /* RTC Configuration*/
  RTC_Configuration();
  BKP_RTCOutputConfig(BKP_RTCOutputSource_None);
  
  /* General Purpose I/O Configuration */
  GPIO_Configuration();
  
  /* Battery Removal Emulation   */
  GPIO_SetBits(GPIOC, GPIO_Pin_8);
  
  while(!(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13)))
  {
    TamperEvent = 1;
  }
  
  /* Joystick NVIC Configuration  */
  NVIC_JoyStickConfig();

  /* Tamper pin NVIC Configuration  */
  Tamper_NVIC_Configuration();

  /* Configure PVD Supervisor to disable the Tamper Interrupt when voltage drops 
  below 2.5 volts*/
  PWR_PVDCmd(ENABLE);
  PWR_PVDLevelConfig(PWR_PVDLevel_2V5);
  PWR_BackupAccessCmd(ENABLE);

  /* Only JoyStick Sel Interrupt is enabled on startup */
  SelIntExtOnOffConfig(ENABLE);

  /* Tamper FeatureRTC  -   Enable Tamper Interrupt and configure for Low level */
  BKP_ITConfig(ENABLE);

  /* Enable Tamper Pin for Active low level: Tamper level detected for low level*/
  BKP_TamperPinLevelConfig(BKP_TamperPinLevel_Low);

  /* Enable tamper Pin Interrupt */
  BKP_TamperPinCmd(ENABLE);

  /*  Menu Initialisation  */
  MenuInit();
}
コード例 #4
0
/**
  * @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_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     

  /* Initialize LEDs LD3, LD4 and USER Button mounted on STM32VLDISCOVERY board */       
  STM32vldiscovery_LEDInit(LED3);
  STM32vldiscovery_LEDInit(LED4);
  STM32vldiscovery_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);

  /* Turn on LD3 */
  STM32vldiscovery_LEDOn(LED3);

  /* Enable PWR and BKP clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Allow access to BKP Domain */
  PWR_BackupAccessCmd(ENABLE);

  /* Configure RTC clock source and prescaler */
  RTC_Configuration();

  /* Configure the SysTick to generate an interrupt each 250 ms */
  SysTick_Configuration();
 
  while (1)
  {
  }
}
コード例 #5
0
ファイル: mcu.c プロジェクト: QXED/MutiNodesBy2.4GWireless
/***************************************************************************
Declaration : void init_mcu (void)

Function :    Initializes ATmega88 MCU
***************************************************************************/
void init_mcu (void)
{
#ifdef DEBUG
  debug();
#endif
  /* System Clocks Configuration */
  RCC_Configuration();
       
  /* Configure the GPIO ports */
  GPIO_Configuration();
 
  /* Configure EXTI Line9 to generate an interrupt on falling edge */
  EXTI_Configuration();

  /* SPI the GPIO ports */
  SPI_Configuration(); 
   
  /* USART  Configuration as SPI */
  USART1_Configuration();
  
  /* TIM2 Configuration */
  TIM2_Configuration();
  
  /* TIM3 Configuration */
  TIM3_Configuration();
  
  /* TIM4 Configuration */
  TIM4_Configuration();
  
   /* Configure RTC clock source and prescaler */
  RTC_Configuration(); 
   
  /* NVIC configuration */
  NVIC_Configuration();
}
コード例 #6
0
ファイル: main.c プロジェクト: DerekTan/STM32F107_ucosIII
/**
  * @brief   Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Setup the microcontroller system. Initialize the Embedded Flash Interface,  
     initialize the PLL and update the SystemFrequency variable. */
  SystemInit();

  /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */       
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_PBInit(Button_KEY, Mode_EXTI);

  /* Enable PWR and BKP clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Configure EXTI Line to generate an interrupt on falling edge */
  EXTI_Configuration();

  /* Configure RTC clock source and prescaler */
  RTC_Configuration();

  /* NVIC configuration */
  NVIC_Configuration();

  /* Configure the SysTick to generate an interrupt each 1 millisecond */
  SysTick_Configuration();

  /* Turn on LED1 */
  STM_EVAL_LEDOn(LED1);
  
  while (1)
  {
    /* Insert 1.5 second delay */
    Delay(1500);

    /* Wait till RTC Second event occurs */
    RTC_ClearFlag(RTC_FLAG_SEC);
    while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET);

    /* Alarm in 3 second */
    RTC_SetAlarm(RTC_GetCounter()+ 3);
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();

    /* Turn off LED1 */
    STM_EVAL_LEDOff(LED1);

    /* Request to enter STOP mode with regulator in low power mode*/
    PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
    
    /* At this stage the system has resumed from STOP mode -------------------*/
    /* Turn on LED1 */
    STM_EVAL_LEDOn(LED1);

    /* Configures system clock after wake-up from STOP: enable HSE, PLL and select 
       PLL as system clock source (HSE and PLL are disabled in STOP mode) */
    SYSCLKConfig_STOP();
  }
}
コード例 #7
0
ファイル: rtc.c プロジェクト: pyjhhh/stm32_f1x
 /**
  * @file   RTC_Init
  * @brief  RTC Initialization
  * @param  无
  * @retval 无
  */
void RTC_Init(void)
{
  if (BKP_ReadBackupRegister(BKP_DR1)!= 0xA5A5)
  {
    /* Backup data register value is not correct or not yet programmed (when
    the first time the program is executed) */
    printf("RTC not yet configured....\r\n");
    /* RTC Configuration */
     RTC_Configuration();
	   Time_Regulate();
	/* Adjust time by values entred by the user on the hyperterminal */
    printf("RTC configured....\r\n");
    BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
  }
  else
  {
    /* Check if the Power On Reset flag is set */
    if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
    {
      printf("Power On Reset occurred....\r\n");
    }
    /* Check if the Pin Reset flag is set */
    else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
    {
      printf("External Reset occurred....\r\n");
    }

    printf("No need to configure RTC....\r\n");
    /* Wait for RTC registers synchronization */
    RTC_WaitForSynchro();

    /* Enable the RTC Second */
    RTC_ITConfig(RTC_IT_SEC, ENABLE);
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
  }

   /* NVIC configuration */
   NVIC_Configuration();

#ifdef RTCClockOutput_Enable
  /* Enable PWR and BKP clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Allow access to BKP Domain */
  PWR_BackupAccessCmd(ENABLE);

  /* Disable the Tamper Pin */
  BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
                                 functionality must be disabled */

  /* Enable RTC Clock Output on Tamper Pin */
  BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock);
#endif

   /* Clear reset flags */
  RCC_ClearFlag();
  return;
}
コード例 #8
0
ファイル: main.c プロジェクト: timmy00274672/STM32-Learning
/*******************************************************************************
* Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
  debug();
#endif
   
  /* Clock configuration */
  RCC_Configuration();

  /* Enable PWR and BKP clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* GPIO configuration */
  GPIO_Configuration();

  /* Configure EXTI Line to generate an interrupt on falling edge */
  EXTI_Configuration();

  /* Configure RTC clock source and prescaler */
  RTC_Configuration();

  /* NVIC configuration */
  NVIC_Configuration();

  /* Configure the SysTick to generate an interrupt each 1 millisecond */
  SysTick_Configuration();

  /* Turn on led connected to GPIO_LED Pin6 */
  GPIO_SetBits(GPIO_LED, GPIO_Pin_6); 
  
  while (1)
  {
    /* Insert 1.5 second delay */
    Delay(1500);

    /* Wait till RTC Second event occurs */
    RTC_ClearFlag(RTC_FLAG_SEC);
    while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET);

    /* Alarm in 3 second */
    RTC_SetAlarm(RTC_GetCounter()+ 3);
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();

    /* Turn off led connected to GPIO_LED Pin6 */
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_6); 

    /* Request to enter STOP mode with regulator in low power mode*/
    PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
    
    /* At this stage the system has resumed from STOP mode -------------------*/
    /* Turn on led connected to GPIO_LED Pin6 */
    GPIO_SetBits(GPIO_LED, GPIO_Pin_6); 

    /* Configures system clock after wake-up from STOP: enable HSE, PLL and select 
       PLL as system clock source (HSE and PLL are disabled in STOP mode) */
    SYSCLKConfig_STOP();
  }
}
コード例 #9
0
/****************************************************************************
* 名    称:void clock_ini(void)
* 功    能:时钟初始化函数
* 入口参数:无
* 出口参数:无
* 说    明:
* 调用方法:
****************************************************************************/  
void clock_ini(void)
{       
#if defined  (STOP_Mode)  
    if(BKP_CheckLOCK_RTC() != BKP_RTC_Flag){  
        RTC_Configuration();
        RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv;
        RTC_InitStructure.RTC_SynchPrediv = SynchPrediv;
        RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;       
        while(RTC_Init(&RTC_InitStructure) == ERROR) {}
        Set_Time(time);
        BKP_LOCK_RTC();
    }else{
        while(RCC_GetFlagStatus(RCC_FLAG_PORRST) == RESET) {}
        while(RCC_GetFlagStatus(RCC_FLAG_PINRST) == RESET) {}
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
        PWR_RTCAccessCmd(ENABLE);
        RTC_WaitForSynchro();
    }   
    
    RTC_Alarm_Exit();
    RTC_NVIC_Configuration();
    
    RTC_ClearFlag(RTC_FLAG_ALRAF);
    PWR_ClearFlag(PWR_FLAG_WU);
#elif defined  (TANDBY_Mode)     
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
    PWR_RTCAccessCmd(ENABLE);
    PWR_ClearFlag(PWR_FLAG_WU);

    if(PWR_GetFlagStatus(PWR_FLAG_SB) != RESET) {
        PWR_ClearFlag(PWR_FLAG_SB);
        RTC_WaitForSynchro();
    }else {
        RTC_Configuration();
        RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv;
        RTC_InitStructure.RTC_SynchPrediv = SynchPrediv;
        RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;       
        while(RTC_Init(&RTC_InitStructure) == ERROR) {}
        Set_Time(time);
        RTC_ClearFlag(RTC_FLAG_ALRAF);
    }  
#endif    
}
コード例 #10
0
ファイル: c_entry.cpp プロジェクト: pavelruban-org/arm
extern "C" void __initialize_hardware_early()
{
	/* Configure the system clocks */
	RCC_Configuration();

	/* NVIC Configuration */
	NVIC_Configuration();

	/* Set up real time clock */
	RTC_Configuration();
}
コード例 #11
0
ファイル: RTC.c プロジェクト: jiangtaojiang/bloodpressure
void RTC_Config(void)	
{
	/*后备寄存器1中,存了一个特殊字符0xA5A5
	第一次上电或后备电源掉电后,该寄存器数据丢失,
	表明RTC数据丢失,需要重新配置 */
    if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) //检查是否第一次上电或后备电池已经掉电,
    {       
        Write_Log("Backup VBAT PowerDown or First time PowerUp,Initialize RTC\r\n");
        RTC_Configuration();
        BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
        
        time_now.tm_year = 2011;
        time_now.tm_mon = 10; //月份表示为0~11
        time_now.tm_mday = 13;
        time_now.tm_hour = 13;
        time_now.tm_min = 16;
        time_now.tm_sec = 38;
        Time_SetCalendarTime(time_now);//设置初始时间
    } 
    else //若后备寄存器没有掉电,则无需重新配置RTC
    {
        Write_Log("Backup VBAT Keep, Don't RTC Configuralation\r\n");
                    //等待RTC与APB同步
  		RTC_WaitForSynchro();
		RTC_WaitForLastTask();
	
  		//使能秒中断 
  		RTC_ITConfig(RTC_IT_SEC, ENABLE);  
  		RTC_WaitForLastTask();
    }
      //这里我们可以利用RCC_GetFlagStatus()函数查看本次复位类型
    if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
    {
		por_rst_flag = 1;	
        Write_Log("PowerUp Reset\r\n");
    }
    else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
    {
		pin_rst_flag = 1;
        Write_Log("pin Reset\r\n");
    }
    else if(PWR_GetFlagStatus(PWR_FLAG_WU)!= RESET)  //wakeup唤醒
    {
        Write_Log("WakeUp...\r\n");     
    }
    if(PWR_GetFlagStatus(PWR_FLAG_SB) != RESET) //检查是否由待机模式下唤醒,如是则不需要配置RTC
        /* System resumed from STANDBY mode */      
         /* Clear StandBy flag */
    PWR_ClearFlag(PWR_FLAG_SB);

        //清除RCC中复位标志
    RCC_ClearFlag();
	return;
}
コード例 #12
0
ファイル: mod_core.c プロジェクト: denisweir/STM32F40X
/**
  * @brief  Initialize the middleware libraries and stacks
  * @param  None
  * @retval None
  */
void MOD_LibInit(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

  MOD_GetParam(GLOBAL_SETTINGS_MEM , &Global_Config.d32);

  /* Force settings change to apply them */
  Global_Config.b.Configuration_Changed = 1;

  /* Starting USB Init. Process */
  GL_State_Message((uint8_t *)"USB Host Starting.  ");

  /*Init USB Host */
  USBH_Init(&USB_OTG_Core,
            USB_OTG_FS_CORE_ID,
            &USB_Host,
            &USBH_MSC_cb,
            &USBH_USR_cb);

  GL_State_Message((uint8_t *)"USB Host Started.");

  GL_State_Message((uint8_t *)"RTC and backup Starting.  ");
  /* Init RTC and Backup */
  if ( RTC_Configuration() == 0)
  {
    GL_State_Message((uint8_t *)"RTC and backup Started.");
    CONSOLE_LOG((uint8_t *)"[SYSTEM] RTC and backup Started.");
  }
  else
  {
    GL_State_Message((uint8_t *)"ERR : RTC could not be started.");
    CONSOLE_LOG((uint8_t *)"[ERR] RTC start-up FAILED .");
  }

  NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  SD_Init();

  if ( f_mount( 1, &MSD_fatfs ) != FR_OK )
  {
    /* fatfs initialisation fails*/
    CONSOLE_LOG((uint8_t *)"[FS] Cannot initialize FS on drive 1.");
  }
  else
  {
    CONSOLE_LOG((uint8_t *)"[FS] FS on drive 1 initialized.");
  }
}
コード例 #13
0
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
	{
		
	}
}
コード例 #14
0
/*********************************************************************************
  *Function     : void init(void)
  *Description  : initiale
  *Input        : none
  *Output       : none
  *Return       : none
  *author       : lz
  *date         : 6-December-2014
  *Others       : none        
**********************************************************************************/ 
void init(void)
{
    //disable JTAG-DP,release pin 29(PB3),30(PB4),23(PA15)
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO , ENABLE);
    
#ifdef DFU_BUILD_ENABLE
    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x5000); // lz
#endif

#ifdef SWD_JTAG_DISABLE
    /* Disable the Serial Wire JTAG Debug Port SWJ-DP */
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
#endif

    // Set Systick to 1ms interval, common to all SAM3 variants
    if (SysTick_Config(SystemCoreClock / 1000))
    {
        // Capture error
        while (true);
    }
    /* Configure the SysTick Handler Priority: Preemption priority and subpriority */
    NVIC_SetPriority(SysTick_IRQn, SYSTICK_IRQ_PRIORITY);	
    
    //digital pin  default output  low
    for (unsigned i = 0; i < FIRST_ANALOG_PIN+TOTAL_ANALOG_PINS; i++)
    {
        pinMode(i, OUTPUT);
        digitalWrite(i, LOW);
    }

    RTC_Configuration(); 

    DWT_Init();

#ifdef IWDG_RESET_ENABLE
    IWDG_Reset_Enable(3 * TIMING_IWDG_RELOAD);
#endif

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
    TIM1_Configuration();
    TIM_Cmd(TIM1, DISABLE); //定时器关闭
    NVIC_DisableIRQ(TIM1_UP_IRQn);
}
コード例 #15
0
ファイル: rtc.c プロジェクト: ShaohuiZhu/Haier-1
//interupt and rtc test OK!
void rtc_init(void)
{
	RTC_DateTypeDef RTC_DateStruct_set,RTC_DateStruct_get;
	RTC_TimeTypeDef RTC_TimeStruct_set,RTC_TimeStruct_get;
	RTC_Configuration();
	
	RTC_TimeStruct_set.RTC_H12 = RTC_H12_AM;
	RTC_TimeStruct_set.RTC_Hours = 10;
	RTC_TimeStruct_set.RTC_Minutes = 45;
	RTC_TimeStruct_set.RTC_Seconds = 0;
	
	RTC_DateStruct_set.RTC_Date = 16;
	RTC_DateStruct_set.RTC_Month = RTC_Month_July;
	RTC_DateStruct_set.RTC_WeekDay = RTC_Weekday_Wednesday;
	RTC_DateStruct_set.RTC_Year = 14;
	RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct_set);
	RTC_SetDate(RTC_Format_BCD, &RTC_DateStruct_set);
	
	RTC_GetTime(RTC_Format_BCD, &RTC_TimeStruct_get);
	RTC_GetDate(RTC_Format_BCD, &RTC_DateStruct_get);
}
コード例 #16
0
ファイル: rtc.c プロジェクト: malooei/yeejoin-workspace
void rt_hw_rtc_init(void)
{
	rtc.type	= RT_Device_Class_RTC;

	if (BKP_ReadBackupRegister(RTC_SET_FLAG_BKP16BITS) != 0xA5A5) {
		rt_kprintf("rtc is not configured\n");
		rt_kprintf("please configure with set_date and set_time\n");
		if ( RTC_Configuration() != 0) {
			rt_kprintf("rtc configure fail...\r\n");
			return ;
		}
	} else {
		/* Wait for RTC registers synchronization */
		RTC_WaitForSynchro();

		/* Wait until last write operation on RTC registers has finished */
		RTC_WaitForLastTask();
		RTC_ITConfig(RTC_IT_SEC, ENABLE); // 使能RTC秒中断
		RTC_WaitForLastTask();
	}

	/* register rtc device */
	rtc.init 	= RT_NULL;
	rtc.open 	= rt_rtc_open;
	rtc.close	= RT_NULL;
	rtc.read 	= rt_rtc_read;
	rtc.write	= RT_NULL;
	rtc.control = rt_rtc_control;

	/* no private */
	rtc.user_data = RT_NULL;

	rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);

	return;
}
コード例 #17
0
ファイル: rtc.c プロジェクト: weimingtom/stm32-gui
void RTC_Config_Init(void)
{
    if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A1 )
	{
	    RTC_Configuration(); 
		RTC_WaitForLastTask();
	//	RTC_SetCounter(Time_Regulate());		   	 	 
	   // RTC_Set(2010,11,14,15,38,30);

		RTC_WaitForLastTask(); 

		BKP_WriteBackupRegister(BKP_DR1, 0xA5A1);
	}
	else
	{
		RTC_WaitForSynchro();        				
													
	 	RTC_WaitForLastTask();       				
																									 
     	RTC_ITConfig(RTC_IT_SEC, ENABLE);   		
													
     	RTC_WaitForLastTask();
	} 
}
コード例 #18
0
/**
  * @brief  Setting up the time by Serial USART1.
  * @param  None
  * @retval None
  */
void RTC_SetTimeBySerial(void) {
  if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) {
    /* Backup data register value is not correct or not yet programmed (when
       the first time the program is executed) */

    printf("\r\n * Begin RTC initialization");
    
    /* RTC Configuration */
    RTC_Configuration();
    
    printf("\r\n * Please set calendar");
    
    /* setup year, month, date in 4, 2, 2 digits each */
    Date_Regulate();
    
    printf("\r\n * Please set time");

    /* Adjust time by values entered by the user on the hyperterminal */
    Time_Adjust();
    
    BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
  } else {
    /* Check if the Power On Reset flag is set */
    if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) {
      printf("\r\n * Power On Reset occurred....");
    }
    /* Check if the Pin Reset flag is set */  
    else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) {
      printf("\r\n\n * External Reset occurred....");
    }

    printf("\r\n * No need to configure RTC....");
    
    /* Check whether we've written year or month or day value before */
    if(BKP_ReadBackupRegister(BKP_DR2) == 0x0000 || BKP_ReadBackupRegister(BKP_DR3) == 0x0000) {
      /* setup year, month, date in 4, 2, 2 digits each */
      Date_Regulate();
    } else {
      
      uint16_t YY, MD;
      YY = BKP_ReadBackupRegister(BKP_DR2);
      MD = BKP_ReadBackupRegister(BKP_DR3);
      
      int month, day;
      if( (MD / 1000) % 10 == 0) {
        month = (MD / 100) % 10;
      } else {
        month = (MD / 1000) % 10 + (MD / 100) % 10 ;
      }
      
      if( (MD / 10) % 10 == 0 ) {
        day = MD % 10;
      } else {
        day = MD - (MD / 100) * 100;
      }
      
      printf("\r\n\n Previous written calendar data found !");
      printf("\r\n Written values are as follows :");
      printf("\r\n Year : %d, Month : %d, Day : %d", YY, month, day);
      printf("\r\n Above calendar datas will be used to set current calendar automatically\r\n");
      
      TranslateIntoYear(YY);
      TranslateIntoMonth(month);
      TranslateIntoDay(day);
    }
        
    /* NVIC MUST BE CONFIGURED before branch into power on reset */
    NVIC_InitTypeDef NVIC_InitStructure;
    EXTI_InitTypeDef EXTI_InitStructure;
  
    /* Configure one bit for preemption priority */
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  
    /* Enable the RTC Interrupt */
    NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    
    NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0xFF;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    
    /* Configure EXTI Line17 (RTC Alarm)to generate an interrupt on rising edge */
    EXTI_ClearITPendingBit(EXTI_Line17);
    EXTI_InitStructure.EXTI_Line = EXTI_Line17;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
    EXTI_Init(&EXTI_InitStructure);
  
    /* Wait for RTC registers synchronization */
    RTC_WaitForSynchro();
    
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    
    /* Alarm in 3 second */
    //RTC_SetAlarm(3);
    
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    
    /* Enable the RTC Second, RTC Alarm interrupt */
    RTC_ITConfig(RTC_IT_SEC || RTC_IT_ALR, ENABLE);
    
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
  }

#ifdef RTCClockOutput_Enable
  /* Enable PWR and BKP clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Allow access to BKP Domain */
  PWR_BackupAccessCmd(ENABLE);

  /* Disable the Tamper Pin */
  BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
                                 functionality must be disabled */

  /* Enable RTC Clock Output on Tamper Pin */
  BKP_RTCOutputConfig(BKP_RTCOutputSource_Second);
#endif
  
  /* Clear reset flags */
  RCC_ClearFlag();
}
コード例 #19
0
ファイル: RTC_Time.c プロジェクト: WrongChao/lammbo-fly
/*******************************************************************************
* Function Name  : RTC_Config
* Description    : 上电时调用本函数,自动检查是否需要RTC初始化, 
* 					若需要重新初始化RTC,则调用RTC_Configuration()完成相应操作
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RTC_Config(void)
{
	NVIC_InitTypeDef NVIC_InitStructure;

   //启用PWR和BKP的时钟(from APB1)
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

	//后备域解锁
	PWR_BackupAccessCmd(ENABLE);   //此要加,否则重启后无法更改时间

	//我们在BKP的后备寄存器1中,存了一个特殊字符0xA5A5
	//第一次上电或后备电源掉电后,该寄存器数据丢失,
	//表明RTC数据丢失,需要重新配置
	if (BKP_ReadBackupRegister(BKP_DR1) != 0xEDED)
	{
		//重新配置RTC
		RTC_Configuration();
		//配置完成后,向后备寄存器中写特殊字符0xA5A5
		BKP_WriteBackupRegister(BKP_DR1, 0xEDED);
		// Lcd_WriteString(0,1,0,Red,"ver 1.0");
	}
	else
	{
		//若后备寄存器没有掉电,则无需重新配置RTC
		//这里我们可以利用RCC_GetFlagStatus()函数查看本次复位类型
		if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
		{
			//Lcd_WriteString(0,3,0,Red,"BATTER OFF");//这是上电复位
		}
		else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
		{
		//	Lcd_WriteString(0,3,0,Red,"RESET");//这是外部RST管脚复位
		}
		//清除RCC中复位标志
		RCC_ClearFlag();

		//虽然RTC模块不需要重新配置,且掉电后依靠后备电池依然运行
		//但是每次上电后,还是要使能RTCCLK???????
		//RCC_RTCCLKCmd(ENABLE);
		//等待RTC时钟与APB1时钟同步
		//RTC_WaitForSynchro();

		//使能秒中断
		RTC_ITConfig(RTC_IT_SEC, ENABLE);
	//	RTC_ITConfig(RTC_IT_OW, ENABLE);
		//等待操作完成
		RTC_WaitForLastTask();
	}

#ifdef RTCClockOutput_Enable
	


	/* Allow access to BKP Domain */
	PWR_BackupAccessCmd(ENABLE);

	/* Disable the Tamper Pin */
	BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
								 functionality must be disabled */

	/* Enable RTC Clock Output on Tamper Pin */
	BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock);
#endif

  #ifdef  VECT_TAB_RAM
	NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
  #else  /* VECT_TAB_FLASH  */
	NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
  #endif

  
  /* Configure one bit for preemption priority */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  
  /* Enable the RTC Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

	return;
}
コード例 #20
0
/**
  * @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_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     
       
  /* RCC configuration */
  RCC_Configuration();
  
  /* TIM4 configuration */
  TIM4_Configuration();
  
  /* UART4 configuration */
  UART4_Configuration();
  
  /* WIZ820io SPI2 configuration */
  WIZ820io_SPI2_Configuration();  // one that is on left one
  
  /* WIZ820io SPI3 configuration */
  //WIZ820io_SPI3_Configuration();  // one that is on right one

  /* W5200 Configuration */
  Set_network();
  
  /* TLCD configuration */
  TLCD_Configuration();
  
  //TLCD_Write(0, 0, str1);
  //TLCD_Write(0, 1, str2);
  
  /* RTC Configuration */
  RTC_Configuration();
  
  /* EXIT4(Mode select button) configuration */
  EXTILine4_Configuration();
  
  /* EXIT5(F_SYNC : 100Hz) configuration */
  EXTILine5_Configuration();
  
  /* EXIT6(F_SCLK : 10KHz) configuration */
  EXTILine6_Configuration();
  
  /* myAccel3LV02 Configuration */
  Accel3LV02_Configuration();
  
  //myAccel3LV02 setup 1000.0111 Power on, enable all axis, self test off
  Accel_WriteReg(CTRL_REG1, 0xC7);
  // following routine setup myAccel3LV02 6g mode
  //Accel_WriteReg(CTRL_REG2, 0x80);
  
  /* GLCD configuration */
  GLCD_Configuration();
  
  // For TCP client's connection request delay
  presentTime = my_time;
  
  // When everything is set, print message
  printf("\r\n - System is ready - ");
    
  while(1) {
    if(TimerCount >= 1000) {  // thousand equals one second
      TimerCount = 0;
      
      // for Calculate connection delay
      my_time++;
      
      // retrieve axis data
      GetAccelValue(AXIS_X, &Xdata);
      GetAccelValue(AXIS_Y, &Ydata);
      GetAccelValue(AXIS_Z, &Zdata);
      
      char str[30];
      sprintf(str, "%d,%d,%d", 0xFFF&Xdata, 0xFFF&Ydata, 0xFFF&Zdata);
      TLCD_Clear();
      TLCD_Write(0, 0, str);
    }
    
    if(ParseUART4) {
      ParseUART4 = False; 
      
      // print Wiz810io configuration
      printSysCfg();
    }
    
    if(flag_uart == 1) {
      tmp_start = start;
    }
        
    switch(mode) {
    case SELECT_AXIS_X : break;
    case SELECT_AXIS_Y : break;
    case SELECT_AXIS_Z : break;
    }
    
    /* Ethernet Client Routine -----------------------------------------------*/
    /* SendFlag get set from when socket established and received any message */
    if(SendFlag) {
      SendFlag = False;
      
      char AxisData[30];
      for(order = 0; order < 100 ; order++) {
        float EW = 0;
        float NS = 0;
        float UD = 0;
        
        EW = data_x[order] * 1e-7;
        NS = data_y[order] * 1e-7;
        UD = data_z[order] * 1e-7;
        
        sprintf(AxisData, "%-0.7f,%-0.7f,%-0.7f\n", EW, NS, UD);
        
        // Only when socket is established, send data
        if(getSn_SR(SOCK_ZERO) == SOCK_ESTABLISHED) {
          /* send the received data */
          send(SOCK_ZERO, (uint8*)AxisData, strlen(AxisData), (bool)False);
        }
      }
    }
    
    /* Process client socket with port 5050 */
    //ProcessTcpClient(SOCK_ZERO);
    
  }
}
コード例 #21
0
void initRTC()
{

	mSecondsAlarm.AlarmCount = 0;
	mSecondsAlarm.AlarmInterval = 0;
	mSecondsAlarm.CurrentValue = 0;
	mSecondsAlarm.cb_func = 0;

	mMinutesAlarm.AlarmCount = 0;
	mMinutesAlarm.AlarmInterval = 0;
	mMinutesAlarm.CurrentValue = 0;
	mMinutesAlarm.cb_func = 0;

	mHoursAlarm.AlarmCount = 0;
	mHoursAlarm.AlarmInterval = 0;
	mHoursAlarm.CurrentValue = 0;
	mHoursAlarm.cb_func = 0;

	 /* Enable PWR and BKP clocks */
	  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

	  /* Allow access to BKP Domain */
	  PWR_BackupAccessCmd(ENABLE);



	if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
	{
		/* Backup data register value is not correct or not yet programmed (when
		       the first time the program is executed) */

		t_print("Configuring RTC....\n");

		RTC_Configuration();

		BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
	}
	else
	{
		t_print("RTC has time....\n");

		s_DateStructVar.Day = BKP_ReadBackupRegister(BKP_DR2);
		s_DateStructVar.Month = BKP_ReadBackupRegister(BKP_DR3);
		s_DateStructVar.Year = BKP_ReadBackupRegister(BKP_DR4);

		CheckForDaysElapsed();
	}

	/* Wait for RTC registers synchronization */
	RTC_WaitForSynchro();

	/* Enable the RTC Second */
	RTC_ITConfig(RTC_IT_SEC, ENABLE);
	/* Wait until last write operation on RTC registers has finished */
	RTC_WaitForLastTask();

	/* Enable the RTC Interrupt */
	NVIC_InitTypeDef NVIC_InitStructure;
	NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);
}
コード例 #22
0
ファイル: main.c プロジェクト: cortex-m3/stm32f10x_libs
/**
  * @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_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     

  /* Initialize LED1 mounted on STM3210X-EVAL board */       
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA , ENABLE);
	
	 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ; // USART 2
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
	
		 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ; // USART 2
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
	
	
  /* USARTx configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  */
	
	
	
	
	
	
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

	
	USART_Init(USART1,&USART_InitStructure);
	USART_Cmd(USART1,  ENABLE);




  /* NVIC configuration */
  NVIC_Configuration();

  if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
    /* Backup data register value is not correct or not yet programmed (when
       the first time the program is executed) */

    printf("\r\n\n RTC not yet configured....");

    /* RTC Configuration */
    RTC_Configuration();

    printf("\r\n RTC configured....");

    /* Adjust time by values entered by the user on the hyperterminal */
    Time_Adjust();

    BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
  }
  else
  {
    /* Check if the Power On Reset flag is set */
    if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
    {
      printf("\r\n\n Power On Reset occurred....");
    }
    /* Check if the Pin Reset flag is set */
    else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
    {
      printf("\r\n\n External Reset occurred....");
    }

    printf("\r\n No need to configure RTC....");
    /* Wait for RTC registers synchronization */
    RTC_WaitForSynchro();

    /* Enable the RTC Second */
    RTC_ITConfig(RTC_IT_SEC, ENABLE);
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
  }

#ifdef RTCClockOutput_Enable
  /* Enable PWR and BKP clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Allow access to BKP Domain */
  PWR_BackupAccessCmd(ENABLE);

  /* Disable the Tamper Pin */
  BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
                                 functionality must be disabled */

  /* Enable RTC Clock Output on Tamper Pin */
  BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock);
#endif

  /* Clear reset flags */
  RCC_ClearFlag();

  /* Display time in infinite loop */
  Time_Show();
}
コード例 #23
0
ファイル: main.c プロジェクト: jiesse/time-meter
/**
  * @brief  Main program.
  * @param  None
  * @retval : None
  */
int main(void)
{
  /* System Clocks Configuration */
  RCC_Configuration();

  /* NVIC configuration */
  NVIC_Configuration();

  /* Configure the GPIOs */
  GPIO_Configuration();

  /* RTC Configuration */
  RTC_Configuration();

  /* Wait until Key Push button is pressed */
  while (GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_8) != 0)
  {
  }

  /* Get the Frequency value */
  RCC_GetClocksFreq(&RCC_Clocks);

  /* Enable TIM5 APB1 clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);

  /* Connect internally the TM5_CH4 Input Capture to the LSI clock output */
  GPIO_PinRemapConfig(GPIO_Remap_TIM5CH4_LSI, ENABLE);

  /* TIM5 Time base configuration */
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);

  /* TIM5 Channel4 Input capture Mode configuration */
  TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0;
  TIM_ICInit(TIM5, &TIM_ICInitStructure);

  /* Reinitialize the index for the interrupt */
  OperationComplete = 0;

  /* Enable the TIM5 Input Capture counter */
  TIM_Cmd(TIM5, ENABLE);
  /* Reset all TIM5 flags */
  TIM5->SR = 0;
  /* Enable the TIM5 channel 4 */
  TIM_ITConfig(TIM5, TIM_IT_CC4, ENABLE);

  /* Wait the TIM5 measuring operation to be completed */
  while (OperationComplete != 2)
  {}

  /* Compute the actual frequency of the LSI. (TIM5_CLK = 2 * PCLK1)  */
  if (PeriodValue != 0)
  {
    LsiFreq = (uint32_t)((uint32_t)(RCC_Clocks.PCLK1_Frequency * 2) / (uint32_t)PeriodValue);
  }

  /* Adjust the RTC prescaler value */
  RTC_SetPrescaler(LsiFreq - 1);

  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();

  /* Set GPIOF pin 7 */
  GPIO_SetBits(GPIOF, GPIO_Pin_7);

  while (1)
  {
    /* Inifinite loop */
  }

}
コード例 #24
0
ファイル: bsp.c プロジェクト: ozwin/erts-project
void  BSP_Init (void)
{
	// Clock Config: HSE 72 MHz
#if __RTC_ENABLE == ON
	RTC_Configuration();
#else
	RCC_Configuration();
#endif


#if __USART1_ENABLE == ON
	// USART1 Config ==> FTDI
	USART1_Configuration();
#endif

#if __USART3_ENABLE == ON
	// USART3 Config ==> Trypano support card
	USART3_Configuration();
#endif


#if __SRAM_ENABLE == OFF && __LED_ENABLE == ON
	// LED Config
		LED_Configuration();
#endif

#if __SWITCH_ENABLE == ON
	// SWITCH Config
	SWITCH_Configuration();
#endif

	// I2C Config
#if __I2C_ENABLE == ON
		I2C_Configuration();
#endif

#if __POT_ENABLE == ON
	// Pot / ADC Config
	ADC_POT_Configuration();
#endif

#if __USB_ENABLE == ON
	//USB Config
	USB_Configuration();
#endif

#if __DAC1_ENABLE == ON
	//DAC Config and start
	DAC1_Configuration();
#endif


#if __SRAM_ENABLE == ON
	// RAM Config
	SRAM_Configuration();
#endif

#if __SDCARD_ENABLE == ON
	// SDCard Config
	SDCARD_Configuration();
#endif

#if __DAC2_ENABLE == ON
	DAC2_Configuration();
#endif

#if __ADCe1_ENABLE == ON
	ADCe1_Configuration();
#endif

}
コード例 #25
0
ファイル: main.c プロジェクト: 003900107/wpa900-base
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
  this i
  s done through SystemInit() function which is called from startup
  file (startup_stm32f10x_xx.s) before to branch to application main.
  To reconfigure the default setting of SystemInit() function, refer to
  system_stm32f10x.c file
  */     
  //GPIO_InitTypeDef GPIO_InitStructure;
  //uint32_t irq; //test IRQ
  
  
  /* System clocks configuration ---------------------------------------------*/
  SystemInit();
  RCC_Configuration();
  
  /* GPIO configuration ------------------------------------------------------*/
  GPIO_Configuration();
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
  GPIO_WriteBit(PWR_LED,  Bit_RESET);
  GPIO_WriteBit(ALARM_LED,  Bit_SET);
  GPIO_WriteBit(RUNSTAT_LED,  Bit_SET);

  GPIO_WriteBit(ETH_RESET,  Bit_RESET);//拉低DM9000 nRST, 延时复位启动
  
  DataBase_Init(DevIPAddressTab);
  
#ifndef TEST  
  /* com1 configuration ------------------------------------------------------*/
  COM1_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_RESET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif
  printf(" <<<<<<< COM1 config complete <<<<<<<\r\n\r\n");  
  
  
  /* com2 configuration ------------------------------------------------------*/
  //COM2_Configuration();
#endif 
  
  /* i2c configuration ------------------------------------------------------*/
  printf(" >>>>>>> I2C config begin >>>>>>>\r\n");
  I2C_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_RESET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET); 
#endif 
  printf(" <<<<<<< I2C config complete <<<<<<<\r\n\r\n");
  
#ifndef TEST  
  /* RTC configuration--------------------------------------------------------*/
  printf(" >>>>>>> RTC config begin >>>>>>>\r\n");
  RTC_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_RESET);
  GPIO_WriteBit(CANRX_LED,  Bit_RESET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif  
  printf(" <<<<<<< RTC config complete <<<<<<<\r\n\r\n");
#endif
  
#ifdef CAN_APP  
  /* can configuration ------------------------------------------------------*/
  printf(" >>>>>>> CAN config begin >>>>>>>\r\n");
  CAN_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_RESET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif  
  printf(" <<<<<<< CAN config complete <<<<<<<\r\n\r\n");  
#endif
  
#ifndef TEST  
  /*temperature configuration------------------------------------------------------*/
  printf(" >>>>>>> TEMPMEA config begin >>>>>>>\r\n");
  TEMPMEA_Confitguration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_RESET);
  GPIO_WriteBit(COMTX_LED,  Bit_RESET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif 
  printf(" <<<<<<< TEMPMEA config complete <<<<<<<\r\n\r\n");
#endif
  
  /* SysTick configuration ------------------------------------------------------*/
  printf(" >>>>>>> SysTick config begin >>>>>>>\r\n");
  SysTick_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_RESET);
  GPIO_WriteBit(CANRX_LED,  Bit_RESET);
  GPIO_WriteBit(COMTX_LED,  Bit_RESET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif  
  printf(" <<<<<<< SysTick config complete <<<<<<<\r\n\r\n");

  /* NVIC configuration ------------------------------------------------------*/
  printf(" >>>>>>> NVIC config begin >>>>>>>\r\n");
  NVIC_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_RESET);
#endif  
  printf(" <<<<<<< NVIC config complete <<<<<<<\r\n\r\n");
  
  /* Update the SysTick IRQ priority should be higher than the Ethernet IRQ */
  /* The Localtime should be updated during the Ethernet packets processing */
  NVIC_SetPriority (SysTick_IRQn, 1); 
  
  /* test IRQ*/
//  irq = NVIC_GetPriority(SysTick_IRQn);
//  irq = NVIC_GetPriority(ETH_IRQn);
//  irq = NVIC_GetPriority(I2C1_ER_IRQn);
//  irq = NVIC_GetPriority(I2C1_EV_IRQn);
  
  
  /* ethernet configuration ------------------------------------------------------*/
  //可添加延时, 用以确保DM9000启动时电压满足芯片要求
  //"nRST must not go high until after the VDDIO and VDD_CORE supplies are stable"  手册P51
  GPIO_WriteBit(ETH_RESET,  Bit_SET);   //拉高DM9000 nRST, 复位启动
  
  printf(" >>>>>>> ETH config begin >>>>>>>\r\n");
  Ethernet_Configuration();
#ifdef TEST_PARTS  
  GPIO_WriteBit(CANTX_LED,  Bit_RESET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_RESET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET);
#endif  
  printf(" <<<<<<< ETH config complete <<<<<<<\r\n\r\n");  

    
#ifdef WATCHDOG
  /* WATCHDOG configuration ------------------------------------------------------*/
  IWDG_Configuration();
#endif
  
  //判断是否有以太网链接
  if(EthInitState)
  {
    CommunicationInit();
  }
  
  printf(" ******* 输入'$'将触发串口控制台!*******\r\n\r\n");
  GPIO_WriteBit(CANTX_LED,  Bit_SET);
  GPIO_WriteBit(CANRX_LED,  Bit_SET);
  GPIO_WriteBit(COMTX_LED,  Bit_SET);
  GPIO_WriteBit(COMRX_LED,  Bit_SET); 
  
  
  //启动完成, 进入常规流程
#ifdef _TEST  
  uint8_t test = 0;
#endif
  
  while (1)
  {
    Di_PostWork();
    LwIP_Periodic_Handle(LocalTime);
    Task_Periodic_Handle(LocalTime);
    

    //判断以太网状态, 决定是否要复位以太网
    EthStateCheck();
    
    reset_flag = Get_eth_reset_flag();
    if(reset_flag == Ethernet_SWRST_FLAG)
      Ethernet_SWRST();
    else if(reset_flag == Ethernet_HWRST_FLAG)
      Ethernet_HWRST();

#ifdef _TEST
    //tyh:20130407 eth reset test
    if((DiStatus_DI[1].Value != test)&&(DiStatus_DI[1].Value == 1))
    {
      //eth_reg = ETH_ReadPHYRegister(0x1F, 17);
      Ethernet_HWRST();
    }
    test = DiStatus_DI[1].Value;
#endif
    
//    else
//    {
//      if( EthLinkCheck() )
//      {
//        //tyh:20130403 send udp test_message
//        if((DiStatus_DI[1].Value != test)&&(DiStatus_DI[1].Value == 1))
//        {
//          Udp_timing_test();
//        }
//        
//        test = DiStatus_DI[1].Value;
//      }
//    }
    
#ifdef WATCHDOG 
    WDGFeeding();
#endif
    
  }
}
コード例 #26
0
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);
    }

}
コード例 #27
0
ファイル: main.c プロジェクト: 201409366/AerobatPCB
	/* 主函数进口 */
int main(void)
{
	/* RTC Configuration */
	RTC_Configuration();


	/* LED 端口初始化 */
    LED_GPIO_Config();
   
    SPI_RF24L01_Init();

	RF24L01_Init();
   
    /* 串口1初始化 */
	USART1_Config();

		
	/* 配置SysTick 为10us中断一次 */
    SysTick_Init();

	Delay_us(5000);    	// 50000 * 10us = 500ms

	printf("\r\n 这是一个 RF24L0124L01 无线传输实验 \r\n");
   	printf("\r\n 这是无线传输 主机端 的反馈信息\r\n");
	printf("\r\n   正在检测RF24L01与MCU是否正常连接。。。\r\n");

	 /*检测RF24L01模块与MCU的连接*/
   	status = RF24L01_Check(); 

	/*判断连接状态*/  
   if(status == SUCCESS)	   
   		 printf("\r\n      RF24L01与MCU连接成功!\r\n");  

   else	  
   	     printf("\r\n  RF24L01与MCU连接失败,请重新检查接线。\r\n");


//	while(1)
//	{
//		RF24L01_TX_Mode();

//		/*开始发送数据*/	
//		status = RF24L01_Tx_Dat(txbuf);	  

//		/*判断发送状态*/
//		switch(status)
//		{
//			case MAX_RT:
//			printf("\r\n 主机端 没接收到应答信号,发送次数超过限定值,发送失败。 \r\n");
//			break;

//			case ERROR:
//			printf("\r\n 未知原因导致发送失败。 \r\n");
//			break;

//			case TX_DS:
//			printf("\r\n 主机端 接收到 从机端 的应答信号,发送成功! \r\n");	 		
//			break;  								
//		}			   	       

//		LED1( ON );			  // 亮
//		Delay_us(50000);    	// 50000 * 10us = 500ms
//		LED1( OFF );		  // 灭

//		LED2( ON );			  // 亮
//		Delay_us(50000);    	// 50000 * 10us = 500ms
//		LED2( OFF );		  // 灭
//		Delay_us(50000);    	// 50000 * 10us = 500ms
//	} 

	LED1( OFF );			  // 亮

	while(1)
	{
		RF24L01_RX_Mode();

		/*开始发送数据*/	
		LED1(OFF);		  // 灭
		status = RF24l01_Rx_Dat(rxbuf);	  

		/*判断发送状态*/
		switch(status)
		{
			case ERROR:
				printf("\r\n 未知原因导致接收失败。 \r\n");
				break;

			case RX_DR:
				//printf("\r\n 主机端 接收到 从机端 的应答信号,发送成功! \r\n");	
				rxbuf[32] = 0;
				printf("\r\n Receive data is:%s \r\n",rxbuf);//打印接收到的数据			 
				LED1(ON);		  // 灭
				break; 
		}			   	       
	} 


}
コード例 #28
0
/*
 * 函数名:RTC_CheckAndConfig
 * 描述  :检查并配置RTC
 * 输入  :用于读取RTC时间的结构体指针
 * 输出  :无
 * 调用  :外部调用
 */
void RTC_CheckAndConfig(struct rtc_time *tm)
{
   	  /*在启动时检查备份寄存器BKP_DR1,如果内容不是0xA5A5,
	  则需重新配置时间并询问用户调整时间*/
	if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
	{
		printf("\r\n\r\n RTC not yet configured....");

		/* RTC Configuration */
		RTC_Configuration();
		
		printf("\r\n\r\n RTC configured....");

		/* Adjust time by users typed on the hyperterminal */
		Time_Adjust(tm);

		BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
	}
	else
	{
	  /*启动无需设置新时钟*/
		/*检查是否掉电重启*/
		if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
		{
		    printf("\r\n\r\n Power On Reset occurred....");
		}
		/*检查是否Reset复位*/
		else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
		{
			printf("\r\n\r\n External Reset occurred....");
		}
	
		printf("\r\n No need to configure RTC....");
		
		/*等待寄存器同步*/
		RTC_WaitForSynchro();
		
		/*允许RTC秒中断*/
		RTC_ITConfig(RTC_IT_SEC, ENABLE);
		
		/*等待上次RTC寄存器写操作完成*/
		RTC_WaitForLastTask();
	}
	   /*定义了时钟输出宏,则配置校正时钟输出到PC13*/
	#ifdef RTCClockOutput_Enable
	  /* Enable PWR and BKP clocks */
	  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
	
	  /* Allow access to BKP Domain */
	  PWR_BackupAccessCmd(ENABLE);
	
	  /* Disable the Tamper Pin */
	  BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
	                                 functionality must be disabled */
	
	  /* Enable RTC Clock Output on Tamper Pin */
	  BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock);
	#endif
	
	  /* Clear reset flags */
	  RCC_ClearFlag();

}
コード例 #29
0
ファイル: main.c プロジェクト: dunchen/ASR-project
int main(void)
{
	
	int flag;
  int i;
	
	//only for sd testing
	extern u8 sd_recv_buf[512];
	extern u8 sd_send_buf[512];
	u8 ret = 1;
	// only for sd testing
	
	RCC_Configuration();
	RTC_Configuration();
	GPIO_Configuration();
	SPI_Configuration();
	NVIC_Configuration();
	USART_Configuration();
	EXTI_cfg();
	
	//only for sd testing
	ret = MSD_Init();
	ret = MSD_GetMediumCharacteristics();
	MSD_EarseBlock(0,Mass_Block_Count);
	//only for sd testing
	
	//system start working
	GPIO_SetBits(GPIOC,GPIO_Pin_14);
	
	//wait for the moment that the device has been fxed into the rocket
//	for (i=0;i<6*5;i++) {delay();} //delay 10 minutes

  //self-testing
  
	//first, test wireless data transmition
	
	Timedisplay=0;
	while (Timedisplay<10)
	{
		USART_SendData(USART3, 'A'); 
	  while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
		
	  if ((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET)
			   && (USART_ReceiveData(USART3)==66)) //except "B"
		  {
				//static char Responce[]="Wireless data transmition test completed";
				for (i=0;i<strlen(Responce);i++)
				{
				  USART_SendData(USART3, Responce[i]); 
	        while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
				}
				break;
			}
		//USART_ClearFlag(USART3, USART_FLAG_RXNE);
	}
	
	if (Timedisplay==10)
	{
		GPIO_ResetBits(GPIOC,GPIO_Pin_14);
		//Write into SD:ERROR in data transmition
		
		//only for testing
		for (i=0;i<strlen(errorDatatransmition);i++)
			{
				sd_send_buf[i]=errorDatatransmition[i];
			}
		ret = MSD_WriteBlock(sd_send_buf,0,512);
		//only for testing
		
		return(0);
	}
	
	//waiting for the continue order
	for (i=0;i<4000;i++);
	while (1)
	{
		if ((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET)
			   && (USART_ReceiveData(USART3)==78)) //except "N"
		  {
				break;
			}
		//USART_ClearFlag(USART3, USART_FLAG_RXNE);
	}
	
	//second,test GPS
  Timedisplay=0;
	flag=1;
	while ((Timedisplay<60*5) &&
		     (!((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET)
			      && (USART_ReceiveData(USART3)==71))))  //except "G"
	{
	  if ((USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == SET))
		  {
				flag=1;
				USART_SendData(USART3, USART_ReceiveData(USART1)); 
	      while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
			}
		//USART_ClearFlag(USART1, USART_FLAG_RXNE);
	}
	
	if (flag==0)
	{
		GPIO_ResetBits(GPIOC,GPIO_Pin_14);
		for (i=0;i<strlen(errorGPS);i++)
		{
			USART_SendData(USART3, errorGPS[i]); 
	    while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
		}
		//Write into SD:ERROR in GPS
		for (i=0;i<strlen(errorGPS);i++)
			{
				sd_send_buf[i]=errorGPS[i];
			}
		ret = MSD_WriteBlock(sd_send_buf,1,512);
		return(0);
	}
	//static char Responce2[]="GPS test completed";
	for (i=0;i<strlen(Responce2);i++)
		{
			USART_SendData(USART3, Responce2[i]); 
	    while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
		}
		
	
	//waiting for the continue order
	for (i=0;i<4000;i++);
	while (1)
	{
		if ((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET)
			   && (USART_ReceiveData(USART3)==78)) //except "N"
		  {
				break;
			}
		//USART_ClearFlag(USART3, USART_FLAG_RXNE);
	}
	
	//third, test clock
	USART_SendData(USART3, 'C'); 
	while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
	Timedisplay=0;
	flag=0;
	while ((Timedisplay<20) &&
		     (!((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET)
			      && (USART_ReceiveData(USART3)==69))));  //except "E"
	
	if ((abs(Timedisplay-10)>2) &&
		    (USART_ReceiveData(USART3)==69))
	{
		GPIO_ResetBits(GPIOC,GPIO_Pin_14);
		for (i=0;i<strlen(errorclock);i++)
		{
			USART_SendData(USART3, errorclock[i]); 
	    while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
		}
		//Write into SD:ERROR in timing
		//only for testing
		for (i=0;i<strlen(errorclock);i++)
			{
				sd_send_buf[i]=errorclock[i];
			}
		ret = MSD_WriteBlock(sd_send_buf,2,512);
		//only for testing
			
		return(0);
	}
	
	//static char Responce3[]="clock test completed";
	for (i=0;i<strlen(Responce3);i++)
		{
			USART_SendData(USART3, Responce3[i]); 
	    while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
		}
	
	//static char Responce4[]="ALL test completed,wait for launching signal";
	for (i=0;i<strlen(Responce4);i++)
		{
			USART_SendData(USART3, Responce4[i]); 
	    while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
		}
	
	while (!((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET)
			      && (USART_ReceiveData(USART3)==76))); //except for "L"
	
	//delay();
  
	//static char Responce5[]="Go! Good Luck!";
	for (i=0;i<strlen(Responce5);i++)
		{
			USART_SendData(USART3, Responce5[i]); 
	    while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
		}

	
	/* Enable the USART Receive interrupt: this interrupt is generated when the
     USART1 receive data register is not empty */
  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
  //USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
	Timedisplay=0;
	while(1)
	{
		if (Timedisplay>=OPEN_Parachute) 
		{
			GPIO_SetBits(GPIOC,GPIO_Pin_6);
			//static char Responce6[]="The parachute is open@";
	    for (i=0;i<strlen(Responce6);i++)
	    	{
	     		USART_SendData(USART3, Responce6[i]); 
	        while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
		    }
		}
	}
	return(0);
}
コード例 #30
0
ファイル: rtc.c プロジェクト: MaxStudio/GPS_TRACER_CODE
void RtcInit(void)
{

	RTC_Configuration();
	
	if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
		/* Backup data register value is not correct or not yet programmed (when
			 the first time the program is executed) */
		printf("\r\n> RTC not yet configured....");
		SetRtcTime();
  }
  else
  {
    /* Check if the Power On Reset flag is set */
    if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
    {
      printf("\r\n> Power On Reset occurred....");
    }
    /* Check if the Pin Reset flag is set */
    else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
    {
      printf("\r\n> External Reset occurred....");
    }

    printf("\r\n> No need to configure RTC....");
    /* Wait for RTC registers synchronization */
    RTC_WaitForSynchro();

    /* Enable the RTC Second */
    RTC_ITConfig(RTC_IT_SEC, ENABLE);

    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
  }

#ifdef RTCClockOutput_Enable
  /* Enable PWR and BKP clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Allow access to BKP Domain */
  PWR_BackupAccessCmd(ENABLE);

  /* Disable the Tamper Pin */
  BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
                                 functionality must be disabled */

  /* Enable RTC Clock Output on Tamper Pin */
  BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock);
#endif

  /* Clear reset flags */
  RCC_ClearFlag();
	
	// Rx8025 对时
	time_set.tm_year	= 2000+ExRtcTime.year;
	time_set.tm_mon		= ExRtcTime.mon;
	time_set.tm_mday	= ExRtcTime.day;
	time_set.tm_hour	= ExRtcTime.hour;
	time_set.tm_min 	= ExRtcTime.min;
	time_set.tm_sec 	= ExRtcTime.sec;

	Time_SetCalendarTime(time_set);	
	
	
	
	
	
}