Shop OBEX P1 Docs P2 Docs Learn Events
CODE .... How to Serial in TTL 8-N-1 ??? — Parallax Forums

CODE .... How to Serial in TTL 8-N-1 ???

Jeff_5_Jeff_5_ Posts: 36
edited 2011-04-11 20:12 in BASIC Stamp
I have an rfid reader that is reading my tag and im trying to input it in to my Basic stamp. The code of the Tag is 1nKq101 with the last one being a space character. I was told the data is in the form of 8-N-1 TTL non inverted output.. My question is what kind of code do i need to read this in to my basic stamp and display it on the screen?

Comments

  • bsnutbsnut Posts: 521
    edited 2011-03-07 18:10
    Ok, welcome to the forums.

    I would suggest you to post the code you are working with so we can better help you. Are you using the Parallax RFID reader and are you using the demo code that came with it?
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-03-07 18:24
    TagID Dec BIt
    main:

    SERIN 1,84,[WAIT(TagID), Dec TagID]

    PAUSE 100
    DEBUG Dec TagID , CR
    PAUSE 100
    GOTO main

    Thats is and all im getting is 0 and 1s i think i need to convert to ASCII
  • FranklinFranklin Posts: 4,747
    edited 2011-03-07 18:28
    If you go here http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/rfid/List/0/SortField/4/ProductID/114/Default.aspx look in the downloads and resources section for BS2 source code.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-03-08 10:12
    Use this and see if you can read your tags

    ' =========================================================================
    '
    '   File....... RFID_basic.BS2
    '   Purpose.... RFID Tag Reader
    '   Author..... (c) Parallax, Inc. -- All Rights Reserved
    '   E-mail..... [EMAIL="support@parallax.com"]support@parallax.com[/EMAIL]
    '   Started....
    '   Updated.... 02 Mar 2005
    '
    '   {$STAMP BS2}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    
    ' -----[ Program Description ]---------------------------------------------
    '
    ' Reads tags from a Parallax RFID reader and displays ID to debug screen
    
    ' -----[ Revision History ]------------------------------------------------
    
    ' -----[ I/O Definitions ]-------------------------------------------------
    Enable          PIN     0                       ' low = reader on
    RX              PIN     1                       ' serial from reader
     
    ' -----[ Constants ]-------------------------------------------------------
    #SELECT $STAMP
      #CASE BS2, BS2E, BS2PE
        T2400       CON     396
      #CASE BS2SX, BS2P
        T2400       CON     1021
      #CASE BS2PX
        T2400       CON     1646
    #ENDSELECT
    Baud            CON     T2400
    LastTag         CON     3
    
    #DEFINE __No_SPRAM = ($STAMP < BS2P)            ' does module have SPRAM?
    
    ' -----[ Variables ]-------------------------------------------------------
    #IF __No_SPRAM #THEN
      buf           VAR     Byte(10)                ' RFID bytes buffer
    #ELSE
      Char       VAR     Byte                    ' character to test
    #ENDIF
    tagNum          VAR     Nib                     ' from EEPROM table
    idx             VAR     Byte                    ' tag byte index
     
    ' -----[ Initialization ]--------------------------------------------------
    Reset:
      HIGH Enable                                   ' turn of RFID reader
     
    ' -----[ Program Code ]----------------------------------------------------
    Main:
      LOW Enable                                    ' activate the reader
      #IF __No_SPRAM #THEN
        SERIN RX, T2400, [WAIT($0A), STR buf\10]    ' wait for hdr + ID
      #ELSE
        SERIN RX, T2400, [WAIT($0A), SPSTR 10]
      #ENDIF
      HIGH Enable                                   ' deactivate reader
    Display_Tag:
      DEBUG "Tag Identification number is: ", CR
        FOR idx = 0 TO 9                            ' scan bytes in tag
          #IF __No_SPRAM #THEN
            DEBUG buf(idx)
          #ELSE
            GET idx, Char                        ' read char from SPRAM
            DEBUG Char
          #ENDIF
        NEXT
      DEBUG CR
      PAUSE 500
      GOTO main    
    
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-03-09 17:10
    I am not using the Paralax reader. I have used that code before and made the parallax reader work but i have upgraded to a better reader.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-09 17:18
    If you're using some other reader, then the only thing that we can tell you is that a SERIN should be able to read TTL 8-N-1 non-inverted data. Look in the Stamp Manual chapters on SERIN and SEROUT for the values for the Baud your reader uses. If you provide a link for the datasheet or manual for your reader, we may be able to offer more specific advice.
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-04-04 12:40
    http://www.ananiahelectronics.com/RF9315R.htm
    This is the reader I am using
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-04 16:05
    That link says the -R has a RS232 output.
    So, the Stamp should be set for INVERTED baudmode.
    And you need to place a 22KΩ resistor between the
    -R's output and the Stamp's input pin.
    (If you use/have a MAX232 between the two then you'd set
    the Stamp up for a TRUE baudmode.)
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-04-06 07:41
    PJ Allen wrote: »
    That link says the -R has a RS232 output.
    So, the Stamp should be set for INVERTED baudmode.
    And you need to place a 22KΩ resistor between the
    -R's output and the Stamp's input pin.
    (If you use/have a MAX232 between the two then you'd set
    the Stamp up for a TRUE baudmode.)

    So I can get the data from the reader to the stamp with rs232? I was told it would be Easyier to get the data out in ttl form before its converted to rs232
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-06 08:09
    If you know how to do that then do that. There are 'True' Baudmodes, too. Do what you were told, what's "Easyier", I don't care.
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-04-06 17:36
    Ok Well i have found where the data is still TTL but my problem is i dont know what code to use to read it in and print it to the screen.
  • Mike GMike G Posts: 2,702
    edited 2011-04-06 17:49
    Mike Green wrote:
    If you're using some other reader, then the only thing that we can tell you is that a SERIN should be able to read TTL 8-N-1 non-inverted data. Look in the Stamp Manual chapters on SERIN and SEROUT for the values for the Baud your reader uses.

    Use DEBUG to write data to the terminal window. Please read the STAMP manual.
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-04-07 16:53
    I know that i am having trouble with the Serin statement. I think my baud rate should be 9600 and its reading but its prints symbols and random stuff i cant get it to print the tag code is ASCII
  • Mike GMike G Posts: 2,702
    edited 2011-04-07 17:39
    Are you still using this? Because It does not compile.
    TagID DEC Bit
    main:
    
    SERIN 1,84,[WAIT(TagID), DEC TagID]
    
    PAUSE 100
    DEBUG DEC TagID , CR
    PAUSE 100
    GOTO main
    

    In the current context, this line of code, assuming you mean TagID VAR Byte...
    SERIN 1,84,[WAIT(TagID), DEC TagID]
    
    waits for the value in TagID to show up on pin 1 but TagID is not initialized so it's nothing or zero. When SERIN sees zero on pin 1 (84 is 9600 baud for a BS2) it puts whatever decimal value received on pin 1 in TagID. Now TagID is initialized with some arbitrary value and the whole thing starts over again.

    If you still need help post your latest code. What kind of STAMP are you using?
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-04-09 08:25
    Mike G wrote: »
    Are you still using this? Because It does not compile.
    TagID DEC Bit
    main:
    
    SERIN 1,84,[WAIT(TagID), DEC TagID]
    
    PAUSE 100
    DEBUG DEC TagID , CR
    PAUSE 100
    GOTO main
    

    In the current context, this line of code, assuming you mean TagID VAR Byte...
    SERIN 1,84,[WAIT(TagID), DEC TagID]
    
    waits for the value in TagID to show up on pin 1 but TagID is not initialized so it's nothing or zero. When SERIN sees zero on pin 1 (84 is 9600 baud for a BS2) it puts whatever decimal value received on pin 1 in TagID. Now TagID is initialized with some arbitrary value and the whole thing starts over again.

    If you still need help post your latest code. What kind of STAMP are you using?

    I kind of understand what your saying. I am on the BS@ homework board. I want to read in the tag id and set it all in one variable
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-09 08:38
    The Stamps, particularly the BS2 which is used on the Homework Board, are not reliable at 9600 Baud and above, particularly when you use complex SERIN "formatters" like WAIT. You're also not going to get the results you expect with the DEC formatter because the Stamps use 16-bit arithmetic and an RFID tag presents numbers much larger than 16 bits. Look at the examples provided for Parallax's RFID reader and adapt them. They read the RFID number into an array of bytes. You can then manipulate the data further.
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-04-10 17:53
    ok this is about ot drive me crazy. No matter what i do to try to read in my data and print it all i get is stupid random symbols. I dont really understand the whole TTL 8-N-1. I have been reading about it but its confusing at times. I just need to readin the tag and print it i nthe form of 1nKq.

    For some reason i think i need something like

    TagID Var Byte(4)

    SERIN 1,84,[WAIT($0A), STR TagID\4] Which is read on pin1 at baud rate 9600(84) then wait command and then read in to a string of 4 spots.

    Then

    Debug STR TagID

    I get random symbols and i dont understand why.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-10 18:16
    You really can't use the "WAIT($0A)" because there's no $0A byte in the data stream. There's only 4 arbitrary characters followed by a space.

    I think if I were trying to use this thing, I'd write the program to monitor the receive data line in a loop looking for maybe 2 seconds of mark (1) starting the timing over if any space (0) is received. Once I found 2 seconds of uninterrupted mark, I'd know that there's about 1/2 second until the next ID is to be received. I'd start the SERIN at that point. The Stamp would hang waiting for 4 bytes to be received, and I'd know that I'm not trying to receive somewhere in the middle of an ID sequence. I'd probably receive 5 bytes and actually check for a space as the 5th byte.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-10 18:37
    Instead of Debug STR TagID, what results with --
    DEBUG CR
    DEBUG HEX2 TagID(0), CR
    DEBUG HEX2 TagID(1), CR
    DEBUG HEX2 TagID(2), CR
    DEBUG HEX2 TagID(3), CR
    END
    
    ? ? ?
    Consistent #s?

    PE --
    $0A means you're waiting for a Line Feed.
    Your device generates a Line Feed as the 1st character in its output series?
    I don't want to read about it, but you can tell me/us about it.

    Say it is.
    Change it to --
    SERIN 1,84,[STR TagID\4]
    DEBUG CR
    DEBUG HEX2 TagID(0), CR
    DEBUG HEX2 TagID(1), CR
    DEBUG HEX2 TagID(2), CR
    DEBUG HEX2 TagID(3), CR
    END
    
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-04-10 20:09
    PJ Allen wrote: »
    Instead of Debug STR TagID, what results with --
    DEBUG CR
    DEBUG HEX2 TagID(0), CR
    DEBUG HEX2 TagID(1), CR
    DEBUG HEX2 TagID(2), CR
    DEBUG HEX2 TagID(3), CR
    END
    
    ? ? ?
    Consistent #s?

    PE --
    $0A means you're waiting for a Line Feed.
    Your device generates a Line Feed as the 1st character in its output series?
    I don't want to read about it, but you can tell me/us about it.

    Say it is.
    Change it to --
    SERIN 1,84,[STR TagID\4]
    DEBUG CR
    DEBUG HEX2 TagID(0), CR
    DEBUG HEX2 TagID(1), CR
    DEBUG HEX2 TagID(2), CR
    DEBUG HEX2 TagID(3), CR
    END
    

    With this code i get a return of four two digit numbers and letter but no more symbols.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-10 20:40
    Are they the same numbers each time? What are they?
    Why do I have to pry the information from you?
    Help me help you, Jeff_5_.

    Participate, Contribute, Fill Your Boots, My Brother.
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-04-11 14:58
    Yea sorry about that i was in a hurry when i posted last. Anyway no my data is not the same meaning i still have problems.

    This is what i get after reading 3 times.

    28
    60
    11
    21

    FF
    00
    18
    30

    00
    84
    00
    00

    Nothing even seem similar. Now im starting to questions the location of my data output from the reader.

    one more thing i forgot to mention. The reader has an RSSI vale also. Almost like a distance meter. So the output from the read is the tag code being 1nKq the a 3 digit number and a space

    Ex 1nKq103_
    1nKq83__
    underscores represent spaces.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-11 15:59
    I appreciate all that.

    You need a voltmeter --
    If the data is "TTL true" then that data pin should be HI when it's idle (doing nothing), the start bit will be 0/GND.
    The data out pin of the RS232 (pin_2, assuming it's female), which you ought to be using but won't, should
    be some negative voltage (-5-12V) when the unit is idle.
    Can you confirm?

    The "ananiha" people don't provide any schematic at the link, so I don't know if they're using a level shifter or using the ol' series resistor gimmick themselves (which I hate.) If they have some means of providing a negative voltage then that pin_2 should go negative; otherwise it'll just go to 0/Gnd in the inactive state (the start bit is a negative voltage.)
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-04-11 17:11
    ok it seems the only time i have any voltage to any of my rs232 pins is when a serial cable is hooked to the reader and the computer. Then on pin 2 i have -10v and pin 3 +10v. An rs232 db9 pin out shows pin 2 as received date pin 3 as transmitted data. As for the TTL i think have the right pin its is 0 volts as soon as the battery is put in the tag then it goes to 1.3v and varies from 1-1.5v
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-11 17:48
    Pin3 of the male/PC is TX data, so with a serial extension cable it goes to Pin3 on the RFIDconn, if it presents a female conn. If the RFID has a male conn then it's null modem. I have no item specific details, just the picture of the top of the device in the link.

    Anyway, I guess we can presume that you found the TTL pin to pick off.

    RF8315T -- "An unique 4 characters (A-Z, a-z, 0-9) will be sent out on every 2.5 seconds plus/minus 0.5 second. "

    Maybe expanding your buffer will help you capture more info/data and thereby find what the scoop is.
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-04-11 18:35
    ok i emailed the manufacturer and he said i should be using pin 7 on the onboard IC where the pin output is TTL RS232 data. I believe i have the right pin but still no good.

    Here is the result now

    00
    80
    FF
    FF
    02
    00
    00
    06
    00
    00
    00
    FF

    00
    00
    03
    08
    02
    FE
    37
    40
    00
    02
    3F
    02

    00
    02
    00
    FF
    31
    00
    00
    FC
    FF
    20
    00
    FC

    i copy and pasted the copy you typed in your last reply and ran it and this is what i get. I just dont understand it should be the same every time.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-11 18:58
    Well, mate, I was hoping to find a pattern, but there's nothing obvious.
    Have you tried the Inverted baudmode for grins & giggles?

    If that device has a female connector on it, can you plug it onto your serial extender
    [PC] and get any intelligence on Hyperterminal (or other terminal program)?
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2011-04-11 19:08
    yea i have had it rummimg hyperterminal a few times. thats how i know the code ot my tag is 1nKq. How do i try inverted baud mode?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-04-11 20:12
    The Inverted baudmode for 9600 8N1 is 16468 (there's a table in PBASIC Help)
    SERIN 1,16468,[STR TagID\x]
    (x = however many bytes in your array)

    PE -- Note my corrections in #24: TTL IDLE is HI, start bit (active) is 0/GND; 232 IDLE is LO/V_neg, start bit (active) is V_pos. I'm ripping myself a new one.
Sign In or Register to comment.