Hi,
I am using SAM3S-EK board - SAM3S4C chip. I have troubles setting up TC. I have following code
Code:
void TC0_IRQHandler(void)
{
ILI9325_DisplayInt(250,100,(int)tclk++);
}
//-----------------------------------------------------------------------------
void TC1_IRQHandler(void)
{
ILI9325_DisplayInt(250,200,(int)tclk++);
}
//-----------------------------------------------------------------------------
int main(void)
{
//sets 64MHz core clock
SystemInit();
//display init - uses PIOC
LCD_Init();
NVIC_DisableIRQ(TC0_IRQn);
NVIC_ClearPendingIRQ(TC0_IRQn);
NVIC_SetPriority(TC0_IRQn,0);
NVIC_EnableIRQ(TC0_IRQn);
NVIC_DisableIRQ(TC1_IRQn);
NVIC_ClearPendingIRQ(TC1_IRQn);
NVIC_SetPriority(TC1_IRQn,0);
NVIC_EnableIRQ(TC1_IRQn);
PMC_EnablePeripheral(ID_TC0);
TC_Configure(TC0,0,TC_CMR0_TCCLKS_TIMER_CLOCK4 | TC_CMR0_ACPC_SET | TC_CMR0_WAVE | TC_CMR0_ACPA_CLEAR | (0x2 << 13));
REG_TC0_RA0 = 25000;
REG_TC0_RC0 = 50000;
REG_TC0_IER0 = TC_IER0_CPCS;
TC_Start(TC0,0);
PMC_EnablePeripheral(ID_TC1);
TC_Configure(TC1,0,TC_CMR0_TCCLKS_TIMER_CLOCK4 | TC_CMR0_ACPC_SET | TC_CMR0_WAVE | TC_CMR0_ACPA_CLEAR | (0x2 << 13));
//tick 500000/s, chci 1ms - > 500
REG_TC1_RA0 = 25000;
REG_TC1_RC0 = 50000;
REG_TC1_IER0 = TC_IER0_CPCS;
TC_Start(TC1,0);
while(1);
}
where PMC_, NVIC_ functions are from library coming with the kit, LCD_Init handles the display and TC_ are defined as follows
Code:
void TC_Configure(Tc *pTc, unsigned char channel, unsigned int mode)
{
TcChannel *pTcCh = &pTc->TC_CHANNEL[channel];
/* Disable TC clock */
pTcCh->TC_CCR = TC_CCR0_CLKDIS;
/* Disable interrupts */
pTcCh->TC_IDR = 0xFFFFFFFF;
/* Clear status register */
pTcCh->TC_SR;
/* Set mode */
pTcCh->TC_CMR = mode;
}
void TC_Start(Tc *pTc, unsigned char channel)
{
TcChannel *pTcCh = &pTc->TC_CHANNEL[channel];
pTcCh->TC_CCR = TC_CCR0_CLKEN | TC_CCR0_SWTRG;
}
Other register handling functions and macros are taken from AT91SAM3S4.h, shipped with Keil Compiler.
Now I would assume that since I am handling both timers exactly the same way, I get the same result. That is wrong, it works only for TC0 channel 0 - IRQ handler is called and text is drawn on the display. If I try any other TC, or any other unit on the first TC, nothing happens - no handler is called.
Code:
//Not working
PMC_EnablePeripheral(ID_TC0);
TC_Configure(TC0,1,TC_CMR0_TCCLKS_TIMER_CLOCK4 | TC_CMR0_ACPC_SET | TC_CMR0_WAVE | TC_CMR0_ACPA_CLEAR | (0x2 << 13));
REG_TC0_RA1 = 25000;
REG_TC0_RC1 = 50000;
REG_TC0_IER1 = TC_IER0_CPCS;
TC_Start(TC0,1);
I guess I am missing some basic point of TC handling (I read TC manual three times back and forward, I swear

), and I would be very grateful if somebody could point me the right way.
Regards
Petr