Shop OBEX P1 Docs P2 Docs Learn Events
RFID Read/Write Trouble — Parallax Forums

RFID Read/Write Trouble

jhwattsjhwatts Posts: 35
edited 2010-12-20 10:02 in BASIC Stamp
I just purchased the 28440 RFID read/write module and several different compatible RFID tags. I am using a BS2px24. I used the demo code below. It doesn't detect my tags and display thier number on the debug terminal. I am confident it is wired correctly. Any help would be greatly appreciated.

' =========================================================================

'

' File...... rfid_rw_test.bs2

' Purpose... System-level test code for the Parallax RFID Read/Write Module

' Author.... Joe Grand, Grand Idea Studio, Inc. [www.grandideastudio.com]

' E-mail.... support@parallax.com

' Updated... 15 Dec 2009

'

' {$STAMP BS2px}

' {$PBASIC 2.5}

'

' =========================================================================





'
[ Program Description ]

'

' This program performs a system-level test of the Parallax RFID Read/

' Write Module by:

'

' 1) Reading tag's unique ID

' 2) Writing and verifying a block of data to the tag





'
[ I/O Definitions ]



RFID_TX PIN 0 ' Connects to RFID R/W Module SIN

RFID_RX PIN 1 ' Connects to RFID R/W Module SOUT





'
[ Constants ]



'#SELECT $STAMP

'#CASE BS2, BS2E, BS2PE

' T9600 CON 84

'#CASE BS2SX, BS2P

T9600 CON 240

'#ENDSELECT



Baud CON T9600



' RFID R/W Module Commands

' Number of bytes returned in ()

RFID_Read CON $01 ' Read data from specified address, valid locations 1 to 33 (5)

RFID_Write CON $02 ' Write data to specified address, valid locations 3 to 31 (1)

RFID_Login CON $03 ' Login to tag with password (1)

RFID_SetPass CON $04 ' Change tag's password from old to new (1)

RFID_Protect CON $05 ' Enable/disable password protection (1)

RFID_Reset CON $06 ' Reset tag (1)

RFID_ReadLegacy CON $0F ' Read unique ID from EM4102 read-only tag (for backwards compatibility with Parallax RFID Card Reader, #28140 and #28340) (12)



' Memory map/address locations for EM4x50 tag

' Each address holds/returns a 32-bit (4 byte) value

ADDR_Password CON 0 ' Password (not readable)

ADDR_Protect CON 1 ' Protection Word

ADDR_Control CON 2 ' Control Word

' ADDR 3-31 are User EEPROM area

ADDR_Serial CON 32 ' Device Serial Number

ADDR_DeviceID CON 33 ' Device Identification



' Status/error return codes

ERR_OK CON $01 ' No errors

ERR_LIW CON $02 ' Did not find a listen window

ERR_NAK CON $03 ' Received a NAK, could be invalid command

ERR_NAK_OLDPW CON $04 ' Received a NAK sending old password (RFID_SetPass), could be incorrect password

ERR_NAK_NEWPW CON $05 ' Received a NAK sending new password (RFID_SetPass)

ERR_LIW_NEWPW CON $06 ' Did not find a listen window after sending old password (RFID_SetPass)

ERR_PARITY CON $07 ' Parity error when reading data





'
[ Variables ]



buf VAR Byte(12) ' data buffer



idx VAR Byte ' index

idy VAR Byte



'
[ EEPROM Data ]





'
[ Initialization ]



Initialize:

PAUSE 250 ' let DEBUG open

DEBUG CLS ' clear the screen

DEBUG "Parallax RFID Read/Write Module Test Application", CR,

"
", CR, CR





'
[ Program Code ]



Main:

DEBUG "Reading tag's unique serial number..."

Read_Tag:

SEROUT RFID_TX, Baud, ["!RW", RFID_Read, ADDR_Serial] ' Read tag's serial number

SERIN RFID_RX, Baud, [STR buf\5] ' Get status byte and data bytes

IF buf(0) <> ERR_OK THEN Read_Tag ' If we get an error, keep trying until the read is successful

FOR idx = 1 TO 4 ' Print data

