8 years, 1 month ago.

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

Hi,

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.

Jim

1 Answer

8 years, 1 month ago.

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