SAM D10 - Event generation from EIC to TC1

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone,

I'm a newbie in SAM program. I want to know Events functionalities. I'm trying to generate an event on channel 0 from a external button (on EIC 5). Then the event0 have to  increment TC1 counter.

  • First step work OK: when button is pressed EXTIN5 bit in INTFLAG register is set
  • Second step doesn't work: TC1 is not configured yet to handle the event 0. Then when button is pressed and EIC generate event I don't see CHBUSY0 bit set in CHSTATUS register

 

EIC 5 configuration code:

void Eic5_init()
{
    /* Synchronous clock already enabled for default */
	//PM->APBBMASK.reg |= PM_APBBMASK_PORT;
	
	/* PA25 port configuration */
	PORT_REGS->GROUP[0].PORT_DIRCLR = PORT_PA25;
	PORT_REGS->GROUP[0].PORT_PINCFG[PIN_PA25] = PORT_PINCFG_PMUXEN(1) | PORT_PINCFG_INEN(1);
	
	GCLK_REGS->GCLK_CLKCTRL = GCLK_CLKCTRL_ID_EIC | GCLK_CLKCTRL_GEN_GCLK2 | GCLK_CLKCTRL_CLKEN(1);
	
	/* Abilito il clock sincrono per EIC_REGS: già abilitato di default dopo il reset */
	//PM->APBAMASK.reg |= PM_APBAMASK_EIC_REGS;
	
	/* Configuro evento sensibile al fronte di salita del pin */
	EIC_REGS->EIC_CONFIG[0] = EIC_CONFIG_SENSE5(EIC_CONFIG_SENSE5_RISE_Val);
	
	/* Abilito il pin su evento 0 */
	EIC_REGS->EIC_EVCTRL = EIC_EVCTRL_EXTINTEO0(1);
	
	/* Abilito EIC_REGS */
	EIC_REGS->EIC_CTRL = EIC_CTRL_ENABLE(1);
	while(EIC_REGS->EIC_STATUS & EIC_STATUS_Msk);
}

Event 0 configuration code:

void EvSys0_init()
{
	/* Enable Asynchronous clock for Evsys */
	GCLK_REGS->GCLK_CLKCTRL = GCLK_CLKCTRL_ID_EVSYS_0 | GCLK_CLKCTRL_GEN_GCLK2 | GCLK_CLKCTRL_CLKEN(1);
	
	/* Enable Synchronous clock for Evsys */
	PM_REGS->PM_APBCMASK |= PM_APBCMASK_EVSYS(1);
	
	/* Reset Evsys */
	EVSYS_REGS->EVSYS_CTRL = EVSYS_CTRL_SWRST(1);
	while (EVSYS_REGS->EVSYS_CTRL & EVSYS_CTRL_SWRST_Msk);
	
	/* User configuration */
	EVSYS_REGS->EVSYS_USER =    ((EVSYS_USER_CHANNEL_0_Val + 1) << EVSYS_USER_CHANNEL_Pos) |	//User listen on channel 0
                                EVSYS_USER_USER(0x0A);                                          //User is TC1
	/* Channel configuration */
	EVSYS_REGS->EVSYS_CHANNEL = EVSYS_CHANNEL_EDGSEL_RISING_EDGE |  //On the rising edge
                                EVSYS_CHANNEL_PATH_SYNCHRONOUS |    //Synchronous path
                                EVSYS_CHANNEL_EVGEN(0x11) |         //EXTINT5 generator
                                EVSYS_CHANNEL_CHANNEL(1);           //Channel 0
}

 

main code:

int main(void)
{
    /* Initialize the SAM system */
    //SystemInit();
    
	__enable_irq();
	
	PORT_REGS->GROUP[0].PORT_DIRSET |= PORT_PA09;
	PORT_REGS->GROUP[0].PORT_OUTCLR |= PORT_PA09;
	
	/* Initialize clocks */
	DFLL48M_init(false);	/* Synchronous clock */
	OSC8M_init();			/* Asynchronous clock */
    
    EvSys0_init();
	Eic5_init();
	//Tc1_init();
    
#if 0	
	EVSYS_REGS->EVSYS_CTRL |= EVSYS_CTRL_GCLKREQ(1);
	EVSYS_REGS->EVSYS_CHANNEL |= EVSYS_CHANNEL_CHANNEL(1) | EVSYS_CHANNEL_SWEVT(1);
#endif
    
    /* Replace with your application code */
    while (1) 
    {
		PORT_REGS->GROUP[0].PORT_OUTSET |= PORT_PA09;
		asm("nop");
    }
}

Where is my mistake?

Thank for your reply

This topic has a solution.
Last Edited: Mon. Jul 19, 2021 - 06:37 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seems some non-standard register access is going on in your code but surely this must be wrong :

	EIC_REGS->EIC_EVCTRL = EIC_EVCTRL_EXTINTEO0(1);

The event for EXTINT5 should be enabled not EXTINT0.

/Lars

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you Lars (again) for your reply. The mistake were 2:

//EIC_REGS->EIC_EVCTRL = EIC_EVCTRL_EXTINTEO0(1);
EIC_REGS->EIC_EVCTRL = EIC_EVCTRL_EXTINTEO5(1);

and:

	/* Channel configuration */
	EVSYS_REGS->EVSYS_CHANNEL = EVSYS_CHANNEL_EDGSEL_RISING_EDGE |  //On the rising edge
                                EVSYS_CHANNEL_PATH_SYNCHRONOUS |    //Synchronous path
                                EVSYS_CHANNEL_EVGEN(0x11) |         //EXTINT5 generator
                                //EVSYS_CHANNEL_CHANNEL(1);           //Channel 0
                                EVSYS_CHANNEL_CHANNEL(0);           //Channel 0

Now work!

Sorry, but there aren't very resources on the web for programming SAM devices in bare C

The only one I have found is microchipdeveloper site and......this forum of course