zoukankan      html  css  js  c++  java
  • ESP32-芯片与系统信息获取

    简介

      本节主要是对于Esp.h文件的理解,在该头文件中主要是实现了对内核中的RAM资源的管理、片外SPI RAM管理、获取芯片的基本信息、Flash管理。

     RAM资源的管理

      其中分为片内与片外RAM的管理。

        //Internal RAM
        uint32_t getHeapSize(); //total heap size 全部的片内内存大小
        uint32_t getFreeHeap(); //available heap  可以内存大小
        uint32_t getMinFreeHeap(); //lowest level of free heap since boot
        uint32_t getMaxAllocHeap(); //largest block of heap that can be allocated at once
    
        //SPI RAM 外设需要自己设计
        uint32_t getPsramSize();
        uint32_t getFreePsram();
        uint32_t getMinFreePsram();
        uint32_t getMaxAllocPsram();

    芯片的基本信息

      获取芯片基本信息,包括了芯片的id物理地址、版本、运行频率等

        uint8_t getChipRevision();
        uint32_t getCpuFreqMHz(){ return getCpuFrequencyMhz(); }
        inline uint32_t getCycleCount() __attribute__((always_inline));
        const char * getSdkVersion();     
        uint64_t getEfuseMac();

       例子:

     1 #include <Arduino.h>
     2 
     3 void setup()
     4 {
     5   Serial.begin(9600);
     6   Serial.println("");
     7 }
     8 
     9 uint64_t chipid;  
    10 
    11 void loop()
    12 {
    13   chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
    14   Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes
    15   Serial.printf("%08X
    ",(uint32_t)chipid);//print Low 4bytes. 
    16 
    17   Serial.printf("total heap size = %u
    ",ESP.getHeapSize());
    18   Serial.printf("available heap = %u
    ",ESP.getFreeHeap());
    19   Serial.printf("lowest level of free heap since boot = %u
    ",ESP.getMinFreeHeap());
    20   Serial.printf("largest block of heap that can be allocated at once = %u
    ",ESP.getMaxAllocHeap());
    21 
    22   Serial.printf("total Psram size = %u
    ",ESP.getPsramSize());
    23   Serial.printf("available Psram = %u
    ",ESP.getFreePsram());
    24   Serial.printf("lowest level of free Psram since boot = %u
    ",ESP.getMinFreePsram());
    25   Serial.printf("largest block of Psram that can be allocated at once = %u
    ",ESP.getMinFreePsram());
    26 
    27   Serial.printf("get Chip Revision = %u
    ",ESP.getChipRevision());
    28   Serial.printf("getCpuFreqMHz = %u
    ",ESP.getCpuFreqMHz());
    29   Serial.printf("get Cycle Count = %u
    ",ESP.getCycleCount());
    30   Serial.printf("get SdkVersion = %s
    ",ESP.getSdkVersion());
    31   
    32   delay(5000);
    33 }

    睡眠模式

    void deepSleep(uint32_t time_us);

      调用后进入深度睡眠模式,深度睡眠时间过后,设备会自动醒来,在醒来时,设备调用深睡眠唤醒存根,然后继续加载应用程序。

      调用这个函数相当于调用esp_deep_sleep_enable_timer_wakeup,然后调用esp_deep_sleep_start。

      esp_deep_sleep不会优雅地关闭WiFi、BT和更高级别的协议连接。确保调用了相关的WiFi和BT栈函数来关闭任何连接,并对外设进行初始化。这些包括:esp_bluedroid_disable、esp_bt_controller_disable、esp_wifi_stop

      此函数不返回。time_us:深度睡眠时间,单位:微秒

      这是极为简单的睡眠调用,且只能是定时唤醒。后面将仔细研究ESP32的各种睡眠与唤醒:链接

     1 #include <Arduino.h>
     2 
     3 void setup(){
     4   Serial.begin(9600);
     5   delay(1000); 
     6   Serial.println("Going to sleep now
    ");
     7   ESP.deepSleep(5000000); // 注时间意单位为:us
     8   Serial.println("This will never be printed
    "); 
     9 }
    10 
    11 void loop(){
    12   // 这里不会调用
    13 }
  • 相关阅读:
    如何让pc端网站在手机上可以等比缩放的整个显示
    CSS
    常见的IE布局兼容问题
    CSS : 使用 z-index 的前提
    CSS : object-fit 和 object-position实现 图片或视频自适应
    CSS
    vscode
    如何识别Form字段中一对多或者多对多字段
    window.open简单使用
    由一个模型拿它的名字、app的名字、字段对象以及字段对象中的属性
  • 原文地址:https://www.cnblogs.com/zy-cnblogs/p/13295736.html
Copyright © 2011-2022 走看看