Hello, all!
I have an SAMD21 Xplained pro. I need to set a 3MHz clock to one of the pins on one of the connectors.
I have the following code, which I assembled from snippedts on these forums:
This code successfully outputs 1MHz on pin PA14 (which is not on any connector).
#include <asf.h> void InitClock() { GCLK_GENDIV_Type gendiv = { .bit.DIV = 1, //Do not divide .bit.ID = 0, //GCLK[0] }; GCLK->GENDIV.reg = GCLK_GENDIV_ID(0) | GCLK_GENDIV_DIV(1); GCLK->GENCTRL.reg = GCLK_GENCTRL_ID(0) | GCLK_GENCTRL_SRC_OSC8M | GCLK_GENCTRL_RUNSTDBY | GCLK_GENCTRL_GENEN | GCLK_GENCTRL_OE; GCLK_CLKCTRL_Type clkctrl = { .bit.CLKEN = 1, .bit.GEN = GCLK_CLKCTRL_GEN_GCLK0_Val //ID of the clock }; GCLK->CLKCTRL.reg =clkctrl.reg; while (GCLK->STATUS.bit.SYNCBUSY); } void PortInit() { PORT->Group[0].DIRSET.reg |= PORT_PA14; PORT->Group[0].PINCFG[14].reg |= PORT_PINCFG_PMUXEN; PORT->Group[0].PMUX[7].bit.PMUXE = 0x7; //Attach clock to I/O } void main() { InitClock(); PortInit(); }
I need this to be 3 MHz, and on another pin (for example, pin PA15).
I have tried achieving this, by:
1. in InitClock() , witching the GCLK_GENCTRL_SRC_OSC8M to GCLK_CLKCTRL_ID_DFLL48 (48MHz, which I can divide by 16) - this doesn't work, whatever I do, the clock rate remains 1MHz.
2. in PortInit, switching PA14 to PA15, by substituting:
- PORT->Group[0].DIRSET.reg |= PORT_PA14; ---> PORT->Group[0].DIRSET.reg |= PORT_PA15;
- PORT->Group[0].PINCFG[14].reg |= PORT_PINCFG_PMUXEN; ---> PORT->Group[0].PINCFG[15].reg |= PORT_PINCFG_PMUXEN;
This also doesn't work. The clock won't appear on pin PA15.
Can you please instruct me on how to output 3MHz clock on PA15 (or another pin)?
Thanks!