DEBUG HEX2 buf(idx)

NEXT

DEBUG CR



DEBUG "Writing and verifying data to tag..."

Write_Tag:

SEROUT RFID_TX, Baud, ["!RW", RFID_Write, 3, $FE, $ED, $BE, $EF] ' Write $FEEDBEEF into address 4 (user EEPROM area)

SERIN RFID_RX, Baud, [buf(0)] ' Wait for status byte

IF buf(0) <> ERR_OK THEN Write_Tag ' If we get an error, keep trying until the write is successful

DEBUG "Success!", CR



DEBUG "End of test.", CR

END



'
[ End of File ]

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-18 07:21
    The #select statement at the beginning of the program is supposed to let the program work on any model Stamp by adjusting the Baud constant (for 9600 Baud) to match the needs of the Stamp. Unfortunately, not all demo programs were updated to include the BS2px. If you look at the supplement to the Stamp Manual for the BS2px (here) you'll see that the value should be 396. Change the "Baud CON 240" to "Baud CON 396" and it should work.
  • jhwattsjhwatts Posts: 35
    edited 2010-12-18 16:08
    I modified the code to below but it still is not working. What am I missing?

    ' ================================================== =======================

    ' File...... rfid_rw_test.bs2
    ' Purpose... System-level test code for the Parallax RFID Read/Write Module
    ' Author.... Joe Grand, Grand Idea Studio, Inc. [www.grandideastudio.com]
    ' E-mail.... support@parallax.com
    ' Updated... 15 Dec 2009
    ' {$STAMP BS2px}

    ' {$PBASIC 2.5}
    ' ================================================== =======================
    '
    [ Program Description ]

    ' This program performs a system-level test of the Parallax RFID Read/

    ' Write Module by:

    ' 1) Reading tag's unique ID

    ' 2) Writing and verifying a block of data to the tag

    '
    [ I/O Definitions ]

    RFID_TX PIN 0 ' Connects to RFID R/W Module SIN

    RFID_RX PIN 1 ' Connects to RFID R/W Module SOUT

    '
    [ Constants ]

    Baud CON 396

    ' RFID R/W Module Commands

    ' Number of bytes returned in ()

    RFID_Read CON $01 ' Read data from specified address, valid locations 1 to 33 (5)

    RFID_Write CON $02 ' Write data to specified address, valid locations 3 to 31 (1)

    RFID_Login CON $03 ' Login to tag with password (1)

    RFID_SetPass CON $04 ' Change tag's password from old to new (1)

    RFID_Protect CON $05 ' Enable/disable password protection (1)

    RFID_Reset CON $06 ' Reset tag (1)

    RFID_ReadLegacy CON $0F ' Read unique ID from EM4102 read-only tag (for backwards compatibility with Parallax RFID Card Reader, #28140 and #28340) (12)

    ' Memory map/address locations for EM4x50 tag

    ' Each address holds/returns a 32-bit (4 byte) value

    ADDR_Password CON 0 ' Password (not readable)

    ADDR_Protect CON 1 ' Protection Word

    ADDR_Control CON 2 ' Control Word

    ' ADDR 3-31 are User EEPROM area

    ADDR_Serial CON 32 ' Device Serial Number

    ADDR_DeviceID CON 33 ' Device Identification

    ' Status/error return codes

    ERR_OK CON $01 ' No errors

    ERR_LIW CON $02 ' Did not find a listen window

    ERR_NAK CON $03 ' Received a NAK, could be invalid command

    ERR_NAK_OLDPW CON $04 ' Received a NAK sending old password (RFID_SetPass), could be incorrect password

    ERR_NAK_NEWPW CON $05 ' Received a NAK sending new password (RFID_SetPass)

    ERR_LIW_NEWPW CON $06 ' Did not find a listen window after sending old password (RFID_SetPass)

    ERR_PARITY CON $07 ' Parity error when reading data
    '
    [ Variables ]

    buf VAR Byte(12) ' data buffer



    idx VAR Byte ' index

    idy VAR Byte



    '
    [ EEPROM Data ]

    '
    [ Initialization ]

    Initialize:

    PAUSE 250 ' let DEBUG open

    DEBUG CLS ' clear the screen

    DEBUG "Parallax RFID Read/Write Module Test Application", CR,

    "
    ", CR, CR

    '
    [ Program Code ]

    Main:

    DEBUG "Reading tag's unique serial number..."

    Read_Tag:

    SEROUT RFID_TX, Baud, ["!RW", RFID_Read, ADDR_Serial] ' Read tag's serial number

    SERIN RFID_RX, Baud, [STR buf\5] ' Get status byte and data bytes

    IF buf(0) <> ERR_OK THEN Read_Tag ' If we get an error, keep trying until the read is successful

    FOR idx = 1 TO 4 ' Print data

    DEBUG HEX2 buf(idx)

    NEXT

    DEBUG CR



    DEBUG "Writing and verifying data to tag..."

    Write_Tag:

    SEROUT RFID_TX, Baud, ["!RW", RFID_Write, 3, $FE, $ED, $BE, $EF] ' Write $FEEDBEEF into address 4 (user EEPROM area)

    SERIN RFID_RX, Baud, [buf(0)] ' Wait for status byte

    IF buf(0) <> ERR_OK THEN Write_Tag ' If we get an error, keep trying until the write is successful

    DEBUG "Success!", CR


    DEBUG "End of test.", CR

    END
    '
    [ End of File ]
  • $WMc%$WMc% Posts: 1,884
    edited 2010-12-18 17:31
    Take a look in the Parallax store for the RFID reader. There is some BS2 code for the RFID that might work for you.
  • jhwattsjhwatts Posts: 35
    edited 2010-12-18 17:59
    The light is red and the debug terminal is displaying "Reading tag's unique serial number...". I'm using the super carrier board and powering it by a usb connection from my laptop. I thought it might might be power consumption problem so I attached a 9 volt battery but still no luck.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-18 18:37
    The RFID reader is a known power hog because it has to provide power to the tag. A 9V battery is hopelessly inadequate for the job. Use an AC supply rated at least for 300mA or use a 6V or 7.2V battery pack with a minimum of AA size cells. A USB port is very marginal to power a Stamp and an RFID reader.
  • jhwattsjhwatts Posts: 35
    edited 2010-12-18 21:29
    Still no luck. I'm using a AC bench supply that is set to 300 mA at 6 volts. Now what? I have 4 different tags types and I cant get any of them to read.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-18 22:04
    I suggest you call Parallax Tech Support on Monday. The demo code should work once the Baud constant is corrected for the BS2px.
  • jhwattsjhwatts Posts: 35
    edited 2010-12-19 14:23
    Its a code problem. It works on my BS2 but not my BS2px24. My smart card reader works on my BS2px24 and other gizmos so I dont think its damaged.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-19 14:53
    Except for the Baud constant, this program has nothing in it that should make a difference between a BS2 and a BS2px. If you've fixed the Baud constant and recompiled for the BS2px as you've shown (with the STAMP directive), then it should work. If it doesn't work, then you've got something going on that's potentially too complex to solve on a forum and you'll need to talk to Parallax Tech Support. Call them tomorrow if you're in North America, otherwise e-mail them directly.
  • jhwattsjhwatts Posts: 35
    edited 2010-12-20 06:48
    I got it. This code below will get the tags number.

    ' =========================================================================

    '

    ' File...... rfid_rw_demo.bs2

    ' Purpose... Demonstration code for the Parallax RFID Read/Write Module

    ' Author.... Joe Grand, Grand Idea Studio, Inc. [www.grandideastudio.com]

    ' E-mail.... support@parallax.com

    ' Updated... 15 Dec 2009

    '

    ' {$STAMP BS2pe}

    ' {$PBASIC 2.5}

    '

    ' =========================================================================





    '
    [ Program Description ]

    '

    ' This program demonstrates the capabilities of the Parallax RFID Read/

    ' Write Module.

    '

    ' Compatible with EM Microelectronic EM4x50 1kbit R/W 125kHz tags.

    ' These tags can be used in a number of ways:

    ' 1) Read-only by reading the tag's unique, non-changing serial number

    ' 2) Read/write up to 116 bytes of user data (publicly accessible)

    ' 3) Read/write up to 116 bytes of user data (password protected)





    '
    [ I/O Definitions ]



    RFID_TX PIN 0 ' Connects to RFID R/W Module SIN

    RFID_RX PIN 1 ' Connects to RFID R/W Module SOUT





    '
    [ Constants ]



    #SELECT $STAMP

    #CASE BS2, BS2E, BS2PE

    T9600 CON 84

    #CASE BS2SX, BS2P

    T9600 CON 240

    #ENDSELECT



    Baud CON T9600



    ' RFID R/W Module Commands

    ' Number of bytes returned in ()

    RFID_Read CON $01 ' Read data from specified address, valid locations 1 to 33 (5)

    RFID_Write CON $02 ' Write data to specified address, valid locations 3 to 31 (1)

    RFID_Login CON $03 ' Login to tag with password (1)

    RFID_SetPass CON $04 ' Change tag's password from old to new (1)

    RFID_Protect CON $05 ' Enable/disable password protection (1)

    RFID_Reset CON $06 ' Reset tag (1)

    RFID_ReadLegacy CON $0F ' Read unique ID from EM4102 read-only tag (for backwards compatibility with Parallax RFID Card Reader, #28140 and #28340) (12)



    ' Memory map/address locations for EM4x50 tag

    ' Each address holds/returns a 32-bit (4 byte) value

    ADDR_Password CON 0 ' Password (not readable)

    ADDR_Protect CON 1 ' Protection Word

    ADDR_Control CON 2 ' Control Word

    ' ADDR 3-31 are User EEPROM area

    ADDR_Serial CON 32 ' Device Serial Number

    ADDR_DeviceID CON 33 ' Device Identification



    ' Status/error return codes

    ERR_OK CON $01 ' No errors

    ERR_LIW CON $02 ' Did not find a listen window

    ERR_NAK CON $03 ' Received a NAK, could be invalid command

    ERR_NAK_OLDPW CON $04 ' Received a NAK sending old password (RFID_SetPass), could be incorrect password

    ERR_NAK_NEWPW CON $05 ' Received a NAK sending new password (RFID_SetPass)

    ERR_LIW_NEWPW CON $06 ' Did not find a listen window after setting new password (RFID_SetPass)

    ERR_PARITY CON $07 ' Parity error when reading data





    '
    [ Variables ]



    buf VAR Byte(12) ' data buffer



    idx VAR Byte ' index

    idy VAR Byte



    '
    [ EEPROM Data ]





    '
    [ Initialization ]



    Initialize:

    PAUSE 250 ' let DEBUG open

    DEBUG CLS ' clear the screen

    DEBUG "Parallax RFID Read/Write Module Demo Application", CR,

    "
    ", CR, CR





    '
    [ Program Code ]



    Main:

    ' Code blocks can be commented/uncommented/rearranged to

    ' experiment with the available features and operations of the

    ' Parallax RFID Read/Write Module



    ' DEBUG "Reading tag's unique serial number..."

    ' Read_Tag:

    ' SEROUT RFID_TX, Baud, ["!RW", RFID_Read, ADDR_Serial] ' Read tag's serial number

    ' SERIN RFID_RX, Baud, [STR buf\5] ' Get status byte and data bytes

    ' IF buf(0) <> ERR_OK THEN Read_Tag ' If we get an error, keep trying until the read is successful

    ' FOR idx = 1 TO 4 ' Print data

    ' DEBUG HEX2 buf(idx)

    ' NEXT

    ' DEBUG CR



    DEBUG "Reading Legacy tag's unique serial number..." ' Read unique ID from EM4102 read-only tag

    Read_Legacy:

    SEROUT RFID_TX, Baud, ["!RW", RFID_ReadLegacy]

    SERIN RFID_RX, Baud, [STR buf\12] ' Get header and data

    IF buf(0) <> $0A THEN Read_Legacy ' If we don't receive the correct header, keep trying until we do

    FOR idx = 1 TO 10 ' Display the data (ignore final \r byte sent by the reader)

    DEBUG buf(idx)

    NEXT

    DEBUG CR



    DEBUG "Writing and verifying data to tag..."

    Write_Tag:

    ' SEROUT RFID_TX, Baud, ["!RW", RFID_Write, 3, $FE, $ED, $BE, $EF] ' Write $FEEDBEEF into address 3 (user EEPROM area)

    SEROUT RFID_TX, Baud, ["!RW", RFID_Write, 3, $FF, $EE, $BB, $EE]

    SERIN RFID_RX, Baud, [buf(0)] ' Wait for status byte

    IF buf(0) <> ERR_OK THEN Write_Tag ' If we get an error, keep trying until the write is successful

    DEBUG "Done!", CR



    DEBUG "Reading tag's entire memory contents:", CR

    FOR idy = 1 TO 33

    Read_Tag2:

    SEROUT RFID_TX, Baud, ["!RW", RFID_Read, idy] ' Read data from address location "idy"

    SERIN RFID_RX, Baud, [STR buf\5] ' Get status byte and data bytes

    IF buf(0) <> ERR_OK THEN Read_Tag2 ' If we get an error, keep trying until the read is successful

    DEBUG DEC2 idy, ": "

    FOR idx = 1 TO 4 ' Print data

    DEBUG HEX2 buf(idx)

    NEXT

    DEBUG CR ' Repeat for address locations 1 to 33

    NEXT



    ' Login is only required to take advantage of the password protection features

    ' e.g., set the tag's password, lock/unlock the tag, or read/write the tag (if tag is locked)

    DEBUG "Logging into the tag..."

    Login:

    SEROUT RFID_TX, Baud, ["!RW", RFID_Login, REP $00\4] ' Login to tag with default password of $00000000

    SERIN RFID_RX, Baud, [buf(0)] ' Wait for status byte

    IF buf(0) <> ERR_OK THEN Login ' If we get an error, keep trying until login is successful

    DEBUG "Done!", CR



    DEBUG "Changing tag's password..."

    Set_Pass:

    SEROUT RFID_TX, Baud, ["!RW", RFID_SetPass, REP $00\4, REP $00\4] ' Change password from old ($00000000) to new ($00000000)

    SERIN RFID_RX, Baud, [buf(0)] ' Wait for status byte

    IF buf(0) <> ERR_OK THEN Set_Pass ' If we get an error, keep trying until the password change is successful

    DEBUG "Done!", CR



    DEBUG "Locking tag..."

    Lock_Tag:

    SEROUT RFID_TX, Baud, ["!RW", RFID_Protect, 1] ' Enable read/write password protection of the entire tag

    SERIN RFID_RX, Baud, [buf(0)] ' Wait for status byte

    IF buf(0) <> ERR_OK THEN Lock_Tag ' If we get an error, keep trying until the function is successful

    DEBUG "Done!", CR



    DEBUG "Unlocking tag..."

    Unlock_Tag:

    SEROUT RFID_TX, Baud, ["!RW", RFID_Protect, 0] ' Disable read/write password protection of the entire tag

    SERIN RFID_RX, Baud, [buf(0)] ' Wait for status byte

    IF buf(0) <> ERR_OK THEN Unlock_Tag ' If we get an error, keep trying until the function is successful

    DEBUG "Done!", CR



    DEBUG "Resetting the tag..."

    Reset_Tag:

    SEROUT RFID_TX, Baud, ["!RW", RFID_Reset] ' Log out and reset the tag (will require a re-login if trying to access a locked tag after this point)

    SERIN RFID_RX, Baud, [buf(0)] ' Wait for status byte

    IF buf(0) <> ERR_OK THEN Reset_Tag ' If we get an error, keep trying until the function is successful

    DEBUG "Done!", CR



    DEBUG "
    ", CR

    PAUSE 1000

    GOTO Main ' Do it all over again!

    END



    '
    [ End of File ]
  • stamptrolstamptrol Posts: 1,731
    edited 2010-12-20 10:02
    So, having the code set for the right processor made all the difference?! ;-)
Sign In or Register to comment.