PDA

View Full Version : RFID RDM6300 Code.. Sample ?? Anyone ??



andybarrett1
- 24th August 2014, 21:30
Hi Thank you for reading….

I have recently got my self some of these to play with.. RDM630(0) Em4100 Serial Output


http://imall.iteadstudio.com/im120618002.html

Question :-

There seems to be a lack of example code around the internet…. Has anybody used these with PBP?

Am I right in just reading what the serial is squirting out somehow ??

Is there any samples to look at ?

BR and Thank you.

Andy

richard
- 24th August 2014, 23:03
this link explains a lot
http://www.seeedstudio.com/wiki/125Khz_RFID_module_-_UART

EarlyBird2
- 25th August 2014, 06:47
Here is a RFID example which uses serin to read 10 characters from a RFID reader.

RFID by Ecoli-557 (http://www.picbasic.co.uk/forum/showthread.php?t=6979)

Have a read and as usual if you need more help just ask.

EarlyBird2
- 25th August 2014, 07:04
This is the example from the site in your original post it reads 14 tag IDs using I will look into converting this to PBP 2.5c for you.


#include <p18lf26j11.h>
#include <delays.h>
#include <usart.h>
#include <string.h>

#pragma config OSC = HS //High speed crystal
#pragma config WDTEN = OFF //Disable watchdog timer
#pragma config XINST = OFF //Disable Extended CPU mode

//LED Pin Configuration
#define LED1Pin LATAbits.LATA0
#define LED1Tris TRISAbits.TRISA0
#define LED2Pin LATAbits.LATA1
#define LED2Tris TRISAbits.TRISA1
#define LED3Pin LATAbits.LATA2
#define LED3Tris TRISAbits.TRISA2

#define RFIDVCCPin LATBbits.LATB4 //Define RFIDVCCPin as PORT B Pin 4
#define RFIDVCCTris TRISBbits.TRISB4 //Define RFIDVCCTris as TRISB Pin 4

//Flags & Data Reception Variables
volatile char tagRecdFlag;
volatile char tagComingFlag;
volatile char tagCounter;
volatile char tagRX[14] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

//RFID Tag IDs
char rfidTag1[14] = {0x02, 0x30, 0x35, 0x30, 0x30, 0x41, 0x44, 0x44, 0x38, 0x46, 0x46, 0x43, 0x3f, 0x03};
char rfidTag2[14] = {0x02, 0x30, 0x35, 0x30, 0x30, 0x41, 0x44, 0x42, 0x46, 0x35, 0x37, 0x36, 0x30, 0x03};
char rfidTag3[14] = {0x02, 0x30, 0x35, 0x30, 0x30, 0x41, 0x45, 0x33, 0x46, 0x36, 0x35, 0x44, 0x33, 0x03};

//Function Prototypes
void rx_handler(void);
//Function Prototypes

#pragma code rx_interrupt = 0x8
void rx_int(void)
{
_asm goto rx_handler _endasm
}
#pragma code

#pragma interrupt rx_handler
void rx_handler(void)
{
unsigned char rxByte;
rxByte = RCREG1; //Read character received from USART

if (tagComingFlag == 0 && rxByte == 0x02)
{
tagRX[tagCounter] = rxByte;
tagComingFlag = 1;
tagCounter++;
} else if (tagComingFlag == 1)
{
tagRX[tagCounter] = rxByte;
tagCounter++;
if (tagCounter == 14)
{
tagCounter = 0;
tagComingFlag = 0;
tagRecdFlag = 1;
}
} else
{
tagComingFlag = 0;
tagCounter = 0;
}
PIR1bits.RCIF = 0; //Clear interrupt flag
}

void main()
{
//Set LED Pins data direction to OUTPUT
LED1Tris = 0;
LED2Tris = 0;
LED3Tris = 0;
//Set LED Pins to OFF
LED1Pin = 0;
LED2Pin = 0;
LED3Pin = 0;

tagRecdFlag = 0; //Set in ISR if new RFID tag has been read
tagComingFlag = 0; //Indicates if a tag is partially received
tagCounter = 0; //Counts byte index

//USART1 Initialization
Open1USART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 25);

//Interrupts
RCONbits.IPEN = 1; //Enable interrupt priority
IPR1bits.RC1IP = 1; //Make receive interrupt high priority
INTCONbits.GIEH = 1; //Enable all high priority interrupts

//Turn on RFID Module
RFIDVCCTris = 0; //Set to output
RFIDVCCPin = 1; //Turn on RFID Module

while(1)
{
if (tagRecdFlag)
{
//Toggle LED corresponding to which card was read
if (memcmp(tagRX, rfidTag1, 14) == 0)
{
LED1Pin = ~LED1Pin;
}
if (memcmp(tagRX, rfidTag2, 14) == 0)
{
LED2Pin = ~LED2Pin;
}
if (memcmp(tagRX, rfidTag3, 14) == 0)
{
LED3Pin = ~LED3Pin;
}

//Delay 1/2 sec & clear flags to prevent repeated card read
Delay10KTCYx(200);
tagRecdFlag = 0;
tagComingFlag = 0;
tagCounter = 0;
}
}
}

EarlyBird2
- 25th August 2014, 07:25
After a bit more reading.

14 bytes because the output includes

a start byte - 02
10 tag characters
2 CRC bytes
an end byte - 03

so with serin2 wait for 02 character and then read 10 characters into tag buffer like this

SERIN2 rfid_data, 396, [WAIT($02),STR buf\10]

andybarrett1
- 25th August 2014, 21:54
Hi..
Thank you all for help..... I have just got something working ....

Not quite sure how the number on the card relates to the hex number embeded in the card...Had to get that out via clever use of a MAX232 chip, hyperterminal and a few caps on the bench...!!

