Access to timer TCNT3 on YUN board

Hello,

I try to read timer TCNT3 value (16bits) using direct acces to timer registers (TCNT3L & TCNT3H with 8bits access (First read to TCNT3L 0x0094 and after to TCNT3H 0x0095) on YUN board (timer inside ATMEGA32U4).

But even if this timer is 16bits wide I read always 0x00 for TCNT3H ???

My sketch does only this task, I have disabled interrupt during reading to both registers but I never see high Bytes changung!!!

Others associated topic:
I believe that TCNT3L and TCNT3H addresses are define inside files *.h but when I want use them, sketch compiles but the value change at each compilation ???
So Ibelieve the "Constant" are not define but I don't get an error at compilation! If I use other register address undefined (i.e UBRR1H) in this case I get an error!

Thanks for your help.

Your sketch seems to got lost during posting.
You can directly access TCNT3, the compiler will do the correct code to read the registers.

hi, Here this is my sketch:

// put your setup code here, to run once:

volatile uint8_t *ptrTIMER = 0x0094;// Value used to address Timer TCNT3 

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.print("ptrTIMER point to address 0x");
  Serial.println((uint32_t) ptrTIMER, HEX);

  uint8_t *pointeurOctet1 = (uint8_t*) ptrTIMER; // pointeurOctet adress one Byte, read access byte per byte

  // First value read 
  Serial.print("Byte0 (TCNT3L) address 0x");
  Serial.print((uint8_t) pointeurOctet1, HEX);
  Serial.print(" est 0x");
  Serial.println(*pointeurOctet1, HEX);
  
  // Second Byte read
  Serial.print("Byte1 (TCNT3H) address 0x");
  Serial.print((uint8_t) (pointeurOctet1 + 1), HEX);
  Serial.print(" est 0x");
  Serial.println(*(pointeurOctet1 + 1), HEX);
  
  Serial.println();

  int i;
  uint8_t ValTimerH;
  uint8_t ValTimerL;
  
  for (i=0;i<4;i++) {

  noInterrupts();
  ValTimerL = *pointeurOctet1;
  ValTimerH = *(pointeurOctet1+1);
  interrupts();
  
  Serial.print("Byte0 at address 0x");
  Serial.print((uint8_t) pointeurOctet1, HEX);
  Serial.print(" est 0x");
  Serial.print(ValTimerL, HEX); 
  Serial.print(" Byte1 at address 0x");
  Serial.print((uint8_t) pointeurOctet1+1, HEX);
  Serial.print(" est 0x");
  Serial.print(ValTimerH, HEX); 
  Serial.println(" ");
    
  }

  Serial.println(" ");

  volatile uint8_t *ptrTCNT3L = TCNT3L;
  volatile uint8_t *ptrTCNT3H = TCNT3H;

  Serial.println("Values of the pre-declared timer register address : ");
  Serial.print("TCNT3L @0x");
  Serial.print((uint32_t) TCNT3L, HEX);
  Serial.print(" TCNT3H @0x");
  Serial.println((uint32_t) TCNT3H, HEX);
  Serial.print("TCNT3L @0x");
  Serial.print((uint32_t) TCNT3L, HEX);
  Serial.print(" TCNT3H @0x");
  Serial.println((uint32_t) TCNT3H, HEX);

  Serial.println();

  Serial.print("Value pointed by ptrTCNT3L  @0x");
  Serial.print((uint16_t) ptrTCNT3L, HEX);
  Serial.print(" 0x");
  Serial.println((uint8_t) *ptrTCNT3L, HEX); 
  
  Serial.print("Value pointed by ptrTCNT3H  @0x");
  Serial.print((uint16_t) ptrTCNT3H, HEX);
  Serial.print(" 0x");
  Serial.println((uint8_t) *ptrTCNT3H, HEX);

  Serial.println();

}

void loop() {
  // put your main code here, to run repeatedly:

}

Don't do such stuff. The development environment comes with all defines you need, let the compiler do the low level stuff, it won't make the mistakes you did.

It's that easy:

uint16_t counter_value = TCNT3;

Hi Pylon,

Thanks for your help, all is fine now!

I have learned something today, great day! :slight_smile:

Regards

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.