Example #1
0
void RTC_Start(){
	if(RTC_SR == RTC_SR_TCE_MASK){ // If RTC clock is already running
		RTC = RTC_Init(NULL, true); // Initialise the RTC softly
	}else{
		RTC = RTC_Init(NULL, false); // Initialise the RTC hard (reset time/date etc.)
		for(uint8 i = 0; i < 4; i++){
			LED_Red_On();
			DelayMs(500);
			LED_Red_Off();
			DelayMs(500);
		}
	}
}
Example #2
0
/**
* @brief  Configures the RTC peripheral.
* @param  None
* @retval None
*/
int8_t RTC_Configuration(void)
{

  RTC_Error = 0;
  /* Enable the PWR clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

  /* Allow access to RTC */
  PWR_BackupAccessCmd(ENABLE);

/* LSI used as RTC source clock */
/* The RTC Clock may varies due to LSI frequency dispersion. */   
  /* Enable the LSI OSC */ 
 // RCC_LSICmd(ENABLE);
	RCC_LSEConfig(RCC_LSE_ON);

  /* Wait till LSI is ready */  
  //while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
	while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {
  }

  /* Select the RTC Clock Source */
  //RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
	RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
   
  /* Enable the RTC Clock */
  RCC_RTCCLKCmd(ENABLE);
  
    /* Wait for RTC APB registers synchronisation */
  RTC_WaitForSynchro();
	
	//RTC_WaitForLastTask();
  
  /* Calendar Configuration with LSI supposed at 32KHz */
  RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
  RTC_InitStructure.RTC_SynchPrediv	=  0xFF; /* (32KHz / 128) - 1 = 0xFF*/
  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
  RTC_Init(&RTC_InitStructure);  

  /* Get the LSI frequency:  TIM5 is used to measure the LSI frequency */
  //LsiFreq = GetLSIFrequency();
   
  /* Adjust LSI Configuration */
  RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
  //RTC_InitStructure.RTC_SynchPrediv	=  (LsiFreq/128) - 1;
	RTC_InitStructure.RTC_SynchPrediv	= (32767/128) - 1;
  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
  RTC_Init(&RTC_InitStructure);
  return RTC_Error;
}
Example #3
0
void rtcSetup(){
	RTC_Init_TypeDef rtcInit = RTC_INIT_DEFAULT;

	/* Enabling clock to LE configuration register */
	CMU_ClockEnable(cmuClock_CORELE, true);

	/* Selecting crystal oscillator to drive LF clock */
	CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);

	/* 32 clock division to save energy */
	CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_32768);

	/* Providing clock to RTC */
	CMU_ClockEnable(cmuClock_RTC, true);

	/* Initialize RTC */
	rtcInit.enable   = false;  /* Do not start RTC after initialization is complete. */
	rtcInit.debugRun = false;  /* Halt RTC when debugging. */
	rtcInit.comp0Top = true;   /* Wrap around on COMP0 match. */
	RTC_Init(&rtcInit);

	/* Interrupt every minute */
	RTC_CompareSet(0, ((RTC_FREQ / CLOCK_DIVISION) * 10 ) - 1 );

	/* Enable interrupt */
	NVIC_EnableIRQ(RTC_IRQn);
	RTC_IntEnable(RTC_IEN_COMP0);

	/* Start Counter */
	RTC_Enable(true);

}
/***************************************************************************//**
 * @brief Enables LFACLK and selects osc as clock source for RTC
 ******************************************************************************/
