Newbee needs help with rfid

SteveT

Senior Member
Hi guys, I've been reading this forum for quite some time and am very impressed with the knowledge available and advice freely given. <grovel grovel>

I'm trying to set up an ID12 rfid reader to read glass rfid tags attached underneath 'N' guage model railway rolling stock. The idea is to place the reader at the entrance to a station and have an LCD display information on the approaching train. On a different part of the layout I want to use a second ID12 reader to activate sound files using the mp3 player Haku originally found.

The code I have cobbled together at the moment doesn't work as intended. It reads the tags and cards I have at the moment, correctly... but only on the second swipe for some reason. If I then swipe a different card/tag, again, it will only display it (using debug) after the second swipe. Also I originally tried to use a quallifier on the serin command, this just screwed everything up. The resulting ascii string received had no bearing on the string expected.

Part of the code used has been lifted from this forum but it's my first foray into the 'bptr' commands.

Code:
' last used on 18m2
' ** rfidtest.bas **
' Picaxe 18M2 and ID12 rfid reader

' Data format is "supposed" to be ......
' STX ($02) Data (10 ascii) Check sum (2ascii) CR LF ETX ($03)
' The 1byte (2 ASCII characters) Check sum is the 
' “Exclusive OR” of the 5 hex bytes (10 ASCII) Data characters.

' "I" get the STX ($02) and use it as a qualifier. I also get the LF ($0A) and ETX ($03).
' I get 10 hex data bytes and 2 hex checksum bytes, no sign of a CR which should be $0D

' ** Data **

eeprom 0, (50,57,48,48,57,52,50,49,49,69,1) 	' "290094211e" card with label	last digit on
eeprom 11, (50,57,48,48,57,52,50,49,49,69,2) 	'"290093fe68" card without		each row is
eeprom 22, (48,48,51,54,53,70,56,57,52,55,3) 	'"00365f8947" tag				item number
'									i.e. at eeprom
' ** variables and constants **				10,21 and 32.

symbol indexa = b21
symbol indexb = b16
symbol indexc = b17
symbol char = b18
symbol tag = b19
symbol cntr = b22

pause 1000

do

setfreq m8 ' set to 8mhz

serin B.0, n9600_8, b0,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15
'					NOTE b0 is used twice above to overwrite the start byte ($02)
setfreq m4 ' reset to 4mhz

debug b0 ' display characters

check:

cntr = 0

for indexa = 0 to 22 step 11

	bptr = 0
	
	for indexb = 0 to 9

		indexc = indexb + indexa
		read indexc, char
		if @bptrinc <> char then exit
		let b23 = bptr
		if indexb => 9 then
		cntr = cntr + 1	
'		read indexc, b20 		' debug only
'		tag = b20			' debug only
'		read indexc, tag
		endif

	next indexb
	
	if cntr <> 0 then exit
		
next indexa		

tag = cntr
' pause 1000
loop
The part between check: and loop doesn't complete for some reason.......
any ideas anyone

cheers, Steve
 

Paix

Senior Member
I suspect that your "do" needs a qualifier and curly braces to construct your block of code before the "loop".

I may be wrong, but suspect not. Even an infinite loop will need quallifiying. Picaxe Manual 2 page 59 gives the options.
 
Last edited:

SteveT

Senior Member
I suspect that your "do" needs a qualifier and curly braces to construct your block of code before the "loop".

I may be wrong, but suspect not. Even an infinite loop will need quallifiying. Picaxe Manual 2 page 59 gives the options.
Hi Paix,

never needed a qualifier or curly brackets before and I've been using do / loop for the last year or so without any bother.

Thanks for the reply though.

Steve
 
Top