Printing 32 bit data using ESP_LOG or printf

khu8rt
Posts: 9
Joined: Sun Aug 21, 2022 10:42 pm

Printing 32 bit data using ESP_LOG or printf

Postby khu8rt » Sun May 21, 2023 1:35 pm

I am reading a data from a device, the data is 32bit long and i want to print it using ESP_LOG.
Here is my code
  1. void app_main(void)
  2. {
  3.     esp_err_t ret = nvs_flash_init();
  4.     if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  5.       ESP_ERROR_CHECK(nvs_flash_erase());
  6.       ret = nvs_flash_init();
  7.     }
  8.     ESP_ERROR_CHECK(ret);
  9.     ESP_LOGI(TAG, "Starting up!");
  10.     //vSetGPIOlevel(GPIO_NUM_18,1);
  11.     //vSetGPIOlevel(GPIO_NUM_19,1);
  12.     spi_transaction_t spitHandler =  init_spi();
  13.     while(1){
  14.         sleep(1);
  15.  
  16.         uint32_t dataOut = readEMregister(0xc001,spitHandler );
  17.  
  18.         ESP_LOGI(TAG, "Register is %04X " ,dataOut );
  19.  
  20.     }
  21. }
It gives an error that "format '%X' expects argument of type 'unsigned int', but argument 6 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]"

How can i print it correctly, i dont want to split it and then print

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Printing 32 bit data using ESP_LOG or printf

Postby MicroController » Sun May 21, 2023 4:51 pm

Try "%Xl", or "%" PRIx32

khu8rt
Posts: 9
Joined: Sun Aug 21, 2022 10:42 pm

Re: Printing 32 bit data using ESP_LOG or printf

Postby khu8rt » Mon May 22, 2023 12:35 pm

Thanks for the hint. %lx works!

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Printing 32 bit data using ESP_LOG or printf

Postby MicroController » Mon May 22, 2023 6:26 pm

Great.
Sorry about the mixup :)

Who is online

Users browsing this forum: Google [Bot] and 115 guests