SAM4E Help using RTT with an ISR

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I am trying to configure and learn interrupts on this platform. My coding skills are noob level and I am coming from a PIC 8bit background. I have a custom board and used the ASF wizard to get started. I am able to debug the board over JTAG with a SAM-ICE. I have burned out on google searching how to setup the RTT and use the interrupt and am seeking help or an example on how to do so. 

 

 

rtt.h gives me everything that I need but I am not sure how to use it properly.

uint32_t rtt_init(Rtt *p_rtt, uint16_t us_prescaler);
#if (SAM4N || SAM4S || SAM4E || SAM4C || SAMG || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70)
void rtt_sel_source(Rtt *p_rtt, bool is_rtc_sel);
void rtt_enable(Rtt *p_rtt);
void rtt_disable(Rtt *p_rtt);
#endif
void rtt_enable_interrupt(Rtt *p_rtt, uint32_t ul_sources);
void rtt_disable_interrupt(Rtt *p_rtt, uint32_t ul_sources);
uint32_t rtt_read_timer_value(Rtt *p_rtt);
uint32_t rtt_get_status(Rtt *p_rtt);
uint32_t rtt_write_alarm_time(Rtt *p_rtt, uint32_t ul_alarm_time);

EDIT:

I found this on a cached website. I assume it will work for a SAM4E. I will try it out but I still appreciate any pointers about how the pointers work LOL.

SAM4S Xplained Pro RTT Demo2018-10-19T06:23:20+00:00

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!
//...
	}
}

 

NOOBLET