void RTC_Setup(CMU_Select_TypeDef osc)
{
  RTC_Init_TypeDef init;

  /* Ensure LE modules are accessible */
  CMU_ClockEnable(cmuClock_CORELE, true);

  /* Enable osc as LFACLK in CMU (will also enable oscillator if not enabled) */
  CMU_ClockSelectSet(cmuClock_LFA, osc);

  /* No division prescaler to increase accuracy. */
  CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_1);

  /* Enable clock to RTC module */
  CMU_ClockEnable(cmuClock_RTC, true);

  init.enable   = false;
  init.debugRun = false;
  init.comp0Top = true; /* Count only to top before wrapping */
  RTC_Init(&init);
  
  RTC_CompareSet(0, ((LFRCOFREQ * WAKEUP_US) / 1000000));
    
  /* Disable interrupt generation from RTC0, is enabled before each sample-run. */
  RTC_IntDisable(_RTC_IF_MASK);
  
  /* Enable interrupts in NVIC */
  NVIC_ClearPendingIRQ(RTC_IRQn);
  NVIC_EnableIRQ(RTC_IRQn);  
}
Example #5
0
void lp_ticker_init()
{
    core_util_critical_section_enter();
    if (!rtc_inited) {
        CMU_ClockEnable(cmuClock_RTC, true);

        /* Initialize RTC */
        RTC_Init_TypeDef init = RTC_INIT_DEFAULT;
        init.enable = 1;
        /* Don't use compare register 0 as top value */
        init.comp0Top = 0;

        /* Initialize */
        RTC_Init(&init);
        RTC_CounterSet(20);

        /* Enable Interrupt from RTC */
        RTC_IntDisable(RTC_IF_COMP0);
        RTC_IntClear(RTC_IF_COMP0);
        NVIC_SetVector(RTC_IRQn, (uint32_t)RTC_IRQHandler);
        NVIC_EnableIRQ(RTC_IRQn);

        rtc_inited = true;
    } else {
        /* Cancel current interrupt by virtue of calling init again */
        RTC_IntDisable(RTC_IF_COMP0);
        RTC_IntClear(RTC_IF_COMP0);
    }
    core_util_critical_section_exit();
}
Example #6
0
void Init() {
    PWR_Init();
    CLOCK_Init();
    UART_Initialize();
    printf("Start\n");
    Initialize_ButtonMatrix();
    SPIFlash_Init(); //This must come before LCD_Init() for 7e

    LCD_Init();
    CHAN_Init();

    SPITouch_Init();
    SOUND_Init();
    BACKLIGHT_Init();
    BACKLIGHT_Brightness(1);
    AUTODIMMER_Init();
    SPI_FlashBlockWriteEnable(1); //Enable writing to all banks of SPIFlash

    PPMin_TIM_Init();
#ifdef MODULAR
    //Force protocol to none to initialize RAM
    Model.protocol = PROTOCOL_NONE;
    PROTOCOL_Init(1);
#endif
#if HAS_RTC
    RTC_Init();        // Watchdog must be running in case something goes wrong (e.g no crystal)
#endif
}
Example #7
0
/******************************************************************************
 * @brief 
 *   Configures and starts RTC from ULFRCO
 *****************************************************************************/
