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 support@ccsinfo.com

RFID Problems....

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
piire



Joined: 04 Mar 2009
Posts: 19

View user's profile Send private message

RFID Problems....
PostPosted: Sun Feb 28, 2010 7:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 28, 2010 1:16 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 28, 2010 5:14 pm     Reply with quote

this is the data sheet for the ID12 RFID sensor:


http://www.coolcomponents.co.uk/resources/ID12/ID-12-Datasheet.pdf

thanks

piire
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 28, 2010 5:29 pm     Reply with quote

Quote:

#define RFID_START_BYTE 0x0A
#define RFID_END_BYTE 0x0D

Well, look at the data format on page 4 of data sheet:
Quote:

Output Data Structure – ASCII

http://www.coolcomponents.co.uk/resources/ID12/ID-12-Datasheet.pdf
What does it show as the starting byte ?
piire



Joined: 04 Mar 2009
Posts: 19

View user's profile Send private message

PostPosted: Mon Mar 01, 2010 4:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 01, 2010 7:28 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 01, 2010 1:30 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 01, 2010 1:52 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 24, 2011 3:20 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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