Thank you all again...

EarlyBird2
- 25th August 2014, 22:07
Not quite sure how the number on the card relates to the hex number embeded in the card...

There is no relation except for the CRC. My understanding is that you have to swipe the cards and capture the embedded numbers (Tag) which you can then use in your code. The output from the RFID is TTL level and using a MAX232 is one way forward.

I have read some posts that suggest the CRC is used to catch bad data but the datasheet says the CRC is calculated using the card number. Examples I have seen ignore the CRC and end byte. I guess the cards are reasonably reliable and do not need CRC checking or end byte detection, who knows?

andybarrett1
- 27th August 2014, 07:28
There is no relation except for the CRC. My understanding is that you have to swipe the cards and capture the embedded numbers (Tag) which you can then use in your code.

That is what I will do…. Seems to be others have same issue..

Thanks again for help

Andy

louislouis
- 5th December 2020, 16:07
Hi Folks,
I started to play with this RFID reader. For beginning I try to create a simple TAG reader and show the tag number on NOKIA LCD. I can read the tag and display it, but I can't extract the decimal value from readed HEX string. For example: TAG number written on tag is 0008201470 (dec) readed as 34007D24FE (HEX).
My question is how to convert this HEX to DEC?
Reading the TAG as HEX string:


'************************************************* ***************
'* Name : RDM6300 RFID Reader, nokia LCD *
'* Notes : PIC16F1829 *
'************************************************* ***************
;@ errorlevel -306
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_OFF
__config _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_19 & _LVP_OFF
#ENDCONFIG

DEFINE OSC 16 ; Use a 16 MHZ internal clock
OSCCON = %01111010
OSCTUNE = %111111
CLKRCON = 0
APFCON0 = 0
APFCON1 = 0
CM1CON0 = 0
FVRCON = %11000011
ADCON1 = %00010000
ADCON0 = %00000000

CCP1CON = %00000000
CCP2CON = %00000000
ANSELA = %00000000
ANSELB = %00000000
ANSELC = %00000000
TRISA = %00100000
TRISB = %00100000
TRISC = %00000000
CM1CON0 = 0 ; Disable comparator 1
CM2CON0 = 0 ; Disable comparator 2
OPTION_REG.6=0
OPTION_REG.7=1 ; weak pull ups

clear

DEFINE HSER_RCSTA 90h ; Set receive register to receiver enabled
DEFINE HSER_TXSTA 24h ; Set transmit register to transmitter enabled
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_BAUD 9600

BUFF VAR BYTE [11] bank1
#DEFINE PIC16 1
lcdheight con 5 ; 6 PAGES
lcdwidth con 83 ; 84 PIXELS WIDE
LCD_CLK var portC.0
LCD_DIN var portC.1
LCD_RST var portC.2
LCD_DC var portC.3
LCD_CE var portC.4
LCD_LIGHT var portC.5
sw1 var porta.5

buf VAR byte [10]

include "nokia_ds2.INC"
include "font7x5_16.bas"

gosub lcd_init
pause 100
LCDCLR
pause 100

Main:
;TAG No. Decimal: 0008201470
hserin 100,main,[wait ($02), STR buf\10] ;wait for $02, then read 10 bytes ascii hex

;Reading in HEX: 34007D24FE
bigtxt = 0
ARRAYWRITE BUFF,[str buf] ;display on NOKIA LCD
LCDSTR 0,0,BUFF
goto main

Reading the TAG as five individual HEX byte:


'************************************************* ***************
'* Name : RDM6300 RFID Reader, nokia LCD *
'* Notes : PIC16F1829 *
'************************************************* ***************
;@ errorlevel -306
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_OFF
__config _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_19 & _LVP_OFF
#ENDCONFIG

DEFINE OSC 16 ; Use a 16 MHZ internal clock
OSCCON = %01111010
OSCTUNE = %111111
CLKRCON = 0
APFCON0 = 0
APFCON1 = 0
CM1CON0 = 0
FVRCON = %11000011
ADCON1 = %00010000
ADCON0 = %00000000

CCP1CON = %00000000
CCP2CON = %00000000
ANSELA = %00000000
ANSELB = %00000000
ANSELC = %00000000
TRISA = %00100000
TRISB = %00100000
TRISC = %00000000
CM1CON0 = 0 ; Disable comparator 1
CM2CON0 = 0 ; Disable comparator 2
OPTION_REG.6=0
OPTION_REG.7=1 ; weak pull ups

clear

DEFINE HSER_RCSTA 90h ; Set receive register to receiver enabled
DEFINE HSER_TXSTA 24h ; Set transmit register to transmitter enabled
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_BAUD 9600

BUFF VAR BYTE [10] bank1
#DEFINE PIC16 1
lcdheight con 5 ; 6 PAGES
lcdwidth con 83 ; 84 PIXELS WIDE
LCD_CLK var portC.0
LCD_DIN var portC.1
LCD_RST var portC.2
LCD_DC var portC.3
LCD_CE var portC.4
LCD_LIGHT var portC.5
sw1 var porta.5

b0 var byte
b1 var byte
b2 var byte
b3 var byte
b4 var byte

include "nokia_ds2.INC"
include "font7x5_16.bas"

gosub lcd_init
pause 100
LCDCLR
pause 100

Main:
;TAG No. Decimal: 0008201470
hSERIN 100,main,[wait ($02),hex2 b0, hex2 b1, hex2 b2, hex2 b3, hex2 b4] ; ;wait for $02, then read 10 bytes ascii hex

;Reading in HEX: 34007D24FE
ARRAYWRITE BUFF,[hex2 b0, hex2 b1,hex2 b2, hex2 b3,hex2 b4] ;display on NOKIA LCD
LCDSTR 0,0,BUFF

gOTO main