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

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

MicroController
Posts: 2663
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: 2663
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: Baidu [Spider], ChatGPT-User, Qwantbot and 2 guests