SM130 Arduino

Hello Guys !

I'm here because I have a problem ! I have for project, Write/Read Mifare cards 1K !

I have buy the SM130 with the Eval Shield 13,35 KHz, nd i have the arduino Uno !

after studying the datasheet, i have write a programm..

My problem is : My programm don't write a new Key A in the card :frowning:

Here is my program :

#include <SoftwareSerial.h>

SoftwareSerial rfid(7,8);



//Prototypes

void Activation(void);

void Analyse(void);

void Authentication(void);

void Cherche_Tag(void);

void Cle_Ecrite(void);

void Control_Presence(void);

void Data_Ecrite(void);

void Ecrire_Block(void);

void Ecrire_Cle(void);

void Imprime_ID_Tag(void);

void Lecture_Block(void);

void Verification(void);

void Read_Firware_Version(void);

void ecrire_cle (void);

//void afficher (void);

 

// commande

int Reset = 128; //( Reset (0x80))

int Firmware = 129; //( Lecture du Firmware, Révision du module (0x81))

int Cherche = 130;//Cherche un tag ( 0x82 seek tag )

int SelecTag = 131;//Select Tag (ox83)

int Controle=133; // Authentification (0x85)

int Lire4Block = 134;//Ecrire les données dans un block spécifié (0x86)

int Lire1Block= 135;//Lit à partir d'un bloc de valeur (0x87))

int Ecri4Block = 137;//Ecrit les données dans le bloc spécifié ( 0x89)

int Ecri1Block=138;//Formate et ecrit une valeur du block  (0x8A)

int EcriCle=140;//Ecrit une clé de l'EEPROM du MFRC530 ( 0x8C ) 

int AntenneOnOff=144;//Antena Power, Active ou desactive le champ RF (0x90)

int On=1;//allumer

int Off=0;//etteind

int CleA=170;//Cle A (0xAA ? )

int CleB=187;//Clé B (OxBB ?)

int Pas2Cle=255;//Pas de Clé (0xFF);

int Active=147; // Arrêt de la CCIP (0x93)

int Veille = 150; //Met le SM130 en veille ( 0x94)

byte Positif=76; //réponse renvoyé en cas de succé


 

// Variable

int Donnees;

int Commande;

int Longueur;

int Code[6];

int Data[16];

int DataE[16];

int SomDataE;

int SomCode;

int CleVerif[6];

int Block;

int BlockS;

int Secteur;

int TypeCle;

int Present;

int a;

float b1;

int b2;

int i;


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

Serial.println(F("Demarrage")); // le F( permet de ne pas stocker le contenu de la () dans la RAM mais ne fonctionne qu'avec la version 1.0

rfid.begin(19200);

delay(10);

SomDataE=0;

Activation();
  
}

void Activation ()//Acitve l'antenne
{

Commande=Active;

Longueur=1;

rfid.write(byte(255));         // Toujour à 255
rfid.write(byte(0));           // Toujour à 0
rfid.write(byte(Longueur));     // mets le nombre de valeur envoyé la commande et les données s'il y en a, ici il n'y a qu'1 commande
rfid.write(byte(Commande));    // C'est la commande
rfid.write(byte(CleVerif[1])); // Clé de controle qui est la somme des valeurs de la longueur, de la commande et des données quand il y en a


  
}

void loop()

{

Cherche_Tag();

Analyse();

Control_Presence();

Imprime_ID_Tag();

delay(100);

SomCode=0;

}

//_____________________________________________________________

void Cherche_Tag()   //Cherche la présence d'un tag

{

Commande=Cherche;

Longueur=1;

CleVerif[1]=Longueur+Commande;

rfid.write(byte(255));

rfid.write(byte(0));

rfid.write(byte(Longueur));

rfid.write(byte(Commande));

rfid.write(byte(CleVerif[1]));

delay(50);

}

//_____________________________________________________________

void Analyse()

{

while(rfid.available()){

if(rfid.read() == 255){

for(i=1;i<17;i++){

Data[i]= rfid.read();

}

}

}

}

//_____________________________________________________________

void Control_Presence()

{

if(Data[2] == 6){

Present++;

}

if(Data[2] == 2){

Present = 0;

}

}

//_____________________________________________________________

void Imprime_ID_Tag()    //imprime le numéro du tag

{

     if(Present == 1){

     Serial.print(F("Tag Type : "));

          if (Data[4]==1){
 
                           Serial.println(F("Mifare Ultralight "));

                         }

          else if (Data[4]==2){

               Serial.println(F("Mifare Standard 1K "));
             }

else if (Data[4]==3){

Serial.println(F("Mifare Classic 4K "));

}

else {

Serial.println(F("Non reconnu "));

}

Serial.print(F("Tag ID : "));

for(int i=5;i<9;i++){

Serial.print(Data[i], HEX);

Serial.print(" ");

}

Serial.println();

ecrire_cle ();


}

delay(50);

}


void ecrire_cle ()

{
  


Commande=EcriCle;

Longueur=9;

Donnees=6;



rfid.write(byte(255));

rfid.write(byte(0));

rfid.write(byte(Longueur));

rfid.write(byte(Commande));

rfid.write(byte(Donnees)); 

rfid.write(byte(170));

rfid.write(byte(01));

rfid.write(byte(02));

rfid.write(byte(03));

rfid.write(byte(04));

rfid.write(byte(05));

rfid.write(byte(06));

rfid.write(byte(90));


//recupère la response

delay(50);

while(rfid.available())
{

if(rfid.read() == 255){

for(i=1;i<6;i++){

Data[i]= rfid.read();

Serial.println(Data[i]);
}

}

}

if(Data[4] == Positif){

Serial.print(F("OK "));



}

else {

Serial.print(F("Cle non disponible: "));

Serial.println(Block);

}

//   a=1;

delay(100);

//   flag2 = 1;

}

I don't use all Void, command and variable, because i used the same standing in all my programs for mifare.

So, I use the commands that are written on the datasheet :

And, i have used the exemple of the datasheet...
Normaly, I must have an answer :

If Write Key successflu :

FF 00 02 8C 4C DA in Hex or in DEC : 255 0 2 140 76 218

If Write Key failied

FF 00 02 8C 4E DA in Hex or in DEC : 255 O 2 140 78 218

Ok, all alright...

In my monitor :

The answer of my SM130 it is, You Have succeful write the Key A...

And i don't have Write the Key A in the Bloc 6... I used, another software, the name is : " ICTransfer " to check

Here, the second image, I try to read sector 6 with the A key I described, it means 010203040506.

And, i have one error, it is : Communication failled, because it fails to identify...

If i Used the transport key FF FF FF FF FF FF :

we see that we can play with the device transport key ...
Normally with my program should change the key to A 010203040506.

Can you help me and tell me why this does not change?

Excuse me for my english, I'm frnaçais and I do not speak English!

And I'm sorry for the size of the post!

again thank you

Commandes.png