Where should I declare a variable of type nvs_handle_t?

nossudak
Posts: 2
Joined: Wed Jul 31, 2019 2:29 am

Where should I declare a variable of type nvs_handle_t?

Postby nossudak » Sat May 30, 2020 11:25 am

Hi, folks! In my code I have this function. If the variable NVS_handle is declared inside this function the error " 'NVS_handle' is used uninitialized in this function" appears during building process. However if NVS_handle is declared globally everything works fine. Can you explain, why that happens? Also it is not clear, is it mandatory to use nvs_close() in the end? Thanks for any help.

Code: Select all

[Codebox=c file=Untitled.c]void update_NVS_data()
{// Write new data to NVS
        ESP_LOGI(TAG,"Updating feedrate value in NVS ... ");
        nvs_handle_t NVS_handle;
        esp_err_t err = nvs_set_i32(NVS_handle, "feed_rate", feed_rate);
        if (err != ESP_OK){
            ESP_LOGI(TAG,"Updating NVS failed!\n");
            ESP_LOGI(TAG,"Error code is %x\n", err);
        }
        ESP_LOGI(TAG,"Committing updates in NVS ... ");
        err = nvs_commit(NVS_handle);        // Commit written value.
        nvs_close(NVS_handle);// Close storage
}[/Codebox]

Who is online

Users browsing this forum: cdollar, MicroController, snutw_ and 149 guests