void startRTCTick(void)
{
  /* Set-up RTC init struct */
  RTC_Init_TypeDef rtcInit;
  rtcInit.comp0Top = true;
  rtcInit.debugRun = false;
  rtcInit.enable = true;
  
  /* Enable clock to LF peripherals */
  CMU_ClockEnable(cmuClock_CORELE, true);

  /* Set ULFRCO as clock source for RTC */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_ULFRCO);

  /* Turn on clock for RTC */
  CMU_ClockEnable(cmuClock_RTC, true);

  /* Enable RTC interrupt lines */
  NVIC_EnableIRQ(RTC_IRQn);
  RTC_IntEnable(RTC_IF_COMP0);

  /* Set compare register */
  RTC_CompareSet(0, MS_TO_SLEEP);

  /* Initialize and start RTC */
  RTC_Init(&rtcInit);
}
Example #8
0
  int main(void)
 {
	 u8 t=0;	
	 u16 Time=0,dis_pre=0;
	 float V_ave;	//平均速度
	 char code_ave[5],code_v[5],code_vr[5], mileage[5];//信息储存数组
	 
	delay_init(72);	    	 			//延时函数初始化	  
	Stm32_Clock_Init(9);		  //系统时钟设置
	uart_init(72,9600);	 	 		  //串口初始化为9600
	usmart_dev.init(72);			//初始化USMART	
	EXTIX_Init();							//外部中断初始化
	TIM3_Int_Init(5000,7199); //10Khz的计数频率,计数到5000为500ms 
	LCD_Init();				 				//  PE.ALL,PD1~5  
	LCD_Display_Dir(1);				//设置显示方向为横屏显示
	LED_Init();		  					//初始化与LED连接的硬件接口
	KEY_Init();								//初始化按键

		while(RTC_Init())
		{	//等待RTC初始化
			delay_ms(200);
			printf("rtc waiting```\r\n");
		} 
		printf("finish\n");
		display_jing();
		//初始化完成
   while(1)
	{	
		POINT_COLOR=RED;
		if(t!=calendar.sec)		//时间更新后显示新时间
		{
				t=calendar.sec;	
				LCD_ShowNum(200,135,calendar.min,2,32);		
				LCD_ShowString(230,135,200,32,32,":");			
				LCD_ShowNum(248,135,calendar.sec,2,32);
			
				Time = 60*calendar.min+calendar.sec;//比赛用时
				if(dis_pre != quanshu_tenfold)			//有位移变化
				{
					V_ave=(0.154*quanshu_tenfold)/Time;
					dis_pre = quanshu_tenfold;
					sprintf(code_ave,"%.2f",V_ave);	
					LCD_ShowString(100,200,200,32,32,code_ave);//修改一下位置
					
				}
		}
			
		sprintf(code_v,"%.2f",V);					//float 转 字符串  
		LCD_ShowString(365,275,200,32,32,code_v);		//速度
		
		sprintf(code_vr,"%d",V_RPM);					//float 转 字符串  
		LCD_ShowString(365,275,200,32,32,code_vr);		//转速
 
		sprintf(mileage,"%.2f",0.154*quanshu_tenfold);
		LCD_ShowString(250,225,200,24,32,mileage);	//里程
		
	  display_dong(V_RPM,V,50);
		delay_ms(300);
	}
 }
Example #9
0
/***************************************************************************//**
 * @brief Enables LFACLK and selects LFRCO as clock source for RTC
 ******************************************************************************/
static void RTC_Setup(void)
{
  RTC_Init_TypeDef init;

  rtcInitialized = 1;

  /* Ensure LE modules are accessible */
  CMU_ClockEnable(cmuClock_CORELE, true);

  /* Enable LFRCO as LFACLK in CMU (will also enable oscillator if not enabled) */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO);

  /* Enable clock to RTC module */
  CMU_ClockEnable(cmuClock_RTC, true);

  init.enable   = false;
  init.debugRun = false;
  init.comp0Top = false; /* Count to max before wrapping */
  RTC_Init(&init);

  /* Disable interrupt generation from RTC0 */
  RTC_IntDisable(_RTC_IF_MASK);

  /* Enable interrupts */
  NVIC_ClearPendingIRQ(RTC_IRQn);
  NVIC_EnableIRQ(RTC_IRQn);
}
Example #10
0
/**
 * Initialize RTC Based on Crystal Oscillator
 */
