• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Reading RFID tag through software UART on 8051 failed

Thread starter #1
Here's my situation.

I attempted to create my own RFID reader with the help of an RDM6300 reader module (with UART) with results sent to a computer via a serial cable.

I have already dedicated the 8051 hardware UART to the PC so my only option is to create a software UART to interface with the UART on the RDM6300 module.

I have borrowed ideas from here: http://webcache.googleusercontent.com/search?q=cache:CyacPmYhWY4J:https://www.8051projects.net/wiki/8051_Software_UART_Tutorial+8051+software+uart+asynchronous&num=50&client=opera&hs=ZUz&rls=en&channel=suggest&hl=en&ct=clnk

This is my code:

Code:
RX equ P3.3 ;pin on micro which RDM6300 TX pin connects to

;reset variables
clr TR1
mov P1,#0FFh
mov P3,#0FFh

;enable 9600bps to PC
mov PCON,#80h
mov TH1,#0F4h ;9.6kbps
mov SCON,#50h ;serial mode 1
mov TMOD,#22h ;auto reload for timers
setb TR1

;print init message
mov DPTR,#Minit
lcall lprint

main:
;call serial receive function
lcall surec
;load hex number table and convert received character (in accumulator) to hex
mov DPTR,#hex
mov B,#0Fh
div AB
;do 1st hex character
movc A,@A+DPTR
clr TI
mov SBUF,A
jnb TI,$
;then next character
mov A,B
movc A,@A+DPTR
clr TI
mov SBUF,A
jnb TI,$
;print space
clr TI
mov SBUF,#20h
jnb TI,$
;print anoter space (to make screen look nice)
clr TI
mov SBUF,#20h
jnb TI,$
sjmp main

;print string from memory until character code 0 reached
lprint:
clr A
movc A,@A+DPTR
inc DPTR
jz exitp
clr TI
mov SBUF,A
jnb TI,$
sjmp lprint
exitp:
ret

;calculate bit time based on (((crystal/baud)/12) - 5) / 2
;crystal = 22.1184Mhz, baud=9600
BITTIM equ 0BBh
;and pre-calculate 1/2 bit time
BITTIMH equ 5Dh

;Software Uart RECeive routine
surec:
;wait for start bit (bit=0)
jb RX,$
mov R0,#BITTIMH
djnz R0,$
;wait 1/2 time and if bit is 0, start over
jb RX,surec
;load 8 bits into accumulator waiting 1 bit time for each
mov R1,#8h
clr A
surecl:
mov R0,#BITTIM
djnz R0,$
mov C,RX
RRC A
djnz R1,surecl
clr C
ret

hex:
db '0123456789ABCDEF????',00h

Minit:
db 0Dh,0Ah,0Dh,0Ah,'RFID Card Reader V1.0',0Dh,0Ah,00h
When I execute it, hex values do appear when the card is on the module but they don't match up with the numbers on the card. Also, I read somewhere that the card byte format must start with a "2" then several bytes then a value "3".

Is the equation (((crystal/baud)/12) - 5) / 2 incorrect for determining bit time? or is there something else I'm doing wrong?
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#2
;wait 1/2 time and if bit is 0, start over
jb RX,surec
Trying to get my head around this... I'm wondering if its a typo!! If the pin is still high carry on else start over..
So shouldn't it be jnb RX,surec?

Whoops... No... I keep forgetting that 8052 pins are reversed...
 

ci139

Active Member
#3
Last edited:
Thread starter #4
Trying to get my head around this... I'm wondering if its a typo!! If the pin is still high carry on else start over..
So shouldn't it be jnb RX,surec?

Whoops... No... I keep forgetting that 8052 pins are reversed...
oops. typo in the comment. It checks for 0 (logic low) then wait 1/2 bit time then check for logic low again
 
Thread starter #5
Ok Now I'm not sure if the data format is right at all. I'm using an RDM6300 card reader module and reading the data through the software uart and I tried EMI4100 compatible cards with the following labels:

004190809 063,62041
004190808 063,62040

When I scanned the first 13 bytes of the card, I received the following output as hexadecimal:

1st card: 023B3B33004E4A4A35383B3448
2nd card: 023B3B33004E4A4A35383C3447

However the documentation for RDM6300 states that the termination byte should be 03 and I don't see that anywhere. I guess I will try more bytes just to see.

But I'm curious as to why I get 48 and 47 as output when that doesn't represent ascii 0 and ascii 1.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#6
Okay!!

Two things wrong....
1) timings.... You forgot the /2 at the end so your bit delay should be 0x5d and the half should be 0x2e.
2) BCD.... You are dividing by 15 and not by 16 you need to change mov b,#0fh to mov b, #10h.


Works now
Code:
RX equ P3.3 ;pin on micro which RDM6300 TX pin connects to

;reset variables
clr TR1
mov P1,#0FFh
mov P3,#0FFh

;enable 9600bps to PC
mov PCON,#80h
mov TH1,#0F4h ;9.6kbps
mov SCON,#50h ;serial mode 1
mov TMOD,#22h ;auto reload for timers
setb TR1

;print init message
mov DPTR,#Minit
lcall lprint

main:
;call serial receive function
lcall surec
;load hex number table and convert received character (in accumulator) to hex
mov DPTR,#hex
mov B,#10h
div AB
;do 1st hex character
movc A,@A+DPTR
clr TI
mov SBUF,A
jnb TI,$
;then next character
mov A,B
movc A,@A+DPTR
clr TI
mov SBUF,A
jnb TI,$
;print space
clr TI
mov SBUF,#20h
jnb TI,$
;print anoter space (to make screen look nice)
clr TI
mov SBUF,#20h
jnb TI,$
sjmp main

;print string from memory until character code 0 reached
lprint:
clr A
movc A,@A+DPTR
inc DPTR
jz exitp
clr TI
mov SBUF,A
jnb TI,$
sjmp lprint
exitp:
ret

;calculate bit time based on (((crystal/baud)/12) - 5) / 2
;crystal = 22.1184Mhz, baud=9600
BITTIM equ 05dh
;and pre-calculate 1/2 bit time
BITTIMH equ 2eh

;Software Uart RECeive routine
surec:
;wait for start bit (bit=0)
jb RX,$
mov R0,#BITTIMH
djnz R0,$
;wait 1/2 time and if bit is 0, start over
jb RX,surec
;load 8 bits into accumulator waiting 1 bit time for each
mov R1,#8h
clr A
surecl:
mov R0,#BITTIM
djnz R0,$
mov C,RX
RRC A
djnz R1,surecl
clr C
ret

hex:
db '0123456789ABCDEF????',00h

Minit:
db 0Dh,0Ah,0Dh,0Ah,'RFID Card Reader V1.0',0Dh,0Ah,00h
end
 
Thread starter #7
That point #2 kept me puzzled for a while there but yes I'll followed point 2. I followed point 1 through experimentation before you posted this.
 

Latest threads

EE World Online Articles

Loading

 
Top