Skip to main content
Visitor II
July 31, 2019
Question

About the timer capture register.

  • July 31, 2019
  • 1 reply
  • 590 views

If you read the capture register like this

 uint16_t capch; 
 capch=*((uint16_t*)&TIM2_CCR3H);

This code will be compiled into an ldw instruction.The data is read incorrectly.

The following code gives the correct result.

 uint16_t capch; 
 ((uint8_t *)&capch)[0]=TIM2_CCR3H;
 ((uint8_t *)&capch)[1]=TIM2_CCR3L;

This means that the CCR has a shadow buffer register.

Could you tell me please, in what document about this said, thank you

    This topic has been closed for replies.

    1 reply

    Graduate II
    July 31, 2019

    CCR is constant until some capture happens. So a correct result is expected as long as no capture happens between the two reads. Try with the CNT register with no prescaler. Then you can see if some shadow buffer is involved.