简体   繁体   中英

Xplained pro SAM4SD32C - Timer 1 - Can't write on RA register

I'm struggling with timer 1 configuration of the SAM4SD32C of the XPlained Pro Sam4s Board... I first used timer 0 and I could generate the waveform I needed.

So I copied past the code, adapted it for timer 1 to generate other waveform following the same technique. While debugging I noticed I couldn't get into my Interrupt routine. I inspected further and noticed that I couldn't write into Register RA and RC of timer 1 using tc_write_ra() and tc_write_rc() functions.

Here's part of my code, which I considered could help answering my problem. If more code is needed, then ask in comments.

#define TIMER_DOOR          TC1
#define TIMER_DOOR_ID       ID_TC1
#define TIMER_DOOR_CHANNEL  1
#define TIMER_DOOR_Handler  TC1_Handler
#define TIMER_DOOR_IRQn     TC1_IRQn

...

void ConfigureDoorTimer(uint32_t ra, uint32_t rc)
{
    uint32_t debug1, debug2 = 0;
    TcChannel *tc_channel =0;
    sysclk_enable_peripheral_clock(TIMER_DOOR_ID);
    tc_init(TIMER_DOOR, TIMER_DOOR_CHANNEL,
                                            TC_CMR_TCCLKS_TIMER_CLOCK4        // Clock selected: MCK/128 : 1 cycle = 128 / 120000000 = 1.06 usec
                                            | TC_CMR_WAVE                     // Waveform mode is enabled
                                            | TC_CMR_WAVSEL_UP_RC);           // UP mode with automatic trigger on RC Compare
    tc_channel = TIMER_DOOR->TC_CHANNEL + TIMER_DOOR_CHANNEL;
    tc_channel->TC_CMR = tc_channel->TC_CMR;
    debug1 = (uint32_t) tc_channel->TC_CMR & TC_CMR_WAVE;
    /* Configure max value before overflow */
    tc_write_ra(TIMER_DOOR, TIMER_DOOR_CHANNEL, ra);
    tc_write_rc(TIMER_DOOR, TIMER_DOOR_CHANNEL, rc);

    NVIC_EnableIRQ(TIMER_DOOR_IRQn);
    NVIC_SetPriority(TIMER_DOOR_IRQn, TIMER_DOOR_IRQ_PRIO);
    tc_enable_interrupt(TIMER_DOOR, TIMER_DOOR_CHANNEL, TC_IER_CPAS | TC_IER_CPCS);//Enables the RA, RC Compare Interrupt
    tc_stop(TIMER_DOOR, TIMER_DOOR_CHANNEL);          // will be started later
}

You can see in this example I've tried reading the CMR register, applying to it a mask = TC_CMR_WAVE, because it's said in the Sam4sd16c datasheet that if if TC_CMRx.WAVE = 1, then RA register is W/R accessible. And while debugging I've noticed this test was true... So I don't know why I can't write on my timer 1 :(

Well, I've kept going inspecting my code and I think I understood what the mistake is...

In TC0, there are 3 timers : ID_TC0 (channel 0), ID_TC1 (channel 1) and ID_TC2 (channel 2)

And in TC1, there are also 3 timers : ID_TC3 (channel 0), ID_TC4 (channel 1) and ID_TC5 (channel 2)

To activate a specific channel, you should activate the right clock peripheric, by using the function sysclk_enable_peripheral_clock(TIMER_DOOR_ID) all the remaining functions called in the code above are working well after correction applied.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM