|
本帖最后由 xvanzhou 于 2016-11-14 17:21 编辑
我现在在尝试让ENC28J60 与RC522 同时使用,用SPI模式。但是始终不成功,只有RC522运行,web一直刷不出来。分开来是都是正常运行的。
源程序如下,RFID片选为4,enc28J60片选为10;
- #include <EtherCard.h>
- #include <SPI.h>
- #include <MFRC522.h>
- #define SS_PIN 4
- #define RST_PIN 9
- static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
- static byte myip[] = { 192,168,150,203 };
- byte Ethernet::buffer[500];
- BufferFiller bfill;
- MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
- MFRC522::MIFARE_Key key;
- // Init array that will store new NUID
- byte nuidPICC[3];
- void setup () {
- if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0)
- Serial.println(F("Failed to access Ethernet controller"));
- ether.staticSetup(myip);
-
- Serial.begin(9600);
- SPI.begin(); // Init SPI bus
- rfid.PCD_Init(); // Init MFRC522
- for (byte i = 0; i < 6; i++) {
- key.keyByte[i] = 0xFF;
-
- Serial.println(F("This code scan the MIFARE Classsic NUID."));
- Serial.print(F("Using the following key:"));
- printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
- }
- pinMode (SS_PIN,OUTPUT);
- digitalWrite (SS_PIN,HIGH);
- pinMode (10,OUTPUT);
- digitalWrite (10,HIGH);
- }
- static word homePage() {
- long t = millis() / 1000;
- word h = t / 3600;
- byte m = (t / 60) % 60;
- byte s = t % 60;
- bfill = ether.tcpOffset();
- bfill.emit_p(PSTR(
- "HTTP/1.0 200 OK\r\n"
- "Content-Type: text/html\r\n"
- "Pragma: no-cache\r\n"
- "\r\n"
- "<meta http-equiv='refresh' content='1'/>"
- "<title>RBBB server</title>"
- "<h1>$D$D:$D$D:$D$D</h1>"),
- h/10, h%10, m/10, m%10, s/10, s%10);
- return bfill.position();
-
- }
-
- void loop () {
-
- digitalWrite (10,LOW);
- digitalWrite (SS_PIN,HIGH);
- word len = ether.packetReceive();
- word pos = ether.packetLoop(len);
-
- if (pos) // check if valid tcp data is received
- ether.httpServerReply(homePage()); // send web page data
-
- delay (100);
- //RFID部分
- digitalWrite (10,HIGH);
- digitalWrite (SS_PIN,LOW);
- // Look for new cards
- if ( ! rfid.PICC_IsNewCardPresent())
- return;
- // Verify if the NUID has been readed
- if ( ! rfid.PICC_ReadCardSerial()) //先查到这里的库函数1
- return;
- Serial.print(F("PICC type: "));
- MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
- Serial.println(rfid.PICC_GetTypeName(piccType));
- // Check is the PICC of Classic MIFARE type
- if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
- piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
- piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
- Serial.println(F("Your tag is not of type MIFARE Classic."));
- return;
- }
- if (rfid.uid.uidByte[0] != nuidPICC[0] ||
- rfid.uid.uidByte[1] != nuidPICC[1] ||
- rfid.uid.uidByte[2] != nuidPICC[2] ||
- rfid.uid.uidByte[3] != nuidPICC[3] ) {
- Serial.println(F("A new card has been detected."));
- // Store NUID into nuidPICC array
- for (byte i = 0; i < 4; i++) {
- nuidPICC[i] = rfid.uid.uidByte[i];
-
- delay (100);
- }
-
-
- Serial.println(F("The NUID tag is:"));
- Serial.print(F("In hex: "));
- printHex(rfid.uid.uidByte, rfid.uid.size);
- Serial.println();
- Serial.print(F("In dec: "));
- printDec(rfid.uid.uidByte, rfid.uid.size);
- Serial.println();
- }
- else Serial.println(F("Card read previously."));
- // Halt PICC
- rfid.PICC_HaltA();
- delay (100);
- // Stop encryption on PCD
- rfid.PCD_StopCrypto1();
- delay (100);
- }
- /**
- * Helper routine to dump a byte array as hex values to Serial.
- */
- void printHex(byte *buffer, byte bufferSize) {
- for (byte i = 0; i < bufferSize; i++) {
- Serial.print(buffer[i] < 0x10 ? " 0" : " ");
- Serial.print(buffer[i], HEX);
- delay (100);
- }
- }
- /**
- * Helper routine to dump a byte array as dec values to Serial.
- */
- void printDec(byte *buffer, byte bufferSize) {
- for (byte i = 0; i < bufferSize; i++) {
- Serial.print(buffer[i] < 0x10 ? " 0" : " ");
- Serial.print(buffer[i], DEC);
- delay (100);
- }
- }
复制代码
如上,确实已经片选置高置低了,怕是因为buffer的原因,也用了delay,但是还是没法同时运行。具体是什么情况?怎么解决,可QQ私聊,酬谢
QQ:305515099 困扰我很久了 真心烦死
今天再来试,发现我ping地址192.168.150.177 结果是192.168.150.180(主机地址)给我回复无法访问,这是个什么道理?如图3
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|