2016-09-24 4 views
0

임피던스 버스에서 ILI9341 디스플레이 320 * 240 및 PN532 RFID 리더를 사용하여 ESP12-E 모듈과 인터페이스하려고합니다. SS 핀을 다른 GPIO에 할당했습니다.다중 슬레이브 SPI on ESP8266 - PN532 및 ILI9341

Im는 둘 다 통신 할 수 없습니다. 디스플레이는 어떤 조건에서도 완벽하게 작동합니다. 그러나 ILI9341과 통신하면 PN532는 작동을 멈추고 다시 초기화하더라도 장치를 다시 시작할 때까지 응답하지 않습니다.

어떤 도움은 매우 내 코드 주시면 감사하겠습니다 :

#include <Wire.h> 
#include <SPI.h> 
#include <Adafruit_PN532.h> 
#include <UTFT.h> 
UTFT lcd(ILI9341_S5P,15,D1,D3); 

// If using the breakout with SPI, define the pins for SPI communication. 
#define PN532_SS (D4) 
#define PN532_SCK (D5) 
#define PN532_MOSI (D7) 
#define PN532_MISO (D6) 

// If using the breakout or shield with I2C, define just the pins connected 
// to the IRQ and reset lines. Use the values below (2, 3) for the shield! 
#define PN532_IRQ (2) 
#define PN532_RESET (3) // Not connected by default on the NFC Shield 

// Uncomment just _one_ line below depending on how your breakout or shield 
// is connected to the Arduino: 

// Use this line for a breakout with a SPI connection: 
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS); 

// Use this line for a breakout with a hardware SPI connection. Note that 
// the PN532 SCK, MOSI, and MISO pins need to be connected to the Arduino's 
// hardware SPI SCK, MOSI, and MISO pins. On an Arduino Uno these are 
// SCK = 13, MOSI = 11, MISO = 12. The SS line can be any digital IO pin. 
//Adafruit_PN532 nfc(PN532_SS); 

// Or use this line for a breakout or shield with an I2C connection: 
//Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET); 
extern uint8_t BigFont[]; 

void setup(void) { 
    Serial.begin(115200); 
    Serial.println("Hello!"); 
    nfc.begin(); 

    uint32_t versiondata = nfc.getFirmwareVersion(); 
    if (! versiondata) { 
    Serial.print("Didn't find PN53x board"); 
    while (1); // halt 
    } 

    // Got ok data, print it out! 
    Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
    Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
    Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC); 
    lcd.InitLCD(); 
    lcd.setColor (0, 0, 0); 
    lcd.fillRect(1,1,319,239); 
    lcd.setColor (255, 255, 255); 
    lcd.fillRect(100,100,220,140); 
    lcd.setFont (BigFont); 
    lcd.print(String("Scanning"),0,0); 
    // Set the max number of retry attempts to read from a card 
    // This prevents us from waiting forever for a card, which is 
    // the default behaviour of the PN532. 
    nfc.setPassiveActivationRetries(0xFF); 

    // configure board to read RFID tags 
    nfc.SAMConfig(); 

    Serial.println("Waiting for an ISO14443A card"); 
} 

void loop(void) { 
    boolean success; 
    uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID 
    uint8_t uidLength;    // Length of the UID (4 or 7 bytes depending on ISO14443A card type) 

    // Wait for an ISO14443A type cards (Mifare, etc.). When one is found 
    // 'uid' will be populated with the UID, and uidLength will indicate 
    // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight) 
    success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength,25); 

    if (success) { 
    Serial.println("Found a card!"); 
    Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes"); 
    Serial.print("UID Value: "); 
    for (uint8_t i=0; i < uidLength; i++) 
    { 
     Serial.print(" 0x");Serial.print(uid[i], HEX); 
    } 
    Serial.println(""); 
    // Wait 1 second before continuing 
    delay(1000); 
    } 
    else 
    { 
    // PN532 probably timed out waiting for a card 
    //Serial.println("Timed out waiting for a card"); 
    } 
} 

답변

0

내가 그것을 많이 테스트하고 알아 냈어요 - SPI의 비트 순서가 다르다, 당신은 이러한 두 개의 디바이스를 구동 할 수 있도록 동일한 SPI.

그러나 NFC 모듈을 빠르게 구동 할 필요가 없으므로 NFC 모듈에 SW-SPI (bitbanging)를 사용할 수 있습니다. 좋은 업데이트 속도를 유지하려면 대신 TFT가 빠 르게되어야합니다.