void rtc_crystal_init(void)
{
  RTC_Init_TypeDef init;

  /* Ensure LE modules are accessible */
  CMU_ClockEnable(cmuClock_CORELE, true);

  /* Enable LFACLK in CMU (will also enable oscillator if not enabled) */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);

  /* Use the prescaler to reduce power consumption. */
  CMU_ClockDivSet(cmuClock_RTC, RTC_PRESCALE);

  /* Enable clock to RTC module */
  CMU_ClockEnable(cmuClock_RTC, true);

  init.enable   = false; /* Start disabled to reset counter */
  init.debugRun = false;
  init.comp0Top = false; /* Count to max before wrapping */
  RTC_Init(&init);

  /* Disable interrupt generation from RTC0 */
  RTC_IntDisable(_RTC_IF_MASK);

  /* Enable interrupts */
  NVIC_ClearPendingIRQ(RTC_IRQn);
  NVIC_EnableIRQ(RTC_IRQn);

  /* Start RTC counter */
  RTC_Enable(true);
}
Example #11
0
static void System_Time_Init(void)
{
	/* RTC Block section ------------------------------------------------------ */
	// Init RTC module
	RTC_Init(LPC_RTC);

    /* Disable RTC interrupt */
    NVIC_DisableIRQ(RTC_IRQn);
    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(RTC_IRQn, ((0x01<<3)|0x01));

	/* Enable rtc (starts increase the tick counter and second counter register) */
	RTC_ResetClockTickCounter(LPC_RTC);
	RTC_Cmd(LPC_RTC, ENABLE);
	RTC_CalibCounterCmd(LPC_RTC, DISABLE);

	/* Set current time for RTC */
	// Current time is 06:45:00PM, 2011-03-25
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MINUTE, 45);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_HOUR, 15);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MONTH, 3);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_YEAR, 2014);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, 30);

	return;
}
Example #12
0
int main(void)
{
    uint8_t last_sec;
    RTC_CalanderTypeDef RTC_Calander1;
    //初始化系统时钟 使用外部50M晶振 PLL倍频到100M
    SystemClockSetup(ClockSource_EX50M,CoreClock_100M);
    DelayInit();
    LED_Init(LED_PinLookup_CHK60EVB, kNumOfLED);
    UART_DebugPortInit(UART4_RX_C14_TX_C15, 115200);
    UART_printf("RTC TEST\r\n");
    RTC_Init();
	
	  //可以设置时间
    RTC_Calander1.Hour = 10;
    RTC_Calander1.Minute = 57;
    RTC_Calander1.Second = 58;
    RTC_Calander1.Month = 10;
    RTC_Calander1.Date = 10;
    RTC_Calander1.Year = 2013;
    //RTC_SetCalander(&RTC_Calander1);
    NVIC_EnableIRQ(RTC_IRQn);
    while(1) 
		{
        RTC_GetCalander(&RTC_Calander1); //读取时间
        if(last_sec != RTC_Calander1.Second)
				{
            UART_printf("%d-%d-%d %d:%d:%d\r\n", RTC_Calander1.Year, RTC_Calander1.Month, RTC_Calander1.Date, RTC_Calander1.Hour, RTC_Calander1.Minute, RTC_Calander1.Second);
            last_sec = RTC_Calander1.Second;
				}	
		}
 }
