Shop OBEX P1 Docs P2 Docs Learn Events
RS-232 Communication with Fingerprint Module — Parallax Forums

RS-232 Communication with Fingerprint Module

willhclamwillhclam Posts: 3
edited 2006-03-12 14:30 in BASIC Stamp
Hello everyone. I am new to microcontrollers and have just started working on my project 2 weeks ago. I am having a lot of trouble with the SERIN and SEROUT commands, espeicially SERIN.

Goal: To send a command and receive the acknowledgement to and from a 3rd party fingerprint module.

Components: BS2p24
·················· FIM01 Fingerprint Module from http://www.ravirajtech.com/fim01.html

Command to initate connection at 9600bps:
7E 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
(header [noparse][[/noparse]2 hex], command [noparse][[/noparse]8 hex], parameter 1 [noparse][[/noparse]8 hex], parameter 2 [noparse][[/noparse]8 hex], data size [noparse][[/noparse]8 hex], error code [noparse][[/noparse]8 hex],·check sum [noparse][[/noparse]8 hex])

Acknowledgement packet I should recieve if connected successfully:
7E 00 00 00·33 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34
(same format as the command)

The following is my stripped down code. All I want is to send a 25-byte command to initiate connection at 9600bps with a SEROUT command. In turn, I should get a 25-byte packet back in HEX.

' {$STAMP BS2p}
' {$PBASIC 2.5}
'pins 0 - 7 are inputs
'pins 8 - 15 are outputs
DIRL = %00000000
DIRH = %11111111
' Counter stored in EEPROM location 0
DATA @100, 0
' Inputs - scanning button, reset button, master reset button, success, failure
main_button VAR IN0
Zero VAR Byte
Zero = $0000
Feedback1 VAR Byte(10)
Main:
· GOSUB Initialization
END
Initialization:
· SEROUT 16, 84, [noparse][[/noparse]$7E, Zero, $0001, Zero, Zero, Zero, Zero, Zero, Zero, Zero, Zero, Zero, $0001]·· 'Initialize serial communication
· SERIN 16, 84, [noparse][[/noparse]Feedback1]
· DEBUG [noparse][[/noparse]Hex Feedback1]·· 'I am not getting anything from the Feedback1 command
RETURN

I understand that I have declared my feedback to be 10-byte only. This is because 25-byte is too big for BS2p to handle. Anyway, I would be really happy to get some kind of feedback from the fingerprint module. Should I "pace" my SERIN or SEROUT? I know I have sent something in via the oscilloscope, but I don't know if the fingerprint module could get the signal also. PLEASE HELP HELP HELP!

Project is due for school very very school. Your help is VERY VERY MUCH appricated! tongue.gif

Best regards,
William

