Auteur Sujet: Bibliothèque ACAN et détecteurs RFID en mode SPI  (Lu 9590 fois)

Dominique

  • Global Moderator
  • Hero Member
  • *****
  • Messages: 2889
  • 100% Arduino et N
    • Voir le profil
Bibliothèque ACAN et détecteurs RFID en mode SPI
« le: avril 19, 2020, 07:06:55 pm »
Je viens de tester 2 cartes RC522 connectées sur un même Nano équipé de l'interface Can (une carte 8 servos de Jean-Luc).



Ces cartes s'interfacent sur le bus SPI, donc il est possible d'en faire coexister plusieurs, avec l'interface Can (SPI aussi), pourvu que le Nano dispose de broches pour les Chip Select.

Le sketch ReadUidMultiReader , un des exemples de la bibliothèque MFRC522, fonctionne parfaitement

Reader 0: Firmware Version: 0x92 = v2.0
Reader 1: Firmware Version: 0x92 = v2.0
init OK
Reader 1: Card UID: 79 CC C6 2B
PICC type: MIFARE 1KB
Reader 0: Card UID: 79 CC C6 2B
PICC type: MIFARE 1KB
Reader 1: Card UID: 04 CA 7E C2 99 58 80
PICC type: MIFARE Ultralight or Ultralight C
Reader 0: Card UID: 04 CA 7E C2 99 58 80
PICC type: MIFARE Ultralight or Ultralight C


Et je confirme à l'instant la compatibilité avec la bibliothèque ACAN selon l'article La bibliothèque ACAN (1).

RC522 init OK
CAN init OK
Reader 1: Card UID: 79 CC C6 2B
PICC type: MIFARE 1KB
Reader 0: Card UID: 04 ED 7E C2 99 58 80
PICC type: MIFARE Ultralight or Ultralight C
recu : 0, longueur : 3
recu : 0, longueur : 3
recu : 0, longueur : 3
recu : 16657409, longueur : 3
recu : 16591873, longueur : 3
recu : 16526337, longueur : 3
Reader 1: Card UID: 79 CC C6 2B
PICC type: MIFARE 1KB

Le programme est très simple :

include <SPI.h>
#include <mcp_can.h>
#include <MFRC522.h>
#include <ACAN2515Settings.h> /* Pour les reglages  */
#include <ACAN2515.h>         /* Pour le controleur */
#include <CANMessage.h>       /* Pour les messages  */


#define SS_1_PIN 8
#define SS_2_PIN 7
#define RST_PIN 9
#define NR_OF_READERS   2
byte ssPins[] = {SS_1_PIN, SS_2_PIN};

MFRC522 mfrc522[NR_OF_READERS];   // Create MFRC522 instances.
MFRC522::MIFARE_Key key1;
MFRC522::MIFARE_Key key2;

static const byte MCP2515_CS  = 10 ; // CS input of MCP2515
//static const byte MCP2515_SCK = 13 ; // SCK input of MCP2515
//static const byte MCP2515_SI  = 11 ; // SI input of MCP2515
//static const byte MCP2515_SO  = 12 ; // SO output of MCP2515
static const byte MCP2515_INT = 3 ; // INT output of MCP2515

ACAN2515 controleurCAN(MCP2515_CS, SPI, MCP2515_INT);
static const uint32_t FREQUENCE_DU_QUARTZ = 16ul * 1000ul * 1000ul; //16Mhz
static const uint32_t FREQUENCE_DU_BUS_CAN = 500ul * 1000ul;        //500kHz
CANMessage messageCANEmission;
CANMessage messageCANReception;

// Init array that will store new NUID
byte nuidPICC[4][4];
bool newtag = false;
byte numtag = 255;



void setup() {
  Serial.begin(115200);
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)

  SPI.begin(); // Init SPI bus
 
  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
    Serial.print(F("Reader "));
    Serial.print(reader);
    Serial.print(F(": "));
    mfrc522[reader].PCD_DumpVersionToSerial();
  }
  Serial.println("RC522 init OK");
  ACAN2515Settings configuration(FREQUENCE_DU_QUARTZ, FREQUENCE_DU_BUS_CAN);
  const uint32_t codeErreur = controleurCAN.begin(configuration, [] { controleurCAN.isr(); });
  Serial.println("CAN init OK");

}

 /**
 * Helper routine to dump a byte array as hex values to Serial.
 */
void dump_byte_array(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);
  }
}

void loop() {

  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    // Look for new cards

    if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
      Serial.print(F("Reader "));
      Serial.print(reader);
      // Show some details of the PICC (that is: the tag/card)
      Serial.print(F(": Card UID:"));
      dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
      Serial.println();
      Serial.print(F("PICC type: "));
      MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
      Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));

      // Halt PICC
      mfrc522[reader].PICC_HaltA();
      // Stop encryption on PCD
      mfrc522[reader].PCD_StopCrypto1();
    } //if (mfrc522[reader].PICC_IsNewC
  } //for(uint8_t reader

  if (controleurCAN.receive(messageCANReception)) {
    Serial.print("recu : ");
    Serial.print(messageCANReception.data32[0]);
    Serial.print(", longueur : ");
    Serial.println(messageCANReception.len);
  }
}
Cordialement,
Dominique

JeeLet

  • Newbie
  • *
  • Messages: 19
    • Voir le profil
Re : Bibliothèque ACAN et détecteurs RFID en mode SPI
« Réponse #1 le: mai 12, 2020, 06:28:32 pm »
Bonsoir

Sympa, je découvre , merci  :)

info pour les curieux https://static.cinay.xyz/2019/07/Lecteur-USB-RFID(NFC)-SCL3711.html