Why does enabling TIMSK1 mess up serial? I am intending to write a code where a user will send lines through serial to affect timer interrupts. I am noticing a problem with serial where as soon as I enable the timer interrupts, the serial communication becomes garbled. More specifically, as soon as I enable the timer interrupts and I open the serial monitor, the monitor gets flooded with garbage. I haven't written too much code and this is already happening. Am I making a silly mistake? I am using an Arduino Mega 2560. My code is below:

void setup() {
  Serial.begin(9600);
  Serial.println("Hello World!");
  timer_setup();
}

void loop() {
  // put your main code here, to run repeatedly:
}

void timer_setup() {
  // waveform generation = 0100 = CTC
  TCCR1B &amp;= ~(1 &lt;&lt; WGM13);
  TCCR1B |=  (1 &lt;&lt; WGM12);
  TCCR1A &amp;= ~(1 &lt;&lt; WGM11);
  TCCR1A &amp;= ~(1 &lt;&lt; WGM10);
  // output mode = 00 (disconnected)
  TCCR1A &amp;= ~(3 &lt;&lt; COM1A0);
  TCCR1A &amp;= ~(3 &lt;&lt; COM1B0);
  // Set the timer pre-scaler
  TCCR1B = (TCCR1B &amp; ~(0x07 &lt;&lt; CS10)) | (2 &lt;&lt; CS10);
  OCR1A = 0x4000;
  TCNT1 = 0;
  // Enable timer interrupt mask 1
  TIMSK1 |= (1&lt;&lt;OCIE1A);
}


If I comment out the TIMSK1 |= (1&lt;&lt;OCIE1A) line, serial doesn't mess up.
You've enabled interrupts for Timer 1 Compare A interrupt. Where is the interrupt handler?

For example:

ISR(TIMER1_COMPA_vect)
{
  // whatever
}  // end of TIMER1_COMPA_vect


Without that, the processor is just restarting. No wonder serial output is messed up.