View previous topic :: View next topic |
Author |
Message |
piire
Joined: 04 Mar 2009 Posts: 19
|
RFID Problems.... |
Posted: Sun Feb 28, 2010 7:58 am |
|
|
Hi there
I'm trying to get RFID tag id on to the computer. I'm using a ID12 RFID sensor. It has a RS232 port which I have linked to the PIC16F877A.
I'm using the hardware UART for the RFID and software to the computer.
This is the code I have come up with using the codes from the search on the forums:
Code: |
#include <16F877A.H>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=ID12, ERRORS)
#use rs232(baud=9600,parity=N,xmit=PIN_E0,rcv=PIN_E1,bits=8,stream=CPU, ERRORS)
#define RFID_START_BYTE 0x0A
#define RFID_END_BYTE 0x0D
void get_rfid_string()
{
int8 s[12];
unsigned int8 max=20;
unsigned int8 len;
char c;
// Wait for start byte
do
{
c = fgetc(ID12);
} while (c != RFID_START_BYTE);
// Receive data until END byte is received or buffer full
// correct for terminating zero
len=0;
s=0;
while ((c != RFID_END_BYTE) && (len < max))
{
c = fgetc(ID12);
s[len++] = c;
};
fprintf(CPU, "%s\n", s);
}
//3. Main program
VOID main()
{
DO {
get_rfid_string();
} WHILE(TRUE);
}
|
The problem is that I get more than the RFID tag on the computer.
This the output on the computer:
Code: |
0 002B56AB67F1 - 1st line tag has three zero with one space
0 002B56AB67F1 - the rest have three zero with two spaces
0 002B56AB67F1
0 002B56AB67F1
|
So how would I get rid of the 0's without using:
Code: | fprintf(CPU, "%s\n", s+4); |
Or is it possible to put the zeros together if you can't remove them,
so I get a code: 0002B56AB67F1
Thanks for everyones help
Regards
Piire! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 28, 2010 1:16 pm |
|
|
Quote: |
I'm using a ID12 RFID sensor.
|
Post a link to the data sheet for your RFID sensor board. |
|
|
piire
Joined: 04 Mar 2009 Posts: 19
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
piire
Joined: 04 Mar 2009 Posts: 19
|
|
Posted: Mon Mar 01, 2010 4:39 am |
|
|
oo what a stupid mistake, i have changed to the following:
Quote: |
#define RFID_START_BYTE 0x02
#define RFID_END_BYTE 0x03
|
now the output is:
Quote: |
002B56AB67F1
0002B56AB67F1
0002B56AB67F1 0002B56AB67F1
0002B56AB67F1 0002B56AB67F1
|
Now i get the output without the spaces, but the first scan of the tag, has two zero in front and the rest have three, is it possible to make it either three or two zero on each scan? i just need it to be consistent.
thanks for your help PCM programmer!!!
regards
piire! |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Mon Mar 01, 2010 7:28 am |
|
|
I noticed something in the code:
Code: |
int8 s[12];
unsigned int8 max=20;
unsigned int8 len;
char c;
// Wait for start byte
do
{
c = fgetc(ID12);
} while (c != RFID_START_BYTE);
// Receive data until END byte is received or buffer full
// correct for terminating zero
len=0;
s=0;
|
s is an array (int8 s[12]; ) and yet you're setting s = 0. I don't know what this accomplishes but it can't be doing anything good. Is this an attempt to get the end-of-string marker loaded into the string s[]?
You could add a line to your character loading to do that:
Code: |
s[len++] = c;
s[len] = '\0';
|
|
|
|
piire
Joined: 04 Mar 2009 Posts: 19
|
|
Posted: Mon Mar 01, 2010 1:30 pm |
|
|
By putting s[len] = '\0'; in, it has solved the problem of the three zeros! I get two constant zeros in front on each scan, which I can work with. Thank you so much, it was small mistake, but so hard to find. Thank for your help again!
Regards
piire!! |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Mon Mar 01, 2010 1:52 pm |
|
|
Hah. You're welcome. But one more point--there could be a new error. If the array fills to its maximum size, the last '\0' would be written beyond the declared maximum size. (At index len = 20, as the code is written.) This would occur if no terminating character arrived. Sorry, it's always something. |
|
|
Chantry
Joined: 18 Jan 2011 Posts: 13
|
|
Posted: Mon Jan 24, 2011 3:20 pm |
|
|
This is a very widely used RFID module and I happen to have one of these myself. Is there any reason why these 0's are appearing? I can't see anything in the code which would be causing this. |
|
|
|