Issue with Timer2 in CTC mode on the arduino uno board

Hi everyone,

First, sorry for my english, it's not my maternal langage ;).

I try to configure the Timer2 of the atmega328 microcontroler in CTC mode.
For this, I defined the OCR2A register but, at the execution of the above code, I always get
the same values on my counter when I print it on the Serial port (in the loop statement). Normaly,
more the value of OCR2A is lower, more the value of my counter should be greater. Also, I tried many prescalers, same problem.

Here my code :

static volatile  unsigned long timerr = 0;
void setup() {
  Serial.begin(9600);
  
  //timer2 setup
  OCR2A = 255; // <-- if i change this value, the timerr values are always the same at the execution
 TCCR2A = 0;
 TCCR2B = 0;
 TCNT2 = 0;
 TCCR2A |= (1 << WGM21); // Configure timer 2 for CTC mode 
 TIMSK2 |= (1 << OCIE2A);

 TCCR2B |= (1 << CS22) | (1 << CS21) | (1 << CS20); //1024 prescaler
 
 sei(); 

  timerr=0;
}     

void loop() {
 
delay(4000);
  Serial.println(timerr); // <-- produce always the same values
  
}

ISR (TIMER2_COMPA_vect)
{    
    timerr += 1;    
}

Can you explain that ?

Thanks in advance.

Solved from an other forum :

This code with a different style works :

void setup()
{
Serial.begin(9600);
TCCR2A = (1 << WGM21); // CTC
TCCR2B = (7 << CS20); //div 1024
OCR2A = 255;
TIMSK2 |= (1 << OCIE2A);
}

But the reason for the first version of the code who didn't work had not been found