SAM4S Xplained Pro RTC Demo2018-10-19T06:23:11+00:00

ASF version

Tested for ASF version 3.31.0

ASF Modules required 

  • RTC – Real Time Clock (driver)

Basic Demo

The demo prints the time in the OLED Display (add OLED1306 drivers to project).
See RTC Demo.

 

Code
#include <asf.h>
#include <string.h>


static void rtc_setup(void)
{
	pmc_switch_sclk_to_32kxtal(PMC_OSC_XTAL);
	while (!pmc_osc_is_ready_32kxtal());
	rtc_set_hour_mode(RTC, 0); //24-hrs mode by default

}

int main(void)
{

	sysclk_init();
	board_init();
	ssd1306_init();
	
	//initialize RTC
	rtc_setup();

	//set time
	rtc_set_date( RTC, 2015, 3, 25, 0 );
	rtc_set_time( RTC, 11, 39, 0 );
	
	uint32_t seconds = 0;
	uint32_t minutes = 5;
	uint32_t hours = 17;
	uint8_t text[20];
	
	ssd1306_clear();

	while(1){
		//get time
		rtc_get_time(RTC, &hours, &minutes, &seconds);
		
		//print time
		ssd1306_set_page_address(0);
		ssd1306_set_column_address(0);
		sprintf( text, "%02d:%02d:%02d", hours, minutes, seconds );
		ssd1306_write_text(text);
		
		delay_ms(100);
	}


}