to describe my problem, i share a short code with arduino here:
int index=0;
void setup()
{
Serial.begin(9600);
noInterrupts();
TCCR1A=0; // RESET
TCCR1B=0; //RESET
TCNT1=0;
TCCR1B |= (1<<CS12); // clk/256 prescaling
TCCR1B |=(1<<WGM12); // ctc mode
OCR1A= 6250; // 10 Hz
TIMSK1 |=(1<<OCIE1A);
interrupts();
}
ISR(TIMER1_COMPA_vect)
{
index++;
Serial.println(index);
}
void loop()
{
if (index == 100)
{
Serial.println("code's here");
noInterrupts();
}
}
output i expect:
1
2
3
...
...
100
code's here
output i get:
1
2
3
...
...
98
99
10
So my Serial.println("code's here")
is not working. i dont understand why. in fact nothing in my void loop works, while I code like this. what does this noInterrupts
do actually?
please give me an explanation. any help is appreciated.