SAM3S Timer0 works, Timer1 does not

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

karelv
Posts: 1
Joined: Mon Feb 16, 2015 5:12 pm

SAM3S Timer0 works, Timer1 does not

Mon Feb 16, 2015 5:33 pm

Hi,

Device: ATSAM3S2B

Functionality: Timer TC0 and Timer TC1

Problem:  I used example code to initiate and utilize TC0. This timer works perfect and the interrupt handler gets called. I changed the code to use TC1 and the interrupt handler never gets called... Am I forgetting an initialization somewhere or am I setting some wrong register?


Timer0 code (working and uses TC0 channel 0):
in main:

Code: Select all

/* Configure TCs. */
	configure_tc();
configure_tc1();
configure_tc():

Code: Select all

static void configure_tc(void)
{
	uint32_t ul_div;
	uint32_t ul_tcclks;
	uint32_t ul_sysclk = sysclk_get_cpu_hz();

	// Configure PMC
	pmc_enable_periph_clk(ID_TC0);

	// Configure TC for a 1Hz frequency and trigger on RC compare.
	tc_find_mck_divisor(1, ul_sysclk, &ul_div, &ul_tcclks, ul_sysclk);
	tc_init(TC0, 0, ul_tcclks | TC_CMR_CPCTRG);
	tc_write_rc(TC0, 0, (ul_sysclk / ul_div));

	// Configure and enable interrupt on RC compare
	NVIC_EnableIRQ((IRQn_Type) ID_TC0);
	tc_enable_interrupt(TC0, 0, TC_IER_CPCS);
}
TC0 handler:

Code: Select all

void TC0_Handler(void)
{
	uint32_t ul_status;
	uint32_t ul_byte_total = 0;

	/* Read TC0 Status. */
	ul_status = tc_get_status(TC0, 0);
	
	//DO SOMETHING HERE
}
Then I changed the code to use TC1, channel 0
configure_tc0():

Code: Select all

static void configure_tc1(void)
{
	uint32_t ul_div;
	uint32_t ul_tcclks;
	uint32_t ul_sysclk = sysclk_get_cpu_hz();

	// Configure PMC
	pmc_enable_periph_clk(ID_TC1);

	// Configure TC for a 1Hz frequency and trigger on RC compare.
	tc_find_mck_divisor(1, ul_sysclk, &ul_div, &ul_tcclks, ul_sysclk);
	tc_init(TC1, 0, ul_tcclks | TC_CMR_CPCTRG);
	tc_write_rc(TC1, 0, (ul_sysclk / ul_div));

	// Configure and enable interrupt on RC compare
	NVIC_EnableIRQ((IRQn_Type) ID_TC1);
	tc_enable_interrupt(TC1, 0, TC_IER_CPCS);
}
Handler:

Code: Select all

void TC1_Handler(void)
{uint32_t ul_status;
	uint32_t ul_byte_total = 0;

	/* Read TC1 Status. */
	ul_status = tc_get_status(TC1, 0);
	
	//DO SOMETHING HERE
}
Or if someone has working code for TC1 it would be greatly apprecitated!
Andy Peters
Posts: 46
Joined: Mon Jul 08, 2013 11:09 pm

Re: SAM3S Timer0 works, Timer1 does not

Tue Mar 03, 2015 12:50 am

Oh my. I used to think that the Atmel user guides were no good. But I revise that opinion: they really do suck in very interesting ways.

You are using the ATSAM3S2B. While the user guide does not come out and say so, this part does NOT have a TC1. It only has TC0.

Header file sam3s3b.h refers only to TC0. There is no base register address defined for TC1.

It would be nice if the documentation made this clear!

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests