RFID reader reboots Mega 2560 when using 12v power supply

Okay i found a software fix and it seems to work great;

void clearSerial() {
  while (Serial1.read() >= 0) {;} //clear the buffer
	
}

void ReadyforRFID()
{
    
    prevDisplay = now();
    digitalClockDisplay();
    clearSerial();
    delay(1000);   
      LCDScreenupdate("   Scan your    ","  RFID Tag now!  ");
 
}