Home > Enterprise >  ATSAMD GCLK[x] for more Peripherals
ATSAMD GCLK[x] for more Peripherals

Time:12-11

is it possible to use one GCLK for more peripherals?

The ATSAMD09C13 have six GCLK Generators but this isn´t enougth.

This example works:

GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(SERCOM0_GCLK_ID_CORE) |
  GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN(0);

This example, with two ID´s doesn´t work:

GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(SERCOM0_GCLK_ID_CORE) | GCLK_CLKCTRL_ID(GCLK_CLKCTRL_ID_WDT) | 
  GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN(0);

Exist a way to solve this or is this not possible?

CodePudding user response:

In register GCLK_CLKCTRL the field ID is not a bit mask but holds the number of the peripheral you want to configure. you cannot combine them by ORing multiple IDs.

Instead configure each device separately:

Here is some code generated by Harmony3 to provide GCLK0 / GCLK1 to multiple devices:


    /* Selection of the Generator and write Lock for WDT */
    GCLK_REGS->GCLK_CLKCTRL = GCLK_CLKCTRL_ID(3) | GCLK_CLKCTRL_GEN(0x0)  | GCLK_CLKCTRL_CLKEN_Msk;

    /* Selection of the Generator and write Lock for EIC */
    GCLK_REGS->GCLK_CLKCTRL = GCLK_CLKCTRL_ID(5) | GCLK_CLKCTRL_GEN(0x1)  | GCLK_CLKCTRL_CLKEN_Msk;

    /* Selection of the Generator and write Lock for SERCOM0_CORE */
    GCLK_REGS->GCLK_CLKCTRL = GCLK_CLKCTRL_ID(14) | GCLK_CLKCTRL_GEN(0x1)  | GCLK_CLKCTRL_CLKEN_Msk;

    /* Selection of the Generator and write Lock for TC1 TC2 */
    GCLK_REGS->GCLK_CLKCTRL = GCLK_CLKCTRL_ID(18) | GCLK_CLKCTRL_GEN(0x1)  | GCLK_CLKCTRL_CLKEN_Msk;

    /* Selection of the Generator and write Lock for ADC */
    GCLK_REGS->GCLK_CLKCTRL = GCLK_CLKCTRL_ID(19) | GCLK_CLKCTRL_GEN(0x0)  | GCLK_CLKCTRL_CLKEN_Msk;
  • Related