{"id":466,"date":"2024-12-26T00:39:11","date_gmt":"2024-12-25T16:39:11","guid":{"rendered":"https:\/\/yhsbj.cn\/?p=466"},"modified":"2024-12-26T00:42:21","modified_gmt":"2024-12-25T16:42:21","slug":"%e5%8d%95%e7%89%87%e6%9c%baesp32-s3rfid-rc522%e8%af%bb%e5%86%99%e6%a0%87%e7%ad%be","status":"publish","type":"post","link":"https:\/\/yhsbj.cn\/index.php\/2024\/12\/26\/466\/","title":{"rendered":"\u5355\u7247\u673aesp32 s3+RFID RC522\u8bfb\u5199\u6807\u7b7e"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/FF39E1A5755372009DC5547C5E02909A-968x1024.jpg\" alt=\"\" class=\"wp-image-467\" width=\"658\" height=\"695\" srcset=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/FF39E1A5755372009DC5547C5E02909A-968x1024.jpg 968w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/FF39E1A5755372009DC5547C5E02909A-284x300.jpg 284w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/FF39E1A5755372009DC5547C5E02909A-768x812.jpg 768w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/FF39E1A5755372009DC5547C5E02909A-1452x1536.jpg 1452w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/FF39E1A5755372009DC5547C5E02909A-1936x2048.jpg 1936w\" sizes=\"(max-width: 658px) 100vw, 658px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/IMG_5827-1024x768.jpg\" alt=\"\" class=\"wp-image-468\" width=\"839\" height=\"629\" srcset=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/IMG_5827-1024x768.jpg 1024w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/IMG_5827-300x225.jpg 300w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/IMG_5827-768x576.jpg 768w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/IMG_5827-1536x1152.jpg 1536w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/IMG_5827-2048x1536.jpg 2048w\" sizes=\"(max-width: 839px) 100vw, 839px\" \/><\/figure>\n\n\n\n<p><strong>Esp32 S3\u63a5\u7ebf\uff1a<\/strong><\/p>\n\n\n\n<p>RDID-RC522\u7684SDA  ->   esp32-s3\u7684\u5f15\u811a10<\/p>\n\n\n\n<p>RDID-RC522\u7684SCK -> esp32-s3\u7684\u5f15\u811a12<\/p>\n\n\n\n<p>RDID-RC522\u7684MOSI -> esp32-s3\u7684\u5f15\u811a11<\/p>\n\n\n\n<p>RDID-RC522\u7684MISO -> esp32-s3\u7684\u5f15\u811a13<\/p>\n\n\n\n<p>RDID-RC522\u7684GUN -> esp32-s3\u7684\u5f15\u811aGUN<\/p>\n\n\n\n<p>RDID-RC522\u7684RST -> esp32-s3\u7684\u5f15\u811a46<\/p>\n\n\n\n<p>RDID-RC522\u76843.3V -> esp32-s3\u7684\u5f15\u811a3.3V<\/p>\n\n\n\n<p><strong>\u5355\u7247\u673aesp32\u4ee3\u7801\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;MFRC522.h>\n#include &lt;SPI.h>\n\n#define SS_PIN 10     \/\/SDA\u5f15\u811a\n#define RST_PIN 46    \/\/RST\uff08\u590d\u4f4d\u4fe1\u53f7\uff09, \u4efb\u610f\u4e00\u4e2a\u53ef\u7528\u7684\u5f15\u811a\u5373\u53ef\n#define SCK_PIN 12    \/\/SCK\uff08\u65f6\u949f\u63a5\u53e3\uff09\n#define MOSI_PIN 11   \/\/MOSI\uff08SPI \u63a5\u53e3\u4e3b\u51fa\u4ece\u5165\uff09\n#define MISO_PIN 13   \/\/MISO\uff08SPI \u63a5\u53e3\u4e3b\u5165\u4ece\u51fa\uff09\n\nMFRC522 mfrc522(SS_PIN, RST_PIN);\nMFRC522::MIFARE_Key key;\n\nvoid setup() {\n  Serial.begin(115200);                             \/\/\u5f00\u542f\u4e32\u53e3\u6253\u5370\u4fe1\u606f\n  while (!Serial);                                  \/\/\u7b49\u5f85\u4e32\u53e3\u6253\u5f00\n  SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, SS_PIN);   \/\/\u5f00\u542fSPI\u603b\u7ebf\u901a\u4fe1\n  mfrc522.PCD_Init();                               \/\/\u521d\u59cb\u5316MFRC522\u6a21\u5757\n  \/\/\u8bbe\u7f6e\u5bc6\u94a5\u5168\u90e8\u4e3a0xFF\uff0c\u5361\u7247\u9ed8\u8ba4\u5168\u90e8\u662f0xFF\n  for (byte i = 0; i &lt; 6; i++) {\n    key.keyByte[i] = 0xFF;\n  }\n}\n\nvoid loop() {\n  \/\/\u7b49\u5f85\u4e32\u53e3\u53d1\u9001\u6d88\u606f\n  if (Serial.available() > 0) {\n    \/\/\u8bfb\u53d6\u4e00\u4e2a\u5b57\u8282\n    int command = Serial.read();\n    \/\/\u68c0\u6d4b\u662f\u5426\u6709\u5361\u5e76\u4e14\u8bfb\u53d6\u5361\u7247\n    if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {\n      Serial.println(\"no card!\");\n      return;\n    }\n    \/\/\u6253\u5370\u5361\u7684UID\n    Serial.print(F(\"Card UID:\"));\n    dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);\n    Serial.println();\n    \/\/\u6253\u5370\u5361\u7684\u7c7b\u578b\n    MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);\n    Serial.println(mfrc522.PICC_GetTypeName(piccType));\n    \/\/\u5224\u65ad\u517c\u5bb9\u6027\n    if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI\n        &amp;&amp; piccType != MFRC522::PICC_TYPE_MIFARE_1K\n        &amp;&amp; piccType != MFRC522::PICC_TYPE_MIFARE_4K) {\n      Serial.println(F(\"This sample only works with MIFARE Classic cards.\"));\n      return;\n    }\n    \/\/\u8bfb\u53d6\u7b2c\u56db\u4e2a\u5757\u7684\u6570\u636e\uff0c\u6bcf\u4e2a\u6247\u533a\u7531 4 \u4e2a\u6570\u636e\u5757 \u7ec4\u6210\n    byte blockAddr = 4;\n    \/\/\u8ba4\u8bc1\u7b2c\u56db\u4e2a\u6570\u636e\u5757\n    byte trailerBlock = 4;\n    MFRC522::StatusCode status;\n    \/\/\u4fdd\u5b58\u8bfb\u53d6\u7684\u6570\u636e\n    byte buffer[18];\n    byte size = sizeof(buffer);\n    \/\/\u5199\u5165\u7684\u6570\u636e\n    byte dataBlock[] = {\n      0x01, 0x02, 0x03, 0x04,  \/\/  1,  2,   3,  4,\n      0x05, 0x06, 0x07, 0x08,  \/\/  5,  6,   7,  8,\n      0x09, 0x0a, 0xff, 0x0b,  \/\/  9, 10, 255, 11,\n      0x0c, 0x0d, 0x0e, 0x0f   \/\/ 12, 13, 14, 15\n    };\n    \/\/\u8ba4\u8bc1Key A\n    status = (MFRC522::StatusCode)mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &amp;key, &amp;(mfrc522.uid));\n    if (status != MFRC522::STATUS_OK) {\n      Serial.print(F(\"PCD_Authenticate() failed(A): \"));\n      Serial.println(mfrc522.GetStatusCodeName(status));\n      return;\n    }\n    \/\/\u8bfb\u53d6\u6570\u636e\u5e93\n    status = (MFRC522::StatusCode)mfrc522.MIFARE_Read(blockAddr, buffer, &amp;size);\n    if (status != MFRC522::STATUS_OK) {\n      Serial.print(F(\"MIFARE_Read() failed: \"));\n      Serial.println(mfrc522.GetStatusCodeName(status));\n    }\n    Serial.print(F(\"Read Data in block :\"));\n    dump_byte_array(buffer, 16);\n    Serial.println();\n    \/\/\u8ba4\u8bc1Key B\n    status = (MFRC522::StatusCode)mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, trailerBlock, &amp;key, &amp;(mfrc522.uid));\n    if (status != MFRC522::STATUS_OK) {\n      Serial.print(F(\"PCD_Authenticate() failed: \"));\n      Serial.println(mfrc522.GetStatusCodeName(status));\n      return;\n    }\n\n    \/\/\u6253\u5370\u5199\u5165\u6570\u636e\n    Serial.print(F(\"Write Data in block :\"));\n    dump_byte_array(dataBlock, 16);\n    Serial.println();\n    \/\/\u5199\u5165\u6570\u636e\n    status = (MFRC522::StatusCode)mfrc522.MIFARE_Write(blockAddr, dataBlock, 16);\n    if (status != MFRC522::STATUS_OK) {\n      Serial.print(F(\"MIFARE_Write() failed: \"));\n      Serial.println(mfrc522.GetStatusCodeName(status));\n    }\n    \/\/\u505c\u6b62\u5361\u7247\u901a\u4fe1\n    mfrc522.PICC_HaltA();\n    \/\/\u505c\u6b62\u5361\u7247\u52a0\u5bc6\u901a\u4fe1\n    mfrc522.PCD_StopCrypto1();\n  }\n}\n\n\/\/\u6253\u5370\u6570\u636e\nvoid dump_byte_array(byte* buffer, byte bufferSize) {\n  for (byte i = 0; i &lt; bufferSize; i++) {\n    Serial.print(buffer[i] &lt; 0x10 ? \" 0\" : \" \");\n    Serial.print(buffer[i], HEX);\n  }\n}<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/QQ\u622a\u56fe20241226004109.png\" alt=\"\" class=\"wp-image-470\" width=\"429\" height=\"369\" srcset=\"https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/QQ\u622a\u56fe20241226004109.png 997w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/QQ\u622a\u56fe20241226004109-300x258.png 300w, https:\/\/yhsbj.cn\/wp-content\/uploads\/2024\/12\/QQ\u622a\u56fe20241226004109-768x662.png 768w\" sizes=\"(max-width: 429px) 100vw, 429px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Esp32 S3\u63a5\u7ebf\uff1a RDID-RC522\u7684SDA -> esp32-s3\u7684\u5f15\u811a10 RDID-RC522\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[58],"tags":[59,64],"_links":{"self":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts\/466"}],"collection":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/comments?post=466"}],"version-history":[{"count":5,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts\/466\/revisions"}],"predecessor-version":[{"id":474,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/posts\/466\/revisions\/474"}],"wp:attachment":[{"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/media?parent=466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/categories?post=466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yhsbj.cn\/index.php\/wp-json\/wp\/v2\/tags?post=466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}