View previous topic :: View next topic |
Author |
Message |
Depner Guest
|
Fingerprint sensor RS232 communication |
Posted: Mon Apr 14, 2008 12:49 pm |
|
|
Hi All!
I'm asking for a little help. I want to creatre a fingerprint-codelock with a DFZ-2002S Fingerptint recognition module.
I'm totally new in RS-232 communication with PICs.
So the task would be as follows:
1.) Send out a command to the module via RS-232, which is asking the version number. As by the datasheet this is: 0x1b 0x5e 0xa0 ax00 ax00
Am I doing this right this way?:
Code: | int8 data[] = {0x1b, 0x5e, 0xa0, 0x00, 0x00};
for(i = 0; i < sizeof(data); i++)
{
putc(data[i]);
} |
And the module should answer:
0x1b 0x5e 0xa1 VERH VERL
where VERH is first position of the firmware version, VERL is the second.
I'm doing it like this:
Code: | char string[6];
gets(string);
printf(lcd_putc,"\n%x",string); |
but not working. Just freezing.
The program head:
Code: | #include <16f877.h>
#device ICD=TRUE
#use delay(clock=4 MHZ)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7, bits=8, ERRORS)
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, DEBUG
#include <stdio.h>
#include <llcd_new.h>
#define DFP_RESET PIN_C5 |
Please help me in this topic.
Thanks in advance!
Depner |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 14, 2008 1:15 pm |
|
|
Quote: | but not working. Just freezing. |
Look in the CCS manual, in the section on the gets() function.
http://www.ccsinfo.com/downloads/CReferenceManual.pdf
It says:
Quote: |
Reads characters (using GETC()) into the string until a RETURN
(value 13) is encountered. The string is terminated with a 0.
Note that INPUT.C has a more versatile GET_STRING function. |
If the device never sends a carriage return character (0x0D),
your program will appear to freeze. |
|
|
Depner Guest
|
|
Posted: Mon Apr 14, 2008 1:52 pm |
|
|
Ohh, thanks. That's true, it never does. Then how to solve? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 14, 2008 2:03 pm |
|
|
The cheap way, just to get you going, is to create a for() loop that calls
the getc() function 5 times. Use the counter in the for() loop as an
index into your data array. Store the value received from getc() into
the array.
For the real version, you would want to create a routine called
"get_isd_response()", for example. You would call it with a pointer
to your result array. The function would do an internal timeout
check. If it doesn't receive a response within a certain amount
of time, the function would return FALSE. If it does get all the data
from the ISD chip within the alloted time, then it would return TRUE.
You could look at the timed_getc() function for some ideas of how
to do this.
Quote: | c:\program files\picc\examples\ex_tgetc.c |
|
|
|
Depner Guest
|
|
Posted: Mon Apr 14, 2008 2:22 pm |
|
|
I did this:
Code: | for(i=0;i<5;i++)
{
c=getc();
string[i]=c;
}
|
And it is halting at i=2.
Sometimes it is going up to 3, but not more.
Theoretically my routine to give the command is OK? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 14, 2008 2:27 pm |
|
|
Post a link to the data sheet for the DFZ-2002S device. |
|
|
Depner Guest
|
|
Posted: Mon Apr 14, 2008 2:38 pm |
|
|
Here is the link:
h**p://w*w.datasheetarchive.c*m/preview/1194375.h**l |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 14, 2008 2:45 pm |
|
|
If you register and login, then you can do links.
http://www.datasheetarchive.com/pdf/1194375.pdf
This is a 3.3v device. Are you running your PIC at +3.3v ?
Also, the baud rate is given as 38,400 baud. That's on page 5 of the
data sheet. |
|
|
Depner Guest
|
|
Posted: Mon Apr 14, 2008 2:53 pm |
|
|
Surely I will register now...
I'm running on 5 V, because it says: Interface: RS-232(TTL Level). (page 2.) Maybe I'm not wrong with this.
I've got another datasheet, but received only via mail from the colleague whom I got the device. He got it from the supplyer. It says 9600 baud standartd, but the user can vary. I'll try to put the original pdf somewhere on the net tomorrow. (Here in Hungary it 22:45 now..)
Thank you for your help. I will post somehow the original .pdf. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 14, 2008 2:57 pm |
|
|
The PIC and the device should be running at the same voltage.
The data sheet that you posted has a table of the pin numbers
on page 5. Here's the first part of it. It shows Vcc is +3.3v.
Maybe your new data sheet shows it is different ?
Code: |
RS-232 Connector
Pin
No. Symbol
1 VCC(+3.3v) |
|
|
|
Depner Guest
|
|
Posted: Mon Apr 14, 2008 2:59 pm |
|
|
No, it's 3.3 V. But despite it is said, that TTL levels are on the RS232, I have to use 3.3 V PIC? Or some transciever..? |
|
|
Depner Guest
|
|
Posted: Mon Apr 14, 2008 3:04 pm |
|
|
It's exactly as follows:
G. Serial Connector
Pin number Symbol
1 VCC(+3.3V)
2 RXD
3 TXD
4 Reset
5 GND
Serial Interface (TTL Level)
Baud rate: 9,600 BPS (It is able to be changed with ver 1.5) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 14, 2008 3:15 pm |
|
|
Well, yes.
If your PIC is running at +5v Vdd, then the hardware UART pins
expect and produce +5v CMOS levels. This is in the PIC data sheet,
in the Electrical Characteristics section (near the end of the data sheet).
The PIC will put out probably at least 4.5v as the high level on the Tx pin.
I don't see anything in the DFZ-2002S about 5v tolerant inputs, so it's
possible that you have already damaged the device. But you can test it
and find out. On the Rx input pin of the PIC's hardware UART, it expects
CMOS input levels, which is a Vih (input high-level voltage) of 4.0 volts.
Your DFZ unit can't do that, since it's running at 3.3v.
You could use level converter chips. One cheap way to do it would be
to use a software UART on Port B, which has TTL level input pins.
Then use a voltage divider circuit on the Tx pin of the PIC, to reduce the
output voltage going to the DFZ device so that it's within 3.3v CMOS levels.
But it's preferable to use the hardware UART, so you might want to run
the PIC at +3.3v if you can. Make sure you change the Brownout fuse
to NOBROWNOUT if you do that. The brownout voltage is only set to
work properly if the 16F877 is running at 5v. You have to disable it
if you run it at 3.3v. |
|
|
Depner
Joined: 15 Apr 2008 Posts: 4 Location: Hungary
|
|
Posted: Tue Apr 15, 2008 1:22 am |
|
|
Hi PCM programmer!
Then I was really wrong. I thought, that "TTL Levels" means I can directly connect it to the PIC, because some level converter is integrated on the device.
I hope I didn't burnt it down. I will test it, at least I can test the TX of the device. Simply giving a HW reset, and watching the TX pin with a scope. (Sending out the Firmware ver. after reset.) If there is communication, then only the RX should be dead.
I've already ordered some MAX3232, I will use this level converter. I've got another module, but hopefully this also stayed alive. (I still not understand this thing with the 3.3 V vs. "TTL levels" stated on the datasheet.)
Anyway, thank you very-very much. I think, will return soon, when the HW is ready with more SW questions. This forum is really cool , full of very helpful experts. |
|
|
Depner
Joined: 15 Apr 2008 Posts: 4 Location: Hungary
|
|
|
|