Comments

  • FORDFORD Posts: 221
    edited 2006-03-12 00:51
    I suggest you either search here or have a look in the help for the SPSTR function which is a part of the Serin command, for BS2P. It simply stores the serial data coming in, into RAM starting at address 0.

    If you combine that with the WAIT instruction, and WAIT for the first byte 7E (if that is always sent first)

    After that, you have all the time you want, to view the bytes from RAM that were sent by the fingerprint thingy.

    You really need to look at the SPSTR and WAIT functions, and then you should be OK.

    somethink like (off the top of my head)...

    debug cls, "waiting for data"
    serin 16, 84,[noparse][[/noparse]WAIT ($7E), SPSTR 24]
    debug cr, "data received", cr

    should put the serial data following the byte 7E into RAM locations 0 - 23, where you can look at them later with something like...

    data_in var byte
    counter var byte
    for counter = 0 to 23
    get counter, data_in
    debug hex data_in, CR
    next
    END

    Cheers,
    Chris

    BTW - You also have a note saying you have a counter stored at Eeprom location 0, your code says it is puyting the value 0 into location 100.
  • willhclamwillhclam Posts: 3
    edited 2006-03-12 01:43
    Hello Chris,

    Thanks for your quick reply. I tried what you suggested and this is what I put on my program:

    SEROUT 16, 84, [noparse][[/noparse]$7E, Zero, $0001, Zero, Zero, Zero, Zero, Zero, Zero, Zero, Zero, Zero, $0001]·· 'Initialize serial communication
    DEBUG CLS, "waiting for data"
    SERIN 16, 84, [noparse][[/noparse]WAIT ($7E), SPSTR 24]
    FOR counter=0 TO 23
    ·· GET counter, data_in
    ···DEBUG HEX data_in, CR

    From the debug window, I got "waiting for data", but not anything after the SERIN function. I tried to output something simple (ex. "Data received"), however, nothing comes up.

    Thanks once again!

    William
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-03-12 01:44

    AK1 VAR Byte            ' reserved for $33 (ascii three)
    AK2 VAR Byte            ' reserved for $01 (ascii soh)
    AK3 VAR Byte            ' reserved for $34 (ascii four)
     
     
    Verify:
      SEROUT 16, 84, [noparse][[/noparse]$7E,$00,$00,$00,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01]
     
      SERIN 16, 84, [noparse][[/noparse]WAIT ($7E),SKIP 3,STR AK1\1,SKIP 3,STR AK2\1,SKIP 15,STR AK3\1]
    
      IF (AK1 = $33) AND (AK2 = $01) AND (AK3 = $34) THEN COMMOK
    
      GOTO Verify           'COMM was NOT OK, try again or re-INIT (?)
    
    COMMOK:
      END                   'Replace with your Debug subroutine
    



    Post Edited (PJ Allen) : 3/12/2006 2:22:08 AM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-03-12 03:47
    William -

    Are you sure your BAUDMODE (84) is correct for that input device? My guess is it should be a BAUDMODE of 240 which represents: 9600, 8, N, 1 . A BAUDMODE of 84 makes sense on slower BS-2's but not for the BS-2p.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->

    Post Edited (Bruce Bates) : 3/12/2006 4:30:06 AM GMT
  • FORDFORD Posts: 221
    edited 2006-03-12 05:32
    Also, There could be a problem with...

    SEROUT 16, 84, [noparse][[/noparse]$7E, Zero, $0001, Zero, Zero, Zero, Zero, Zero, Zero, Zero, Zero, Zero, $0001] 'Initialize serial communication
    DEBUG CLS, "waiting for data"
    SERIN 16, 84, [noparse][[/noparse]WAIT ($7E), SPSTR 24]

    Where the Debug is after serout and before serin. The byte $7E (and some more bytes) might be coming back while the debug string is being sent to your pc.

    Try this...
    DEBUG CLS, "waiting for data"
    SEROUT 16, 84, [noparse][[/noparse]$7E, Zero, $0001, Zero, Zero, Zero, Zero, Zero, Zero, Zero, Zero, Zero, $0001] 'Initialize serial communication
    SERIN 16, 84, [noparse][[/noparse]WAIT ($7E), SPSTR 24]
    Debug CR, "Received data", CR
    FOR counter=0 TO 23
    GET counter, data_in
    DEBUG HEX data_in, CR
    next
    end

    Also, as Bruce said, be sure to make sure the baud rate is OK.
  • FORDFORD Posts: 221
    edited 2006-03-12 05:36
    Sorry, you could also do it this way to see if you are getting anything back at all...

    DEBUG CLS, "waiting for data"
    SEROUT 16, 84, [noparse][[/noparse]$7E, Zero, $0001, Zero, Zero, Zero, Zero, Zero, Zero, Zero, Zero, Zero, $0001] 'Initialize serial communication
    SERIN 16, 84, [noparse][[/noparse]SPSTR 6] 'or any other number lower than 24
    Debug CR, "Received data", CR
    FOR counter=0 TO 5
    GET counter, data_in
    DEBUG HEX data_in, CR
    next
    end

    This will just show you the 6 bytes it receives, at least showing you what is coming back.
    It should also show you what the first byte is that is is receiving.
  • FORDFORD Posts: 221
    edited 2006-03-12 05:50
    Also william,
    Are you aware that when you serout - - - $0001, you are sending 2 bytes of data (a word), not one ?
    Is it possible that you should be sending $01 as a byte ?


    Check the string that you need to send carefully.
    Check the baudrate carefully.

    I would also use hyperterminal to test what is being sent.
  • willhclamwillhclam Posts: 3
    edited 2006-03-12 06:34
    Hello Ford, Bruce, and PJ,

    Thank you very much for your valuable advice. I have been trying to get this thing working but still no luck. You are right Bruce, the baud rate should be 240, not 84.

    Ford, I have attached a PDF file, showing an example of how the initialization should be done. I believe I have to send in $0001 instead of $01. The following is my latest code, incorporating advices from you guys.

    AK1 VAR Byte······ ··· ·' reserved for $01 (ascii soh)
    AK2 VAR Byte······ ··· ·' reserved for $01 (ascii soh)
    AK3 VAR Byte·········· ·' reserved for $0A (ascii LF)

    Initialization:
    ··SEROUT 16, 240, [noparse][[/noparse]$7E,$00,$00,$00,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01]
    · SERIN 16, 240, [noparse][[/noparse]WAIT ($7E),SKIP 3,STR AK1\1,SKIP 3,STR AK2\1,SKIP 3,STR AK3\1]
    · DEBUG "SERIN finished", CR
    · IF (AK1 = $01) AND (AK2 = $01) AND (AK3 = $0A) THEN COMM_OK

    COMM_OK:
    · DEBUG "SERIN is working perfectly! Thanks guys!", CR
    · END


    Unfortunately, I cannot get into the COMM_OK routine. Actually, I can't even get the "SERIN finished" to show up on the screen. It's 1:33AM and I am getting really frustrated in the lab at school... but I really appreciate help from you guys! Thanks soooo much!

    Best regards,
    William
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-03-12 07:20
    William -

    Swing the entire thing over to pin port 15 (or some other pin port), rather than using pin port 16. See if that helps. Pin port 16 I/O and DEBUG use the same pin!

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-03-12 14:30
    Bruce Bates, you are absotootley right.· You can't DEBUG and run a device with the programming port at the same time.

    I rarely DEBUG.· Often, I have the STAMP turn on an LED for me, instead.

    So, willhclam, if you want to run the gizmo using SERIN/SEROUT 16 and you don't have a MAX232 at the ready, then set up a couple of LEDs as Status Indicators.
Sign In or Register to comment.