Page 1 of 1

Printing 32 bit data using ESP_LOG or printf

Posted: Sun May 21, 2023 1:35 pm
by khu8rt
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

Code: Untitled.cpp Select all


void app_main(void)
{
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
ESP_LOGI(TAG, "Starting up!");
//vSetGPIOlevel(GPIO_NUM_18,1);
//vSetGPIOlevel(GPIO_NUM_19,1);
spi_transaction_t spitHandler = init_spi();
while(1){
sleep(1);

uint32_t dataOut = readEMregister(0xc001,spitHandler );

ESP_LOGI(TAG, "Register is %04X " ,dataOut );

}
}
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

Re: Printing 32 bit data using ESP_LOG or printf

Posted: Sun May 21, 2023 4:51 pm
by MicroController
Try "%Xl", or "%" PRIx32

Re: Printing 32 bit data using ESP_LOG or printf

Posted: Mon May 22, 2023 12:35 pm
by khu8rt
Thanks for the hint. %lx works!

Re: Printing 32 bit data using ESP_LOG or printf

Posted: Mon May 22, 2023 6:26 pm
by MicroController
Great.
Sorry about the mixup :)