GetChipID

はじめに

ESP32のチップIDを取得し、シリアルコンソールに表示します。本来のチップIDは、MACアドレスですが、ESP8266のESP.getChipId()が出力するチップIDを出力します。

プログラム

定義等

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
/* The true ESP32 chip ID is essentially its MAC address.
This sketch provides an alternate chip ID that matches 
the output of the ESP.getChipId() function on ESP8266 
(i.e. a 32-bit integer matching the last 3 bytes of 
the MAC address. This is less unique than the 
MAC address chip ID, but is helpful when you need 
an identifier that can be no more than a 32-bit integer 
(like for switch...case).

created 2020-06-07 by cweinhofer
with help from Cicicok */
	
uint32_t chipId = 0;
 

チップIDを格納するための変数を定義します。

setup()

15
16
17
18
void setup() {
	Serial.begin(115200);
}
 

シリアルコンソールの設定を行います。

loop()

19
20
21
22
23
24
25
26
27
28
29
30
void loop() {
	for(int i=0; i<17; i=i+8) {
	  chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
	}

	Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision());
	Serial.printf("This chip has %d cores\n", ESP.getChipCores());
  Serial.print("Chip ID: "); Serial.println(chipId);
  
	delay(3000);

}

EspClass::getEfuseMac()で、MACアドレス(chipId)を取得します。ESPというのは、事前に定義されているEspClassのオブジェクトです。

67行目のループで、48ビットあるマックアドレスから、24ビット分の情報を取り出します。

  1. chipId |= ((ESP.getEfuseMac() >> 40 & 0xff) << 0;
  2. chipId |= ((ESP.getEfuseMac() >> 32 & 0xff) << 8;
  3. chipId |= ((ESP.getEfuseMac() >> 24 & 0xff) << 16;

EspClass::getChipModel()は、チップモデル(ESP32-D0WDQ6など)を取得する関数です。EspClass::getChipRevision()は、チップのリビジョンを取得する関数です。EspClass::getChipCores()は、チップのコア数を取得する館数です。

バージョン

Hardware:ESP-WROOM-32
Software:Arduino core for the ESP32 2.0.4

最終更新日

September 4, 2022

inserted by FC2 system