Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 39

Thread: Teency 3.1 Compatibility with MFRC522 RFID Library

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    12

    Teensy 3.1 Compatibility with MFRC522 RFID Library

    I have recently purchased a number of Teensy3.1 controllers, which I have been very impressed, especially the RTC capability. I am trying to build a project with the Teensy 3.1 that uses an SPI connection to the MFRC522 RFID card reader (SSRFIDV1.0 or RFID RC522 Reader IC Card Module) links to each manual are listed below. I have been using the libraries downloaded from http://github.com/miguelbalboa/rfid. Unfortunately, the teensy 3.1 will only read the 4 byte cards and will not register the 7 or 10 byte RFID Cards. Since this library works on the arduino Mega and Uno etc.(I have been able to read all RFID Card formats), which are all 8 bit processors and since the Teensy 3.1 is 32 bit processor, would this be the reason for the lack of functionality. If this is the case, can you direct me as to how to change the library or point me in the direction of someone who may know and be willing to help. I am very keen to stay with the Teensy3.1 if I can fix this compatibility issue.

    Your advice would be greatly accepted,

    SSRFIDV1.0 manual at http://www.elechouse.com/elechouse/i...FID_Manual.pdf
    Last edited by HGPAust; 04-17-2014 at 08:12 AM.

  2. #2
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    As an experiment, or as a work-around, could you use the tag reader's UART interface with one of the 3 UARTs on the Teensy 3?

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    12
    Quote Originally Posted by stevech View Post
    As an experiment, or as a work-around, could you use the tag reader's UART interface with one of the 3 UARTs on the Teensy 3?
    Yes, that is one of the reasons for going to a SPI connection as to bypass the UART as it will read the 4 byte card but nothing else. The only way to read the other cards is to use the SPI, bypassing the UART and using the Arduino and supporting library. However, I desperately want to stay with the Teensy 3.1 as I need to use the built in RTC and I am a Teensy fan.
    Last edited by HGPAust; 04-17-2014 at 08:09 AM.

  4. #4
    I'm not at all sure if this helps you...
    If you're using a 522 RFID reader using SPI you might be better off going for something cheaper.

    See

    I'm not familiar with the library you're using, however I've used the above cards with Teensy 2

    Ian

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,606
    I ordered this one, just now. It's shipping from within the USA, so hopefully I'll have it sometime next week.

    I'm afraid there's not much can I do to help until I get the actual hardware for testing.

  6. #6
    Junior Member
    Join Date
    Apr 2014
    Posts
    12
    Quote Originally Posted by ian View Post
    I'm not at all sure if this helps you...
    If you're using a 522 RFID reader using SPI you might be better off going for something cheaper.

    See

    I'm not familiar with the library you're using, however I've used the above cards with Teensy 2

    Ian
    Thanks Ian, I have been using these ones and moving my project to incorporate them, once again they work well with Arduino, I have used them with the Mega 2560, with the library linked below with no problems, however, when it comes to the Teensy3.1 it will one pick up cards with 4 bytes IDs. I have looked through the library files to find if it is something obvious but I am afraid it is way beyond my level of expertise. However, would love to learn more.

    http://https://github.com/miguelbalboa/rfid

  7. #7
    Junior Member
    Join Date
    Apr 2014
    Posts
    12
    Paul, thanks I have been working on this project for weeks, however, I am afraid it is just beyond my knowledge. I would like to understand where the disconnect is. As previously mentioned, I have had this working on numerous Arduino boards such as the mega 2560 using the same aforementioned library with either the SSRFIDV0.1 or the RFID RC522 cards with no problems. It just will not even recognise any card that has more than 4 bytes for it ID.
    Last edited by HGPAust; 04-18-2014 at 01:01 PM.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,606
    I got a shipping notice, so hopefully I'll have this hardware soon.

    I'm not very familiar with these RFID tags. That product I ordered seems to come with 1 thing to read. Will it have only a 4 byte ID?

    If I'm going to need something else to test 7 and 10 byte IDs, please let me know?

  9. #9
    Junior Member
    Join Date
    Apr 2014
    Posts
    12
    Paul, I believe the MIFARE DESFire EV1 and the MIFARE Ultralight C have the 7 byte UIDs, while the MIFARE Classic has a 4 byte UID. I believe the encryption talked about in the standards are associated with access to the memory, however just being able to read the different card's is a great start. As I mentioned these cards are able to be read on both the readers previously mentioned readers when using the arduino and associated libraries. I hope this helps, if not please let me know.

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,606
    Is the cheap hardware I ordered ok? See the link on reply #5.

    If I need something else to reproduce this problem, please let me know. I do want to resolve this issue, and PJRC does have a small but reasonable budget to buy hardware for testing Arduino libraries. If there's something else I need to buy to scan a 7 or 10 digit ID, and if it's not really expensive, I can get it. But I'm not very familiar with this RFID stuff. If you can point me to the right hardware, we'll all save a lot of time.

  11. #11
    Junior Member
    Join Date
    Apr 2014
    Posts
    12
    That is the one I have ordered, it is cheap and uses the SPI connection. I also know these work with all the known RFID cards using the arduino and associated library.

  12. #12
    Junior Member
    Join Date
    Apr 2014
    Posts
    12
    Sorry a bit out of sink with the threads, I can not think of anything else in the way of hardware, I have been using both the RFID readers listed in my first post. I originally started my project with the teensy 3.1 with a serial connection using the UART, however it only READ THE 4 byte cards. I then went to a SPI connection, even removing the UART chip from the SSRFIDV1.0 to no avail. I then went to the other reader with the same result. I then tried the SPI connection on both readers using the libraries, prescribed above, with the Mega 2560 and arduino pro mino, both worked well and read all the cards tested(both 4 and 7 byte cards). As a result I thought it to be an issue related to the chip type etc. I hope this helps!
    Last edited by HGPAust; 04-19-2014 at 03:28 PM.

  13. #13
    Paul,

    It would probably be helpful to have some cards which you know for certain use a 7 byte ID, particularly as this is what HGPAust is struggling with. It's quite likely the cards bundled with the reader are 4 byte. In essence, both are readily available but 4 byte IDs are no longer unique.

    A quick look around the web suggests to me that all of the Arduino code out there derives from example code published by www.B2CQSHOP.com in China. AFAICR when I was using these RFID readers I based my code on a slightly more readable version.

    Something that jumps out at me at the start of the program:

    #define uint unsigned int

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,606
    Quote Originally Posted by HGPAust View Post
    That is the one I have ordered, it is cheap and uses the SPI connection.
    Was there supposed to be a link in reply #11?


    Quote Originally Posted by ian View Post
    It would probably be helpful to have some cards which you know for certain use a 7 byte ID, particularly as this is what HGPAust is struggling with. It's quite likely the cards bundled with the reader are 4 byte.
    Where can I buy a 7 byte ID card?

    A quick look around the web suggests to me that all of the Arduino code out there derives from example code published by www.B2CQSHOP.com in China.
    I've been looking at the miguelbalboa copy, linked from the original post. Any chance you could point me to these other copies?

    About the code, I took a very quick look, even though I don't have any real hardware yet.

    My first guess would be the 2 structs in MFRC522.h. Perhaps they need the "packed" attribute on 32 bit platforms? Like this:

    Code:
        // A struct used for passing the UID of a PICC.
        struct Uid_struct {
            byte        size;           // Number of bytes in the UID. 4, 7 or 10.
            byte        uidByte[10];
            byte        sak;            // The SAK (Select acknowledge) byte returned from the PICC after successful selection.
        } __attribute__((packed));
        typedef struct Uid_struct Uid;
    
        // A struct used for passing a MIFARE Crypto1 key
        struct MIFARE_Key_struct {
            byte        keyByte[MF_KEY_SIZE];
        } __attribute__((packed));
        typedef struct MIFARE_Key_struct MIFARE_Key;

  15. #15
    Junior Member
    Join Date
    Apr 2014
    Posts
    12
    I purchased two blank cards today via eBay, however, they were purchased from China and may take up to a month to get here. From what I understand cards that are compliant with the MILFARE DESFire EV1 standard have UID of 7 Bytes as confirmed in the data sheet that was posted with the cards on eBay. I will test them on the Arduino setup when they arrive to ensure they are compliant and have a 7 byte UID. If you can't source one at your end, I will send one across, however by the time it gets here it may be quite awhile. The ones I have used for testing in the past are in constant use and unfortunately cannot be released. The link below illustrates the cards and their associated data sheet:

    http://www.ebay.com.au/itm/NFC-Tags-...af598a7&_uhb=1
    Last edited by HGPAust; 04-19-2014 at 03:56 PM.

  16. #16
    I believe all mifare cards are available with 7 byte UID now(?) I suspect DESFire might be a bit special (DES encryption)
    Google shows me plenty of UK suppliers of 'mifare classic 7 byte cards'
    The code I've used is linked in reply #13

  17. #17
    Junior Member
    Join Date
    Apr 2014
    Posts
    12
    Ian, did you successfully get the teensy 3.1 to detect a 7 byte card with the code you posted at #13?

  18. #18
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,606
    Did anyone try the packed attribute idea from #14? I still don't have hardware, so I can't try it. I do have a reader and 7 byte card on order, but the card is coming from China, so it may be a few weeks until I have all the hardware needed to test.

    I can tell you there are 3 common issues with 8 bit code porting to 32 bit platforms. The most common is putting 2 bytes from I2C into a 16 bit signed integer (common with motion sensors). A similar issue involves passing data through int pointers, where the pointer is initialized with the address of a 16 bit variable (eg, the variable is int16_t but the function's pointer is "int*").

    The third issue involves using structs as data templates, where an array of bytes is access as a struct (usually though a pointer, initialized with the array address). On 8 bit AVR, structs are always packed together. But on 32 bit platforms, often the compiler will align the elements of the struct to 32 bit boundaries, which greatly improves performance, but it leaves small gaps in memory between the items in the struct. The packed attribute tells the compiler to pack the data together, the same as if it were on an 8 bit platform.

    This library appears to use that technique, where data is received from the card into a byte array, then a struct pointer is initialized to the address of the array. That's why I suggested trying the packed attribute in reply #14. Please give it a try and let me know if it solves the problem?
    Last edited by PaulStoffregen; 04-21-2014 at 08:56 AM.

  19. #19
    Junior Member
    Join Date
    Apr 2014
    Posts
    12
    I will give it a crack over the next few days.

  20. #20
    Junior Member
    Join Date
    Apr 2014
    Posts
    12
    Unfortunately, I have not been able to get the library functional as yet! I will continue to try and locate the fault.

  21. #21
    Junior Member
    Join Date
    Jun 2014
    Posts
    1
    Hey Guys,

    Any news on this potential 32bit issue on the Teensy 3.1? (works fine on the Teensy 2.0)
    As I'm also stuck with my Mifare Ultralight card (7 bytes) that can't be read.

  22. #22
    Junior Member
    Join Date
    Nov 2014
    Posts
    2
    Any news on this? Struggling to get the RFID-RC522 on a Teensy 3.1 to work as well.

  23. #23
    Senior Member sumotoy's Avatar
    Join Date
    Nov 2012
    Location
    Venezia, Italia
    Posts
    421
    I just got one of these modules and some tag and cards to play with. I got the Balboa's library and out of the box it really dosn't work, get a lot of disconnect, etc. Even on DUE the library have the same problems so Ive tried the Paul suggestions but got the same results. I've tried several mods on pointer side but the library it's a bit too hudge and I'm lost in code, get only small success.
    So I got an early version that it's much smaller and modified for Teensy3.x and SPI transaction, it's really basic but good start point!
    https://github.com/sumotoy/RFID/tree/master
    At list it works with Teesny3.x and DUE.

  24. #24
    Senior Member
    Join Date
    Nov 2012
    Location
    Chipping Norton, UK
    Posts
    274
    Quote Originally Posted by PaulStoffregen View Post
    I do have a reader and 7 byte card on order, but the card is coming from China, so it may be a few weeks until I have all the hardware needed to test.
    Paul

    Did you ever get any further with this or is Sumotoy's library in #23 the best starting point at present?

    Ex.

  25. #25
    Junior Member
    Join Date
    Mar 2016
    Posts
    4
    Hello,

    I've just tried sumotoy's library but without any success...
    Still unable to make rc522 and teensy communicate together if any expert in porting teensy lib could help... I've also opened a ticket on arduino lib's owner and creator.
    Any dev help could be coordinated from there...

    https://github.com/miguelbalboa/rfid/issues/193

    Thanks

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •