ATMEGA4809 CLKOUT on PA7

ATMEGA4809 CLKOUT on PA7

Code to output CPU clock on pin PA7:

#define CLKOUT_OFF 0
#define CLKOUT_ON 1

void clock_out(int option) { // PA7
  cli();  // Disable Interrupts
  switch (option) {
    case CLKOUT_ON:
      _PROTECTED_WRITE(CLKCTRL_MCLKCTRLA, CLKCTRL_CLKOUT_bm);
      break;
    case CLKOUT_OFF:
    default:
      _PROTECTED_WRITE(CLKCTRL_MCLKCTRLA, (CLKCTRL_MCLKCTRLA & ~(CLKCTRL_CLKOUT_bm)));
  }
  sei();  // Enable Interrupts
}

Call the function from setup() like this:

clock_out(CLKOUT_ON);
// clock_out(CLKOUT_OFF);

Leave a Reply