내 설치시 한 가지 문제가 여전히 열려 있습니다. 열려있는 직렬 터미널이있는 경우 디스플레이에 내용이 표시되지 않습니다. 하지만 닫히면 TFT와 NFC가 함께 잘 작동합니다. 도움을

#include <ESP8266WiFi.h> 
#include <Wire.h> 
#include <SPI.h> 
#include <Adafruit_PN532.h> 
#include <UTFT.h> 

// NFC module 
#define PN532_SCK D1 
#define PN532_MOSI D2 
#define PN532_MISO D3 
#define PN532_SS D0 
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS); 

// TFT display 
// HSPI defines 
#define TFT_SCK  D5 
#define TFT_MOSI D7 
//#define TFT_MISO D6 (not connected) 
#define TFT_CS  D8 
#define TFT_DC  D4 
UTFT myGLCD(ILI9341_S5P, TFT_CS, -1, TFT_DC); 

// Declare which fonts we will be using 
extern uint8_t SmallFont[]; 
extern uint8_t BigFont[]; 

// forward declaration of helper function to get UID as HEX-String 
void byteToHexString(String &dataString, byte *uidBuffer, byte bufferSize, String strSeperator); 

void setup() { 
    Serial.begin(9600); 

    Serial.println("Initial nfc module"); 
    nfc.begin(); 
    uint32_t versiondata = nfc.getFirmwareVersion(); 
    if (! versiondata) { 
    Serial.print("Didn't find PN53x board"); 
    while (1); // halt 
    } 

    // Got ok data, print it out! 
    Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
    Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
    Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC); 

    // Set the max number of retry attempts to read from a card 
    // This prevents us from waiting forever for a card, which is 
    // the default behaviour of the PN532. 
    nfc.setPassiveActivationRetries(0xFF); 

    // configure board to read RFID tags 
    nfc.SAMConfig(); 

    Serial.println("Waiting for an ISO14443A card"); 
    Serial.println("Initial tft display"); 

    myGLCD.InitLCD(); 
    myGLCD.setColor(0, 0, 0); 
    myGLCD.fillRect(1,1,319,239); 
    myGLCD.setColor(255, 255, 255); 
    myGLCD.setFont(BigFont); 
    myGLCD.print(String("Scanning"),0,0); 
} 

void loop(void) { 
    boolean success; 
    uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID 
    uint8_t uidLength;    // Length of the UID (4 or 7 bytes depending on ISO14443A card type) 

    // Wait for an ISO14443A type cards (Mifare, etc.). When one is found 
    // 'uid' will be populated with the UID, and uidLength will indicate 
    // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight) 
    success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength); 
    //success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength,25); 

    if (success) { 
    Serial.println("Found a card!"); 
    Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes"); 
    Serial.print("UID Value: "); 
    String strUID; 
    // store UID as HEX-String to strUID and print it to display 
    byteToHexString(strUID, uid, uidLength, "-"); 
    Serial.println(""); 
    Serial.println(strUID); 
    myGLCD.print(strUID, CENTER, 50); 
    myGLCD.setColor (255, 0, 0); 
    myGLCD.setFont (BigFont); 
    myGLCD.print(String("Scanning"),0,0); 
    // Wait 1 second before continuing 
    delay(1000); 
    } 
    else 
    { 
    Serial.println("Timed out or waiting for a card"); 
    } 
} 

// helper function to get UID as HEX-String 
void byteToHexString(String &dataString, byte *uidBuffer, byte bufferSize, String strSeperator=":") { 
    dataString = ""; 
    for (byte i = 0; i < bufferSize; i++) { 
    if (i>0) { 
     dataString += strSeperator; 
     if (uidBuffer[i] < 0x10) 
     dataString += String("0"); 
    } 
    dataString += String(uidBuffer[i], HEX); 
    } 
    dataString.toUpperCase(); 
} 
0

감사 :

여기 내 코드입니다. Im bitbanging SPI의 큰 팬이 아닙니다. 여러 가지 방법을 시도하고 다시 초기화 해 보았습니다. 마지막으로 해결되었습니다.

이유는 모르겠지만 카드를 읽은 후 SPI 하드웨어를 다시 초기화하면 모듈이 완벽하게 작동합니다.

난 그냥 카드를 읽은 후 추가 된 코드 : 같은

lcd._hw_special_init(); 

을 :

success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength,0); 
    if (success) { 
    lcd._hw_special_init(); 
    //Do the rest 
    }