Example #13
0
void TM_RTC_SetDateTime(TM_RTC_Time_t* data, TM_RTC_Format_t format) {	
	/* Fill time */
	RTC_TimeStruct.RTC_Hours = data->hours;
	RTC_TimeStruct.RTC_Minutes = data->minutes;
	RTC_TimeStruct.RTC_Seconds = data->seconds;
	/* Fill date */
	RTC_DateStruct.RTC_Date = data->date;
	RTC_DateStruct.RTC_Month = data->month;
	RTC_DateStruct.RTC_Year = data->year;
	RTC_DateStruct.RTC_WeekDay = data->day;
	
	/* Set the RTC time base to 1s and hours format to 24h */
	RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24;
	RTC_InitStruct.RTC_AsynchPrediv = uwAsynchPrediv;
	RTC_InitStruct.RTC_SynchPrediv = uwSynchPrediv;
	RTC_Init(&RTC_InitStruct);

	if (format == TM_RTC_Format_BCD) {
		RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);
	} else {
		RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct);
	}
	
	if (format == TM_RTC_Format_BCD) {
		RTC_SetDate(RTC_Format_BCD, &RTC_DateStruct);
	} else {
		RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct);
	}	
	
	if (TM_RTC_Status != RTC_STATUS_ZERO) {
		/* Write backup registers */
		RTC_WriteBackupRegister(RTC_STATUS_REG, RTC_STATUS_TIME_OK);
	}
}
Example #14
0
/*---------------------------------------------------------------------------*/
void
rtimer_arch_init(void)
{
  RTC_Init_TypeDef init = RTC_INIT_DEFAULT;

  /* Ensure LE modules are accessible */
  CMU_ClockEnable(cmuClock_CORELE, true);

  /* Enable LFACLK in CMU (will also enable oscillator if not enabled) */
  CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);

  /* Don't use prescaler to have highest precision */
  CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_1);

  /* Enable clock to RTC module */
  CMU_ClockEnable(cmuClock_RTC, true);

  init.enable   = false; /* Start disabled to reset counter */
  init.debugRun = false;
  init.comp0Top = false; /* Don't Reset Count on comp0 */
  RTC_Init(&init);

  /* Disable interrupt generation from RTC0 */
  RTC_IntDisable(_RTC_IF_MASK);

  /* Enable interrupts */
  NVIC_ClearPendingIRQ(RTC_IRQn);
  NVIC_EnableIRQ(RTC_IRQn);

  /* Start RTC counter */
  RTC_Enable(true);
}
Example #15
0
int main(void)
{
		TIME  time;
		
		 /*时钟初始化*/
		CLK_Config();
			
		/*初始化电源控制*/
		GPIO_DeInit(GPIOD); 
		GPIO_Init(GPIOD,GPIO_PIN_3,GPIO_MODE_OUT_PP_LOW_FAST);
		GPIO_DeInit(GPIOC); 
		GPIO_Init(GPIOC,GPIO_PIN_1,GPIO_MODE_OUT_PP_LOW_FAST);	
	
		/*上电,3.3V/12V*/
		VDD3V3_ON();
		VDD12_ON();
	
		RTC_Init();


		while (1)
		{
			RTC_ReadDate(&time);

		  
		}
			

	


	return 0;
}
Example #16
0
/* start the main program */
void main() 
{
  
   unsigned char sec,min,hour,day,month,year;

  /* Initialize the lcd before displaying any thing on the lcd */
    LCD_Init(8,2,16);

  /* Initialize the RTC(ds1307) before reading or writing time/date */
    RTC_Init();


   /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetTime(0x10,0x40,0x00);  //  10:40:20 am
    RTC_SetDate(0x01,0x01,0x15);  //  1st Jan 2015



   /* Display the Time and Date continuously */ 
   while(1)
    {
		LCD_GoToLine(1);
	   /* Read the Time from RTC(ds1307) */ 
        RTC_GetTime(&hour,&min,&sec);    
		
	   /* Read the Date from RTC(ds1307) */ 
       RTC_GetDate(&day,&month,&year);     		 
        
	   LCD_Printf("\n\rtime:%2x:%2x:%2x  \nDate:%2x/%2x/%2x",(uint16_t)hour,(uint16_t)min,(uint16_t)sec,(uint16_t)day,(uint16_t)month,(uint16_t)year);
	}		

  }
Example #17
0
int main(void)
{
	uint8_t i, j, cardType, error;
	
	DDRB = 0xFF;
	PORTB = 0x00;
	SD_Init_hw();	// cs of sd disable!
	SPI_Init();		//only one SPI on BIGAVR... need to change for ATmega328
	cardType = 0;

//	error = SD_Init(2);
	_delay_us(10);
	RTC_Init();
	sei();
	
	while(1)
	{
		if(Status & RTC_UPDATE)
		{
			PORTB |= _BV(PB2);		//sd deassert ako test rtc interruptu
			sei();
			for(j=0; j<8; j++)
			{
				SPI_Send8(0xAA,0);
				_delay_us(10);
			}
			Status &= ~RTC_UPDATE;
		}
		SPI_Send8(0xF0,0);
	}
}
Example #18
0
/***************************************************************************//**
 * @brief
 *	Enables LFACLK and selects LFXO as clock source for RTC
 *
 * @param osc
 *	Oscillator
 ******************************************************************************/
