espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.28k stars 7.35k forks source link

RFID read error with RDM 6300 (125Mhz RFID Reader Modun) #1405

Closed hoangthaibmvl closed 6 years ago

hoangthaibmvl commented 6 years ago

Hardware:

Board: ESP32 VN Iot Core Installation/update date: 15/May/2018 IDE name: Arduino IDE Flash Frequency: 80Mhz Upload Speed: 115200

Description:

I try to read rfid wth rdm 6300 modun but i can't. When i read it have this code then reboot:

Guru Meditation Error: Core 0 panic'ed (StoreProhibited) . Exception was unhandled. Core 0 register dump: PC : 0x40080e8f PS : 0x00060031 A0 : 0x80080f40 A1 : 0x3ffc05b0
A2 : 0x00010000 A3 : 0x00000000 A4 : 0x00000010 A5 : 0x00000000
A6 : 0x3fefffff A7 : 0x00000000 A8 : 0x80080e26 A9 : 0x3ffc0590
A10 : 0x00038d8d A11 : 0x00000000 A12 : 0x8008578d A13 : 0x3ffc6db0
A14 : 0x00000003 A15 : 0x00060323 SAR : 0x00000010 EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Core 0 was running in ISR context: EPC1 : 0x40080e8f EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x400d5274

Backtrace: 0x40080e8f:0x3ffc05b0 0x40080f3d:0x3ffc05d0 0x400810ad:0x3ffc05f0 0x400818c1:0x3ffc0610 0x400d480b:0x00000000

Rebooting...

I'm looking for solution. If you know how to fix it please tell me. Thank you so much

Sketch:



//Change the code below by your sketch

#include <SoftwareSerial.h>
#include <SeeedRFID.h>

#define RFID_RX_PIN 16
#define RFID_TX_PIN 17

// #define DEBUG
// #define TEST

SeeedRFID RFID(RFID_RX_PIN, RFID_TX_PIN);
RFIDdata tag;

void setup() {
    Serial.begin(115200);
    Serial.println("RFID Test..");
}

void loop() { 
    if(RFID.isAvailable()){
        tag = RFID.data();
        Serial.print("RFID card number: ");
        Serial.println(RFID.cardNumber());
#ifdef TEST
    Serial.print("RFID raw data: ");
    for(int i=0; i<tag.dataLen; i++){
        Serial.print(tag.raw[i], HEX);
        Serial.print('\t');
        }
#endif
    }
}
Exception decoder

PC: 0x40080e8f: SoftwareSerial::rxRead() at C:\Users\hoang\Documents\Arduino\libraries\espsoftwareserial-master\SoftwareSerial.cpp line 265
EXCVADDR: 0x00000000

Decoding stack results
0x40080e8f: SoftwareSerial::rxRead() at C:\Users\hoang\Documents\Arduino\libraries\espsoftwareserial-master\SoftwareSerial.cpp line 265
0x40080f3d: sws_isr_16() at C:\Users\hoang\Documents\Arduino\libraries\espsoftwareserial-master\SoftwareSerial.cpp line 50
0x400810ad: __onPinInterrupt at C:\Users\hoang\Documents\Arduino\hardware\espressif\esp32\cores\esp32\esp32-hal-gpio.c line 211
0x400d480b: esp_vApplicationIdleHook at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/./freertos_hooks.c line 62
stickbreaker commented 6 years ago

@hoangthaibmvl

Guru Meditation Error: Core 0 panic'ed (StoreProhibited) . Exception was unhandled.

StoreProhibited is saying that an invalid memory address was specified to store a value. Usually this means that an uninitialized pointer was used as a storage location.

You need to download and install me-no-dev's backtrace decoder and use it to find where in your code this error is generated.

Chuck.

hoangthaibmvl commented 6 years ago

@stickbreaker hi there is the decoder

PC: 0x40080e8f: SoftwareSerial::rxRead() at C:\Users\hoang\Documents\Arduino\libraries\espsoftwareserial-master\SoftwareSerial.cpp line 265 EXCVADDR: 0x00000000

Decoding stack results 0x40080e8f: SoftwareSerial::rxRead() at C:\Users\hoang\Documents\Arduino\libraries\espsoftwareserial-master\SoftwareSerial.cpp line 265 0x40080f3d: sws_isr_16() at C:\Users\hoang\Documents\Arduino\libraries\espsoftwareserial-master\SoftwareSerial.cpp line 50 0x400810ad: __onPinInterrupt at C:\Users\hoang\Documents\Arduino\hardware\espressif\esp32\cores\esp32\esp32-hal-gpio.c line 211 0x400d480b: esp_vApplicationIdleHook at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/./freertos_hooks.c line 62

stickbreaker commented 6 years ago

@hoangthaibmvl Why are you using software serial? The esp32 has 3 hardware serials available?

Chuck.

hoangthaibmvl commented 6 years ago

@stickbreaker hi i'm a beginner so i read in the internet it say use the software serial so i have no idea about that. You can tell me how to fix that

stickbreaker commented 6 years ago

@hoangthaibmvl It looks like the Seeed library #include <SeeedRFID.h> is based on SoftwareSerial.

Are you using this library? SeedStudio/RFID_Library?

I just read through it, and it is very sloppy code. The read() function has this loop in it:

while (_rfidIO->available())
    {
        _data.raw[_data.dataLen++] = _rfidIO->read();
        delay(10);
    }

_rfidIO() is the SoftwareSerial object. _data is defined:

struct RFIDdata
{
    int dataLen;
    byte chk;
    boolean valid;
    unsigned char raw[5];
};

So raw[] is a five element character array. The read() function has no provision for handling more than 5 characters. And the while loop will keep reading data from the serial object and adding it to the end of raw[]. Also, if only 1 character is in the serial input buffer when read() is called, that single character will be discarded and the rest of the 5 character data packed will still be in the input buffer, If another packet is received then the input buffer would have 9 characters in it the next time read() is called. read() then would store those next 4 bytes in [0..3] and the first character of the next packet in [5] then then rest of the second packet past the end of raw[]. That is what is probably causing the explosion.

You need a better library.

Chuck.

hoangthaibmvl commented 6 years ago

@stickbreaker I use the RDM6300. I search on google many time it just have the library based on SoftwareSerial. So I can find the better library. May be find another way to fix it.

stickbreaker commented 6 years ago

@hoangthaibmvl try reading the raw data directly from the device

I'm basing this code from the dataformat described from SEEED 125khz RFID module

HardwareSerial Serial1(1);

#define RX_PIN 16
#define TX_PIN 17

void setup(){
  Serial.begin(115200); // debug serial monitor
  Serial1.begin(9600,SERIAL_8N1,RX_PIN,TX_PIN); // connect card reader to TX_PIN and RX_PIN
  Serial.printf(" initialized Second UART on pins: Rx=%d, Tx=%d\n",RX_PIN,TX_PIN);
}

#define MAX_BUFFER 100 // storage buffer length
bool started = false; // Flag to indicate a start marker(0x2) was found.
char buffer[MAX_BUFFER+1]; // need room for the terminating NULL, [0..99] for characters [100] for NULL to mark the end.
uint16_t len=0; // current length of buffer

void loop(){
if(Serial1.available()){ // data in serial buffer
  char ch=Serial1.read();
  if(started){ // currently building a packet, either add it to existing buffer, or start over if START (0x2) or END (0x3) is detected.
    if(ch==0x02){ // found START before END, ERROR
      buffer[len] = 0x0; // null to terminate character array
      Serial.printf(" Invalid packet struction START found before END: Current raw Packet = %s\n",buffer); 
      len = 0; // reset buffer because START detected
      }
    else if(ch==0x03) { // END of packet detected, Display it., test Checksum
      if(len==11){ // full data packet, 10 ascii hex characters, 1 checksum byte
        // convert ascii hex digits to bytei representation
       byte b[6]; // 5 byte plus room for calculated checksum
       for(uint8_t i = 0; i<5; i++){ // walk through hex string
          b[i] = (buffer[i*2] - ((buffer[i*2]>57)? 55: 48) ) * 16; // convert high nibble
          b[i] += buffer[(i*2)+1] - ((buffer[(i*2)+1]>57)? 55: 48); // convert, add low nibble
          }

        b[5] = b[0] ^ b[1] ^ b[2] ^ b[3] ^ b[4]; // XOR all five bytes to generate checksum

    // now print it out
        byte receivedCheckSum = buffer[10]; // saving it because I am writing NULL, to terminate string
        buffer[10] = 0x0; // null to terminate Data string 
        Serial.printf(" Complete data packet detected = %s CheckSum: %s\n",buffer,(b[5]==receivedCheckSum)?"GOOD":"FAILED");
        if(b[5]!=receivedCheckSum){
          Serial.printf(" Calculated Checksum =0x%02X, received Check Sum = 0x%02X\n",b[5],receivedCheckSum);
          }
        len=0;
        started=false; // read for next packet
        }
      else { // packed wrong length
        Serial.printf(" END detected,but packet not Correct Length, expected 10+cksum, actual=%d\n",len);
        Serial.printf(" Raw Packet = %s\n",buffer);
        len=0; 
        started = false;

      }
    }
    else if(len<10){
        if(((ch>='0')&&(ch<='9')) || ((ch>='A') && (ch<='F'))) { // valid data value
          buffer[len++] = ch; // store raw data, increment len
          buffer[len] = 0x0; // add string end marker, will be overwritten by next character stored.
        }
        else Serial.printf("invalid raw data character at position: %d =%c\n",len,ch);
    }
    else { // more than 10 characters, just store as raw chars, possibly checksum.
      if(len<MAX_LEN) {
         buffer[len++] = ch;
         buffer[len] = 0x0; // end of string marker.
      }
      else { //discard because buffer is full
        Serial.printf(" Discarded because buffer was full 0x%02X = %c\n",ch,ch);
      }
    } 
  }
  else { // haven't found START yet, so discard
    Serial.printf(" Look for START (0x02) found 0x%02X\n",ch);
    }
  }
}

Try this code, See what it prints.

Chuck.

hoangthaibmvl commented 6 years ago

@stickbreaker Code have this error:
rfid:63: error: 'MAX_LEN' was not declared in this scope

   if(len<MAX_LEN) {
stickbreaker commented 6 years ago

Change MAX_LEN to MAX_BUFFER

Chuck.

hoangthaibmvl commented 6 years ago

@stickbreaker Here

Look for START (0x02) found 0x02 Look for START (0x02) found 0x30 Look for START (0x02) found 0x44 Look for START (0x02) found 0x30 Look for START (0x02) found 0x30 Look for START (0x02) found 0x33 Look for START (0x02) found 0x31 Look for START (0x02) found 0x39 Look for START (0x02) found 0x43 Look for START (0x02) found 0x44 Look for START (0x02) found 0x30 Look for START (0x02) found 0x37 Look for START (0x02) found 0x30 Look for START (0x02) found 0x03

lbernstone commented 6 years ago

This is now a basic logic control problem. Please close the issue and either do some troubleshooting on your own or take the conversation over to https://gitter.im .

hoangthaibmvl commented 6 years ago

Thank you

hoangthaibmvl commented 6 years ago

END detected,but packet not Correct Length, expected 10+cksum, actual=12 Raw Packet = 0D00319CD070

0D00319CD070 this is my RFID right ?