cancel
Showing results for 
Search instead for 
Did you mean: 

How to print unsigned int always positive

LMI2
Lead
Posted on September 06, 2016 at 18:47

This is more of a C problem than Arm problem, here too are some people who know their C.

I am reading the value of DWT_CYCCNT; When print it via Uart, after a while it becomes negative. The most signicant bit becomes 1, but how to tell it to the compiler that it is not a sign.

//the declaration 
char
klaa[40];
//the code
while
(1)
{
kellopulshit = *DWT_CYCCNT;
sprintf
(klaa,
''Clock pulses %d \n''
, kellopulshit);
c=
strlen
(klaa);
HAL_UART_Transmit(&huart2,(uint8_t *) klaa,c,1000);

3 REPLIES 3
christoph2399
Associate II
Posted on September 06, 2016 at 19:08

whats the type of

kellopulshit

try %u for unsigned int
LMI2
Lead
Posted on September 06, 2016 at 19:28

It is unsigned int

I'll try the %u a bit later. At least it didn't give an error

LMI2
Lead
Posted on September 06, 2016 at 19:45

It works, thanks.