void RTC_Setup(CMU_Select_TypeDef osc)
{
  RTC_Init_TypeDef init;

  rtcInitialized = 1;

  /* Ensure LE modules are accessible */
  CMU_ClockEnable(cmuClock_CORELE, true);

  /* Enable osc as LFACLK in CMU (will also enable oscillator if not enabled) */
  CMU_ClockSelectSet(cmuClock_LFA, osc);

  /* Use a 32 division prescaler to reduce power consumption. */
  CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_32);

  rtcFreq = CMU_ClockFreqGet(cmuClock_RTC);

  /* Enable clock to RTC module */
  CMU_ClockEnable(cmuClock_RTC, true);

  init.enable   = false;
  init.debugRun = false;
  init.comp0Top = false; /* Count to max before wrapping */
  RTC_Init(&init);

  /* Disable interrupt generation from RTC0 */
  RTC_IntDisable(_RTC_IF_MASK);

  /* Enable interrupts */
  NVIC_ClearPendingIRQ(RTC_IRQn);
  NVIC_EnableIRQ(RTC_IRQn);
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
#if (ARCH == ARCH_AVR8)
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);
#endif

	/* Hardware Initialization */
	LEDs_Init();
	ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);
	Temperature_Init();
	Dataflash_Init();
	USB_Init();
	TWI_Init(TWI_BIT_PRESCALE_4, TWI_BITLENGTH_FROM_FREQ(4, 50000));
	RTC_Init();

	/* 500ms logging interval timer configuration */
	OCR1A   = (((F_CPU / 256) / 2) - 1);
	TCCR1B  = (1 << WGM12) | (1 << CS12);
	TIMSK1  = (1 << OCIE1A);

	/* Check if the Dataflash is working, abort if not */
	if (!(DataflashManager_CheckDataflashOperation()))
	{
		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
		for(;;);
	}

	/* Clear Dataflash sector protections, if enabled */
	DataflashManager_ResetDataflashProtections();
}
Example #20
0
void rtt_init(void)
{
    /* prescaler of 32768 = 1 s of resolution and overflow each 194 days */
    CMU_ClockDivSet(cmuClock_RTC, cmuClkDiv_32768);

    /* enable clocks */
    CMU_ClockEnable(cmuClock_CORELE, true);
    CMU_ClockEnable(cmuClock_RTC, true);

    /* reset and initialize peripheral */
    EFM32_CREATE_INIT(init, RTC_Init_TypeDef, RTC_INIT_DEFAULT,
        .conf.enable = false,
        .conf.comp0Top = false
    );

    RTC_Reset();
    RTC_Init(&init.conf);

    /* enable interrupts */
    RTC_IntEnable(RTC_IEN_OF);

    NVIC_ClearPendingIRQ(RTC_IRQn);
    NVIC_EnableIRQ(RTC_IRQn);

    /* enable peripheral */
    RTC_Enable(true);
}
void rtc_test()
{
    unsigned char sec,min,hour,day,month,year;
    UART_Printf("\n\rConnections SCL->P0.6 SDA->P0.7");
	UART_Printf("\n\r Make connections and hit 'k' to test! ");
    while(UART_RxChar()!='k');   

	RTC_Init();

	
 /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetTime(0x10,0x40,0x00);  //  10:40:20 am
    RTC_SetDate(0x01,0x01,0x15);  //  1st Jan 2015

   /* Display the Time and Date continuously */ 
   while(1)
    {
        RTC_GetTime(&hour,&min,&sec);      
        RTC_GetDate(&day,&month,&year);        
        UART_Printf("\n\rtime:%2x:%2x:%2x  \nDate:%2x/%2x/%2x",(uint16_t)hour,(uint16_t)min,(uint16_t)sec,(uint16_t)day,(uint16_t)month,(uint16_t)year);
     }
    
   
}
/* start the main program */
void main() 
{
   unsigned char sec,min,hour,day,month,year;

  /* Initilize the Uart before Transmiting/Reaceiving any data */
    UART_Init(9600);

  /* Initilize the RTC(ds1307) before reading or writing time/date */
    RTC_Init();

	UART_TxString(" Testing RTC ");
 /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetTime(0x10,0x40,0x00);  //  10:40:20 am
    RTC_SetDate(0x01,0x01,0x15);  //  1st Jan 2015



   /* Display the Time and Date continuously */ 
   while(1)
    {
	   /* Read the Time from RTC(ds1307) */ 
        RTC_GetTime(&hour,&min,&sec);      
		
	    /* Read the Date from RTC(ds1307) */ 
        RTC_GetDate(&day,&month,&year);        
	 
        UART_Printf("\n\r the time is :%2x:%2x:%2x  \nDate:%2x/%2x/%2x",(uint16_t)hour,(uint16_t)min,(uint16_t)sec,(uint16_t)day,(uint16_t)month,(uint16_t)year);
	  }		

  }
