Board freezes using Serial.println with sei(); cli();

void setup() 
{ 
  pinMode(13, OUTPUT);
  Serial.begin(9600); 
} 

void loop ()    
{
  digitalWrite(13, LOW); //just to see when the program/board freezes
  
  sei();      //Enables interrupts
  delay (300); 
  cli();      //Disable interrupts
  digitalWrite(13, HIGH); //just to see when the program/board freezes
  Serial.println ("pretty looooooooooooooooooooooooong woooooooooooooooooooooords");
}

I know the code has no meaning this way, but I reduced it to its simplest expression to better understand why the board freezes.

Here is the issue :
The way the code is written will freeze a UNO board (tried it on two different boards, same problem). If i take away just one character from the Serial.println sentence, it doesn't freeze! I came to realize that the issue is related to sei(); and cli(); but I have no idea how to fix this. BTW, even when nothing is connected to the board, I get this problem...

I'm using the IDE version 1.0.6.

Any ideas?

Interrupts are used for serial printing. If you fill up the buffer it waits for an interrupt to empty it, which doesn't happen if interrupts are off. The buffer is probably 64 bytes in your case. Your string, including the cr/lf at the end is 64 bytes.

So, working as expected.

Your code looks suspiciously like code which is not recommended. Read that link for alternatives.

Thanks for your very incredibly fast reply! I guess it solves my weird problem :smiley: