SAM4S Xplained Pro RTT Demo

Posted on Sep 12, 2016 | 0 comments


SAM4S Xplained Pro RTT Demo

ASF version

Tested for ASF version 3.31.0

ASF Modules required 

  • RTT – Real Time Timer

Basic Demo

Demo in progress. Meanwhile…

Use this to start it. The counter is incremented (i.e. it ticks) every steps/(2^15) seconds

uint32_t steps;	

//Configure
rtt_sel_source(RTT, false);	
rtt_init( RTT, steps ); //Configure RTT to tick every steps/32768 secs... 

 

Use this to start it with a callback that is triggered on every tick.

//sets callback
timer_callback = callback;
	
//Configure
rtt_sel_source(RTT, false);	
rtt_init(RTT, steps ); //Configure RTT to tick every steps/32768 secs... 
	
//Wait until timer starts going? (not sure why this is needed)
volatile uint32_t ul_previous_time = rtt_read_timer_value(RTT);
while (ul_previous_time == rtt_read_timer_value(RTT));

//Clear previous on-going ints? (not too sure of this either)
NVIC_DisableIRQ(RTT_IRQn);
NVIC_ClearPendingIRQ(RTT_IRQn);
		
//Sets new int 
NVIC_SetPriority(RTT_IRQn, 0);
NVIC_EnableIRQ(RTT_IRQn);
rtt_enable_interrupt(RTT, RTT_MR_RTTINCIEN);

 

Stop it like this

	NVIC_DisableIRQ(RTT_IRQn);
	NVIC_ClearPendingIRQ(RTT_IRQn);
	rtt_disable_interrupt(RTT, RTT_MR_RTTINCIEN);

 

Use this to read it (read the count i.e. the number of ticks)

rtt_read_timer_value (RTT);

 

Use this to read it from within a handler

//The RTT ISR
void RTT_Handler(void){
	uint32_t ul_status;

	//get rtt status
	ul_status = rtt_get_status(RTT);
	
	//Check whether the Timer has been incremented since the last read
	if ((ul_status & RTT_SR_RTTINC) == RTT_SR_RTTINC) {

		//Timer tick has occurred!
//...
	}
}

Submit a Comment

Your email address will not be published. Required fields are marked *