Close

It Blinks!

A project log for Atmel SAMC breakout

Simple breakout board for Atmel's SAMC 5V ARM chip.

westfwWestfW 08/05/2019 at 08:080 Comments

Aside from Microchip apparently deciding to rename all the peripheral registers, going from "running" to "blinking the LED" went pretty quickly.  Running at 48MHz, 2 wait states, and outputting the clock on its respective IO pin.  Woo hoo!

int main(void) {
    // Clock at reset is set to the internal 48MHz clock, divided by 12.
    NVMCTRL_REGS->NVMCTRL_CTRLB |= NVMCTRL_CTRLB_RWS(2); // 2 wait states for 48MHz
    OSCCTRL_REGS->OSCCTRL_OSC48MDIV = 0;  // no division
    GCLK_REGS->GCLK_GENCTRL[0] |= GCLK_GENCTRL_OE_Msk; // output the clock on a pin
    PORT_REGS->GROUP[0].PORT_DIRSET = GCLK0_OUT;
    PORT_REGS->GROUP[0].PORT_PMUX[GCLK0_PIN/2] |= 7;  // PMUX H is clkO
    PORT_REGS->GROUP[0].PORT_PINCFG[GCLK0_PIN] |= PORT_PINCFG_PMUXEN_Msk;
    PORT_REGS->GROUP[0].PORT_DIRSET = LED;
    
    while (1) {
        PORT_REGS->GROUP[0].PORT_OUTTGL = LED;
        mydelay();
    }
    return;
}

Discussions