3 years, 6 months ago.

How can I cast a 32-bit hardware timer to a uint32_t variable


I want to read one of the hardware 32-bit timer numbers (in the LPC1768) as an unsigned integer. The compiler seems to think it is 32-bit signed. For example

. . printf("%d", (uint32_t) LPC_TIM1->TC); . . In this code, the value printed is a negative number if the counter has gone over its first half.


Comment on this question

1 Answer

3 years, 6 months ago.

Please try "%u" instead of "%d" in printf format string. I think this will work ;)

You need to log in to post a question