Example #23
0
/*!
 * Init board.
 */
void BoardInit(void)
{
    /* Initialise ports. */
    PortInit();
    /* Initialise system clock. */
    SystemClkInit();
    /* Initialise SPI1. */
    Spi1Init();
    /* Initialise Timer0. */
    Timer0Init();
    /* Initialise Timer3. */
    Timer3Init();
    /* Initialise interrupts. */
    InterruptInit();
    /* Initialise the LCD. */
    LcdInit();
    /* Clear LCD. */
    LcdClearDisplay();
    /* Initialise LEDs. */
    LEDInit();
  #ifdef RTC_ENABLED
    /* RTC init. */
    RTC_Init();
  #endif //RTC_ENABLED
  #ifdef UART0_ENABLED
    /* UART0 init. */
    Uart0Init();
  #endif //UART0_ENABLED
}
Example #24
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{  
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();  
  
  /* Configure the system clock to have a system clock = 168 Mhz */
  SystemClock_Config();
  
  /* Initialize LCD and LEDs */
  BSP_Config();
  
  /* Initialize RTC and Backup */
  RTC_Init();
  
  /* Init the STemWin GUI Library */
  GUI_Init();
  GUI_Initialized = 1;
  
  /* Activate the use of memory device feature */
  WM_SetCreateFlags(WM_CF_MEMDEV);

  /* Do the calibration if needed */
  CALIBRATION_Check();
  
  /* Start Demo */
  GUIDEMO_Main();
  
  /* Infinite loop */
  for(;;);
}
Example #25
0
void main(void) {
	SystemInit();
	TEMP_init();
	AIRSENS_init();
	MEM_init();
	SysTick_Config(84000); // config systick to interrupt w/ 1 interrupt/ms
	sta.FAST_MODE = 1;
	sta.state = 0;
	sta.n_avg = 3;
	sta.temp_sum_f = 0;
	sta.fast_count = 0;
	sta.status.MEAS = 0;
	sta.status.TEMP_REQ = 0;
	
	
	
	RTC_Init(50, 00, 14, 20, 15, 01, 18, 7);
	while(1){
		tempSens();
		if(sta.status.MEAS == 1){
			sta.status.MEAS = 0;
			if(mem.temp->count>0){
				MEM_save((sta.temp_sum_f/mem.temp->count), AIRSENS_getPres() );
				sta.temp_sum_f = 0;
				mem.temp->count = 0;
			}
		}
		if(sta.status.NEW_DAY){
			sta.status.NEW_DAY = 0;
			MEM_newDay();
			//meas_count = 0;
		}
	}
}
Example #26
0
int main() 
{
    rtc_t rtc;
    SystemInit();
    UART0_Init(9600);  

    RTC_Init();
    rtc.hour = 10; //  10:40:20 am
    rtc.min =  40;
    rtc.sec =  0;

    rtc.date = 1; //1st Jan 2016
    rtc.month = 1;
    rtc.year = 2016;
    rtc.weekDay = 5; // Friday: 5th day of week considering monday as first day.   


    /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetDateTime(&rtc);  //  10:40:20 am, 1st Jan 2016


    /* Display the Time and Date continuously */
    while(1)
    {
        RTC_GetDateTime(&rtc);
        UART0_Printf("\n\rtime:%2d:%2d:%2d  Date:%2d/%2d/%4d",(uint16_t)rtc.hour,(uint16_t)rtc.min,(uint16_t)rtc.sec,(uint16_t)rtc.date,(uint16_t)rtc.month,(uint16_t)rtc.year);
    }	      
}
Example #27
0
void rtc_init(void) {
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); // Enable PWR clock

    PWR_RTCAccessCmd(ENABLE); // Enable access to RTC

    // Note: the LSI is used as RTC source clock
    // The RTC Clock may vary due to LSI frequency dispersion.  
   
    RCC_LSICmd(ENABLE); // Enable LSI
  
    while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {} // Wait until ready
    
    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); // Select LSI as RTC Clock Source
  
    RCC_RTCCLKCmd(ENABLE); // Enable RTC Clock 
      
    RTC_WaitForSynchro(); // Wait for RTC registers synchronization

    uint32_t lsi_freq = 40000; // [TODO] To be measured precisely using a timer input capture

    RTC_InitTypeDef RTC_InitStructure;
    RTC_InitStructure.RTC_AsynchPrediv = 127;
    RTC_InitStructure.RTC_SynchPrediv	 = (lsi_freq / 128) - 1;
    RTC_InitStructure.RTC_HourFormat   = RTC_HourFormat_24;
    RTC_Init(&RTC_InitStructure);
    
    PWR_RTCAccessCmd(DISABLE); // Disable access to RTC
      
    rtc_inited = 1;
}
Example #28
0
void RTC_SetUp(void)
{
  /* Allow access to RTC */
	PWR_BackupAccessCmd(ENABLE);
	RCC_LSICmd(ENABLE); // LSI is used as RTC clock source
	while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
		; // Wait till LSI is ready

	RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); // Select RTC clock source
