problem with serial.print

The program works fine until I make it faster(too fast for serial?) or putting Serial.print in ISR…

I’m using interupteds that’ occuars every 0.064s(15Hz),I want to make it alot faster until it’s about 5-10kHz

void setup()
    cli();        //With this speed the interupteds occuar every 0.064s  
    TCCR1A = 0;   
    TCCR1B = 0;     
    OCR1A = 1000;
    TCCR1B |= (1 << WGM12);
    TCCR1B |= (1 << CS10);
    TCCR1B |= (1 << CS12);
    TIMSK1 |= (1 << OCIE1A);

The issue is that when I’m putting the reading part in ISR at this speed it doesnt show off in the monitor

    for(int x=0;x<16;x++){
      Serial.print(F(" bit ["));

But at the same time it works perfect in void loop()?. If I make the interrupteds faster it wont work ethier in void loop()…
Iam 100% sure it got something to do with the coding since at the same speed it wont show it in the monitor if the code is in ISR…

Don't print from an ISR. Printing uses ISRs, too, but interrupts are off while your ISR is running.

It's best to set a flag in the ISR for action to be performed in loop().


is there any instructions for how to do that?

newari: is there any instructions for how to do that?

"Flags" are just a conceptional use of variables:

int myFlag = 0;

if (something happened)
  myFlag = 1; // set flag


if (flag == 1) // flag is set
  // do something
  flag = 0; // clear the flag