Arduino 开发不传之秘: 读取MCU Device ID(设备ID)以及Signature(标识)

in #arduino8 years ago

在实际应用中,我们可能需要唯一的设备ID用于标识设备或者进行功能加密等操作。
Arduino中并未直接提供此类接口,那么是否可以实现此类功能呢?答案是肯定的。

在AVR的LIBC库中提供了以下定义(boot.h):

Read the Signature Row byte at address. For some MCU types, this function can
also retrieve the factory-stored oscillator calibration bytes.
Parameter address can be 0-0x1f as documented by the datasheet.
Note The values are MCU type dependent.

Datasheet中关于如何在软件中读取Signature的说明:

不同型号MCU的Device ID信息:

根据如上信息,写了个测试程序:
读取手头Arduino板的信息:

  • Arduino UNO R3 (1)

  • Arduino UNO R3 (2)

  • Arduino NANO

对于我们获取的Device ID以及文档中的说明,可知手头的两片Arduino UNO R3以及Arduino NANO 均采用ATMEGA328P.
那个RC Oscillator Calibration Byte没搞明白,先不理会啦。

可以明显看到这些数据分成几组,但是除了(Device ID)以及(Calibration Byte)没有从datasheet中找到其它部分对应的描述。
网上一些帖子说从第十四个字节(从0开始),后连续10个字节亦即MCU的唯一编码。

对程序稍作修改:

    #include "avr/boot.h"

    void setup() {
      Serial.begin(9600);
      Serial.println("Arduino MCU Signature Reader");
      Serial.println("By JoyTag, [email protected]\n");
    }

    void loop() {

      // 28.3 Signature Bytes
      Serial.print("Device ID:\t");
      Serial.print(boot_signature_byte_get(0), HEX);
      Serial.print("\t");
      Serial.print(boot_signature_byte_get(2), HEX);
      Serial.print("\t");
      Serial.print(boot_signature_byte_get(4), HEX);

      // 28.4 Calibration Byte
      Serial.print("\nCalibration Byte:\t");
      Serial.println(boot_signature_byte_get(1), HEX);

      //23.12.2.14 #define boot_signature_byte_get( addr )
      Serial.println("\nRow Bytes:");
      for (int i = 0; i <= 0x1F; i++)
      {
        Serial.print(boot_signature_byte_get(i), HEX);
        Serial.print(", ");
      }
      Serial.println("");


      Serial.println("\nUID Bytes:");
      for (int i = 14; i < 14 + 10; i++)
      {
        Serial.print(boot_signature_byte_get(i), HEX);
        Serial.print(", ");
      }
      Serial.println("");

      while (1);
    }

看来,利用这个方法读取唯一标识还是可行的。

参考资料

补充:
带水印的截图都是本人以前亲自做的,懒得把多个设备拿出来重新跑,直接用老图啦。
文章所述功能属于隐藏技能哦,我周围很多做产品的都不知道这个事那,免费大放送啦。

Sort:  

被老外搶了頭香> <

😄我把你点到他上边去,气死他

太感動了,O大週末快樂~

不大,😄同愉快

既然如此也顶顶我嘛

话说 arduino里面的传感器参数 可以直接指定吗?就是直接给模拟参数

没懂你说啥呢,具体点?😄

我这几天在家里把手机的加速度感应器弄成外接的 所以 固有此问。一解释 一下子暴露了 我完全不懂 电路板 呵呵。

😄 完了,完全暴露我不懂你在说什么?
我理解你是把加速度传感器外接,然后想返回一些虚假数据给手机,比如说计步之类?

如果不外接传感器你可以弄一组硬件,比如电机舵机,通过控制硬件晃手机,达到目的
如果能外接你要知道传感器和手机之间的通信协议,比如SPI之类的,然后你可以用类似arduino 这类硬件伪装成一个传感器,直接返回数据给手机

Nice, Thanks

This comment has received a 0.15 % upvote from @booster thanks to: @hamzaoui.

God!

不好意思,我想使用你的人头照,用来介绍给新人认识,可以吗?
参考如下
新手入门手册之 #cn 介绍华文区元老 Part2
https://steemit.com/cn/@incrediblesnow/cn-cny-part2

这玩意有点小复杂,还是 树莓PI 简单。
看到 while (1); 就想起了 8位的 NES 编程。
比如这篇我写的博文: https://helloacm.com/tutorial-7-c-programming-in-6502-colour-setting-for-nes/
最后也有一个 for (;;);

Good. Thanks. Upvoted. Resteemed.

it is very interesting

明明看了頭暈,還是要看完為止。為什麼我會看@oflyhigh的技術帖子呢?是不是因為我的工程背景的強迫症呢?

这是病,得治。😄
那个医生哪去了呢?😄

醫生在這兒!🙋‍♂️無牌行醫都是醫生嘛。

哪有自己醫自己的,我叫小嬸的搭檔來幫你吧!

妹紙你來醫就好了!

你確定不讓我呼叫D爸嗎? LOL

D爸是誰呀?我只要妹紙夠了

我是小護士~ ((舉手

快帮他打针吧

Very interesting @oflyhigh you really have a good knowledge in arduino. Sir can I have your help please? We have a project called automotive smoke emission analyzer and our problem is we don't know the proper codes to use can you help us with this sir?

Our materials used are:
Arduino Uno
DHT22
ESP8266 Wi-Fi Module
MQ-135 Gas Sensor
MQ-7 Gas Sensor
MQ131 Gas sensor

Can you help us sir?

What's your question?

We have our final project in Engineering this Semester. And it is an Automotive Exhaust Emission Analyzer using an Arduino, We're having trouble in making codes in Arduino. Can you help us with this one @oflyhigh?

Sorry, I am afraid I can't.
I am busy recently. 😄

Its okay sir I understand 🤗

this is for miners?

No, This's platform for IOT.

Welcome to steemit, happy to have you here
I comment to your post to follow me. and I will follow you

I am@istiaq69 , my real name istiaq ahmed:)
Checkout my blog posts, Enjoy your time here and let's get this party started :)