Skip to content

Instantly share code, notes, and snippets.

@lgbeno lgbeno/tc2_test.ino
Last active Nov 13, 2018

Embed
What would you like to do?
SAMD51 TC2 EVSYS Not working
#define PA13 22
#define J5E PA13
#define USE_EVSYS
void e_irq() {
TC2->COUNT16.CTRLBSET.bit.CMD = 4;
while(TC2->COUNT16.SYNCBUSY.bit.COUNT);
Serial.println(TC2->COUNT16.COUNT.reg);
}
void setup() {
Serial.begin(115200);
while(!Serial);
Serial.println("TC2 Test");
MCLK->APBAMASK.reg |= MCLK_APBAMASK_EIC;
MCLK->APBBMASK.reg |= MCLK_APBBMASK_TC2 | MCLK_APBBMASK_EVSYS;
GCLK->GENCTRL[7].bit.SRC = 3;
GCLK->PCHCTRL[TC2_GCLK_ID].bit.GEN = 7;
GCLK->PCHCTRL[TC2_GCLK_ID].bit.CHEN = 1;
GCLK->GENCTRL[7].bit.GENEN = 1;
TC2->COUNT16.CTRLA.bit.SWRST = 1;
while(TC2->COUNT16.SYNCBUSY.bit.SWRST);
TC2->COUNT16.INTENSET.reg = TC_INTENSET_MC0 | TC_INTENSET_MC1 | TC_INTENSET_OVF;
#ifdef USE_EVSYS
TC2->COUNT16.EVCTRL.reg = TC_EVCTRL_EVACT_PPW | TC_EVCTRL_TCEI;
#endif
TC2->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 |
#ifndef USE_EVSYS
TC_CTRLA_COPEN0 | TC_CTRLA_COPEN1 |
#endif
TC_CTRLA_CAPTEN0 | TC_CTRLA_CAPTEN1 |
TC_CTRLA_ENABLE;
NVIC_EnableIRQ( TC2_IRQn ) ;
// PA13 connectomux to E
#ifdef USE_EVSYS
PORT->Group[0].PMUX[6].bit.PMUXO = 0;
#else
PORT->Group[0].PMUX[6].bit.PMUXO = 4;
#endif
PORT->Group[0].PINCFG[13].bit.PULLEN = 0;
PORT->Group[0].PINCFG[13].bit.INEN = 1;
PORT->Group[0].PINCFG[13].bit.PMUXEN = 1;
#ifdef USE_EVSYS
attachInterrupt(J5E,e_irq,RISING);
EIC->CTRLA.bit.ENABLE = 0;
EIC->INTENCLR.bit.EXTINT = (1<<13);
EIC->EVCTRL.bit.EXTINTEO = (1<<13);
EIC->CTRLA.bit.ENABLE = 1;
EVSYS->USER[EVSYS_ID_USER_TC2_EVU].reg = 1;
EVSYS->Channel[0].CHANNEL.reg =(uint32_t) (EVSYS_ID_GEN_EIC_EXTINT_13 | EVSYS_CHANNEL_PATH_ASYNCHRONOUS);
#endif
}
void TC2_Handler() {
Serial.print("TC2 IRQ ");
Serial.print(TC2->COUNT16.INTFLAG.reg,HEX);
TC2->COUNT16.INTFLAG.reg = 0x33;
Serial.print(" ");
Serial.print(TC2->COUNT16.CC[0].reg);
Serial.print(" ");
Serial.print(TC2->COUNT16.CC[1].reg);
Serial.print(" ");
Serial.println(TC2->COUNT16.INTFLAG.reg,HEX);
}
void loop() {
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.