// Enable RTC clock
	RCC_RTCCLKCmd(ENABLE);

	RTC_WaitForSynchro(); // Wait until the RTC Time and Date registers (RTC_TR and RTC_DR) are synchronized with RTC APB clock.

	  // Set RTC calendar clock to 1 HZ (1 second)
	RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
	RTC_InitStructure.RTC_AsynchPrediv = 88;
	RTC_InitStructure.RTC_SynchPrediv = 470;
  
	if (RTC_Init(&RTC_InitStructure) == ERROR)
	{
		while (1)
			;
	}
}
Example #29
0
/**
  * @brief  Calendar Configuration.
  * @param  None
  * @retval None
  */
void Calendar_Init(void)
{
  RTC_InitStr.RTC_HourFormat = RTC_HourFormat_24;
  RTC_InitStr.RTC_AsynchPrediv = 0x1F;
  RTC_InitStr.RTC_SynchPrediv = 0x03FF;
  RTC_Init(&RTC_InitStr);
}
void main() {

  Start_TP();

  Init_GPIO();
  Init_SDIO();
  Init_Ext_Mem();
  Init_FAT();
  RTC_Init();
  
  I2C2_Init_Advanced(400000, &_GPIO_MODULE_I2C2_PF01);
  UART2_Init_Advanced(9600, _UART_8_BIT_DATA, _UART_NOPARITY, _UART_ONE_STOPBIT, &_GPIO_MODULE_USART2_PD5_PA3);
  MPU9150A_FSY = 0;
  MPU9150A_Init();
  MPU9150A_Detect();
  MAG_Detect();
  tmrTicks = 0;
  initTimer2();
  Timer2_On();
  MPU9150A_Read(); //initial read
  delay_ms(10);

  while (1) {
    DisableInterrupts();
    Check_TP();
    EnableInterrupts();
    //DrawScreen(&Boot);
    //DrawScreen(&Speedometer_graphics);
    Run_logger();

  }
}