<p><iframe name="ifd" src="https://mnifdv.cn/resource/cnblogs/LearnESP32" frameborder="0" scrolling="auto" width="100%" height="1500"></iframe></p>
<iframe frameborder="0" height="1500" name="ifd" scrolling="auto" src="https://mnifdv.cn/resource/cnblogs/LearnESP32" width="100%"></iframe>
#include <stdio.h> #include <string.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/queue.h" #include "freertos/event_groups.h" #include "esp_system.h" #include "nvs_flash.h" #include "esp_log.h" void app_main(void) { //初始化 NVS esp_err_t err = nvs_flash_init(); if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } ESP_ERROR_CHECK(err); /*操作nvs时用的句柄*/ nvs_handle_t my_handle; /*打开*/ //操作的表格名字 //以读写模式打开 err = nvs_open("storage", NVS_READWRITE, &my_handle); /*写*/ err = nvs_set_i32(my_handle, "test", 111); /*提交*/ err = nvs_commit(my_handle); int32_t test_value; /*读*/ err = nvs_get_i32(my_handle, "test", &test_value); printf("test_value = %d\n", test_value); /*关闭*/ nvs_close(my_handle); }