Go Down

Topic: SM130 with evaluation board problem (AUTH) (Read 616 times) previous topic - next topic

up201003803

hello,

I'm having problems with auth response.

My code:
Code: [Select]
/*
  RFID Eval 13.56MHz Shield example sketch v10

  Aaron Weiss, aaron at sparkfun dot com
  OSHW license: http://freedomdefined.org/OSHW

  works with 13.56MHz MiFare 1k tags

  Based on hardware v13:
  D7 -> RFID RX
  D8 -> RFID TX
  D9 -> XBee TX
  D10 -> XBee RX

  Note: RFID Reset attached to D13 (aka status LED)

  Note: be sure include the SoftwareSerial lib, http://arduiniana.org/libraries/newsoftserial/

  Usage: Sketch prints 'Start' and waits for a tag. When a tag is in range, the shield reads the tag,
  blinks the 'Found' LED and prints the serial number of the tag to the serial port
  and the XBee port.
 
  06/04/2013 - Modified for compatibility with Arudino 1.0. Seb Madgwick.

*/
#include <SoftwareSerial.h>

SoftwareSerial rfid(7, 8);

//Prototypes
void halt(void);
void parse(void);
void parse_auth(void);

void print_serial(void);
void read_serial(void);
void seek(void);
void set_flag(void);
void auth(void);
void print_auth(void);
void print_read(void);
void read(void);

//Global var
int flag = 0;
int Str1[11];
int Str2[7];
int Str3[21];

//INIT
void setup()
{
  Serial.begin(9600);
  Serial.println("Start");

  // set the data rate for the SoftwareSerial ports
  rfid.begin(19200);
  delay(10);
  halt();
}

//MAIN
void loop()
{
  if(flag==0)
    read_serial();
  if(flag==1){
    auth();
    delay(10);
    parse_auth();
    print_auth();
    flag++;
    delay(100);
  }
  if(flag==2){
    read();
    delay(10);
    parse_read();
    print_read();
    flag++;
    delay(100);
  }
}


void halt()
{
 //Halt tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)147);
  rfid.write((uint8_t)148);
}

void parse()
{
  while(rfid.available()){
    if(rfid.read() == 255){
      for(int i=1;i<11;i++){
        Str1[i]= rfid.read();
      }
    }
  }
  delay(10);
}

void parse_auth()
{
  while(rfid.available()){
    if(rfid.read() == 255){
      for(int i=1;i<7;i++){
        Str2[i]= rfid.read();
      }
    }
  }
  delay(10);
}

void parse_read(){
  while(rfid.available()){
    if(rfid.read() == 255){
      for(int i=1;i<21;i++){
        Str3[i]= rfid.read();
      }
    }
  }
  delay(10);
}


void print_serial()
{
  if(flag == 1){
    //print to serial port
    Serial.print(Str1[5], HEX);
    Serial.print(Str1[6], HEX);
    Serial.print(Str1[7], HEX);
    Serial.print(Str1[8], HEX);
    Serial.println();
    delay(100);
    //check_for_notag();
  }
}

void print_auth()
{
  if(flag == 1){
    //print to serial port
   
    Serial.print(Str2[1], HEX);
    Serial.print(Str2[2], HEX);
    Serial.print(Str2[3], HEX);
    Serial.print(Str2[4], HEX);
    Serial.print(Str2[5], HEX);
    Serial.print(Str2[6], HEX);
   
    Serial.println();
    delay(100);
  }
}

void print_read()
{
  if(flag == 2){
    //print to serial port
   
    Serial.print(Str3[1], HEX);
    Serial.print(Str3[2], HEX);
    Serial.print(Str3[3], HEX);
    Serial.print(Str3[4], HEX);
    Serial.print(Str3[5], HEX);
    Serial.print(Str3[6], HEX);
    Serial.print(Str3[7], HEX);
    Serial.print(Str3[8], HEX);
    Serial.print(Str3[9], HEX);
    Serial.print(Str3[10], HEX);
    Serial.print(Str3[11], HEX);
    Serial.print(Str3[12], HEX);
    Serial.print(Str3[13], HEX);
    Serial.print(Str3[14], HEX);
    Serial.print(Str3[15], HEX);
    Serial.print(Str3[16], HEX);
    Serial.print(Str3[17], HEX);
    Serial.print(Str3[18], HEX);
    Serial.print(Str3[19], HEX);
    Serial.print(Str3[20], HEX);
    delay(100);
  }
}


void read_serial()
{
  seek();
  delay(10);
  parse();
  set_flag();
  print_serial();
  delay(100);
}

void seek()
{
  //search for RFID tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)130);
  rfid.write((uint8_t)131);
  delay(10);
}

void auth(){
  rfid.write(0xff);
  rfid.write((uint8_t)0);
  rfid.write(0x09);
  rfid.write(0x85);
  rfid.write(0x01);
  rfid.write(0x38);
  rfid.write(0x59);
  rfid.write(0xa1);
  rfid.write(0x0d);
  rfid.write(0x43);
  rfid.write(0xf7);
  rfid.write(0x08);
  delay(10);


}

void read(){
  rfid.write(0xff);
  rfid.write((uint8_t)0);
  rfid.write(0x02);
  rfid.write(0x86);
  rfid.write(0x01);
  rfid.write(0x89);
  delay(10);

}


void set_flag()
{
  if(Str1[2] == 6){
    flag++;
  }
  if(Str1[2] == 2){
    flag = 0;
  }
}



I want to auth without a default key. I'm sure that is the correct key.


Code: [Select]

Start
569C69C
000000
028646CEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


This is my output. The second row (full of 0), should be my auth(response).

Thank you for your help,
best,

Pedro Cabral

Go Up