SAM DA EIC Problems

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

I have been pouring over the datasheet and several other forum posts about configuring the EIC on the SAM series chips and I believe I am covering all the steps, but the code keeps hanging when I check the SYNCBUSY bit in the EIC Status register after enabling the EIC.  My complete code is posted below, but my basic steps are as follows: Make sure the internal 8MHz oscillator is running, set GCLK4 to the 8MHz Oscillator, set the EIC to use GCLK4, enable the IO pin as input and enable the PMUX, set the PMUX to the external interrupt, enable the EIC interrupt, configure the interrupt to falling edge triggered, enable EIC, and finally, check the SYNCBUSY bit.  If I comment out the falling edge triggered setting, the code will run past the SYNCBUSY check, which I believe points to my GCLK settings somehow.  Any tips or solutions would be greatly appreciated. 

 

PORT->Group[0].DIRCLR.reg |= PORT_PA00;

REG_SYSCTRL_OSC8M |= SYSCTRL_OSC8M_ENABLE;

while(!(REG_SYSCTRL_PCLKSR & SYSCTRL_PCLKSR_OSC8MRDY)){};
REG_GCLK_GENDIV |= GCLK_GENDIV_ID(4)|GCLK_GENDIV_DIV(0x0);
REG_GCLK_GENCTRL |= GCLK_GENCTRL_ID(4)|GCLK_GENCTRL_GENEN|GCLK_GENCTRL_SRC_OSC8M;
REG_GCLK_CLKCTRL |= GCLK_CLKCTRL_GEN(4)|GCLK_CLKCTRL_ID_EIC|GCLK_CLKCTRL_CLKEN;
PORT->Group[0].PINCFG[16].bit.PULLEN = 1;
PORT->Group[0].PINCFG[16].bit.PMUXEN = 1;
PORT->Group[0].PMUX[9].bit.PMUXO = MUX_PA16A_EIC_EXTINT0;
EIC->INTENSET.reg = EIC_INTENSET_EXTINT0;
EIC->CONFIG[0].bit.SENSE0 = EIC_CONFIG_SENSE0_FALL;
EIC->CTRL.reg |= EIC_CTRL_ENABLE;

while((REG_EIC_STATUS & EIC_STATUS_SYNCBUSY)){};
NVIC_EnableIRQ(EIC_IRQn);

 

This topic has a solution.
Last Edited: Fri. Nov 9, 2018 - 03:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, I have an edit, the first line should read

 

PORT->Group[0].DIRCLR.reg |= PORT_PA16;

not

PORT->Group[0].DIRCLR.reg |= PORT_PA00;

 

The code still gets stuck in the while loop with this edit.  My exact chip is SAMDA1J14B

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

More Information on the Problem

 

It turns out that the program will not hang in the while loop if I don't initialize another GCLK for a peripheral timer.  If I comment out these two lines earlier in the program

 

REG_GCLK_CLKCTRL = GCLK_CLKCTRL_CLKEN|GCLK_CLKCTRL_GEN_GCLK3|GCLK_CLKCTRL_ID_TCC2_TC3;
REG_GCLK_GENCTRL = GCLK_GENCTRL_GENEN|GCLK_GENCTRL_ID(3)|GCLK_GENCTRL_SRC_OSC32K;

 

Then the EIC will run.  I need both peripherals to run in my project.  Am I setting up generic clock generators wrong?  I thought they would be seperate because one is ID=3 and the other I use ID=4.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Assign the registers don't use |=

/Lars

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

Thank you so much for the help!  I should have seen something that simple.