CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Fingerprint sensor RS232 communication
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Depner
Guest







Fingerprint sensor RS232 communication
PostPosted: Mon Apr 14, 2008 12:49 pm     Reply with quote

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. Sad

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

View user's profile Send private message

PostPosted: Mon Apr 14, 2008 1:15 pm     Reply with quote

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







PostPosted: Mon Apr 14, 2008 1:52 pm     Reply with quote

Ohh, thanks. That's true, it never does. Then how to solve?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 14, 2008 2:03 pm     Reply with quote

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







PostPosted: Mon Apr 14, 2008 2:22 pm     Reply with quote

I did this:
Code:
for(i=0;i<5;i++)
{
c=getc();
string[i]=c;
}


And it is halting at i=2. Sad
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

View user's profile Send private message

PostPosted: Mon Apr 14, 2008 2:27 pm     Reply with quote

Post a link to the data sheet for the DFZ-2002S device.
Depner
Guest







PostPosted: Mon Apr 14, 2008 2:38 pm     Reply with quote

Here is the link:
h**p://w*w.datasheetarchive.c*m/preview/1194375.h**l
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 14, 2008 2:45 pm     Reply with quote

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







PostPosted: Mon Apr 14, 2008 2:53 pm     Reply with quote

Surely I will register now... Very Happy

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

View user's profile Send private message

PostPosted: Mon Apr 14, 2008 2:57 pm     Reply with quote

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







PostPosted: Mon Apr 14, 2008 2:59 pm     Reply with quote

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? Sad Or some transciever..?
Depner
Guest







PostPosted: Mon Apr 14, 2008 3:04 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 14, 2008 3:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 15, 2008 1:22 am     Reply with quote

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. Embarassed
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.) Bummed Out

Anyway, thank you very-very much. I think, will return soon, when the HW is ready with more SW questions. Very Happy This forum is really cool Cool , full of very helpful experts.
Depner



Joined: 15 Apr 2008
Posts: 4
Location: Hungary

View user's profile Send private message

Link for the datasheet
PostPosted: Tue Apr 15, 2008 1:36 am     Reply with quote

I've uploaded the datasheet, I got with the device.
Hope it's working:
http://www.keepandshare.com/doc/view.php?id=512687&da=y
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group