This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52840 uint64_t problem

I have one problem with unsing uint64_t in application...

Im for test try simple demo:

uint64_t test = 1327644190303473294;
NRF_LOG_INFO("test: %"PRIX64"\n", test);

But I receive in RTT Viewer output:

 0> APP:INFO:test: 0

What Im doing wrong? Thanks for any help :)

  • What do you expect to see?

    I am not a printf formatting expert, but perhaps you instead want

    NRF_LOG_INFO("test: %llu\n", test);
    

    For an 'unsigned long long'. Also check your library settings to see if you have support for long longs. I know it can be turned off to save space for some toolchains.

  • Something still doesn't work ok:

    uint64_t test = 7340861779410949837;
    NRF_LOG_INFO("test: %llu\n", test);
    NRF_LOG_FLUSH();
    

    Produce:

     0> APP:INFO:test: 47549582942412
    

    I will check project settings...

    P.S. If I disable MicroLib I get:

    0> APP:INFO:test: 319297229
    

    This is if I convert uint64 to 2xuint32 by calculator on pc one of int32 ...

    If I change Optimization from Level 3 to Level 0 result is same...

  • Do you need this number in decimal ?

    You could split into 2 blocks of uint32_t hex and display them side by side to make it look like 64 bits worth of hex

  • No char array is also ok. Im also found that NRF_LOG_INFO doesn't work witn char array(strings) ... Example:

    uint32_t info_variant = NRF_FICR->INFO.VARIANT;
    
    unsigned char buffer[5];
    buffer[0] = info_variant >> 24;
    buffer[1] = info_variant >> 16;
    buffer[2] = info_variant >> 8;
    buffer[3] = info_variant;  
    buffer[4] = '\0';
    
    NRF_LOG_INFO("string: %s \n", buffer);
    SEGGER_RTT_printf(0, "string: %s \n", buffer);
    NRF_LOG_FLUSH();
    

    SEGGER_RTT_printf function print AAAA which is OK. But If I try use NRF_LOG_INFO building produce error.

  • Im figure out this last problem...

    uint32_t info_variant = NRF_FICR->INFO.VARIANT;
    	
    char buffer[5];
    buffer[0] = info_variant >> 24;
    buffer[1] = info_variant >> 16;
    buffer[2] = info_variant >> 8;
    buffer[3] = info_variant;  
    buffer[4] = '\0';
    	
     
    NRF_LOG_INFO("string: %s \n", nrf_log_push(buffer));
    NRF_LOG_FLUSH();