PDA

View Full Version : Need help on serial rfid receive



luminas
- 8th August 2008, 08:36
I am experimenting with id12 rfid reader with PIC18f2550, but I can not get consistent reading. id12 has a leading character ( 02h) , how to read the data after this leading character?
I tried with WAIT modifier, but it did not gave any result
HSERIN [ wait ($02), b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 ]




ASM
__CONFIG _CONFIG1L, _PLLDIV_10_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_1_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _VREGEN_OFF_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_ON_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L

ENDASM

define osc 40
DEFINE LCD_DREG PORTB ' LCD data port
DEFINE LCD_DBIT 0 ' LCD data starting bit
DEFINE LCD_RSREG PORTB ' LCD register select port
DEFINE LCD_RSBIT 4 ' LCD register select bit
DEFINE LCD_EREG PORTB ' LCD enable port
DEFINE LCD_EBIT 5 ' LCD enable bit
DEFINE LCD_BITS 4 ' LCD data bus size
DEFINE LCD_LINES 2 ' Number lines on LCD
DEFINE LCD_COMMANDUS 1500 ' Command delay time in us
DEFINE LCD_DATAUS 44 ' Data delay time in us
define HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 25
define HSER_CLROERR
b1 var byte
b2 var byte
b3 var byte
b4 var byte
b5 var byte
b6 var byte
b7 var byte
b8 var byte
b9 var byte
b10 var byte
b11 var byte
b12 var byte
b13 var byte

clear
porta = 0
portb = 0
portc = 0
TRISA = %00000000 ' Set PORTA to all input
TRISB = %00000000 ' Set PORTB to all output
TRISC = %10000000 ' Set PORTC to all input


LCDOUT $FE, 1 'clear lcd
pause 100

main:
HSERIN [ wait ($02), b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 ] ' the data sequence is STX(02h), data ( 10 ASCII ),checksum (2 ASCII ),CR, LF, ETX(03h)

LCDOUT $FE,1 , b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13
pause 500

goto main

Archangel
- 8th August 2008, 09:17
Have a look at the code posted in this thread, in particular post #16 I think there might be something you can use in there, a tidy little ring buffer perhaps.
http://www.picbasic.co.uk/forum/showthread.php?t=4972

luminas
- 10th August 2008, 16:20
Thanks Joe,

I have got "rather" consistent reading with HSERIN command
For example I got @123456789 , then 89 @12345 then 3@ 234 789

How to "filter" or how to put a qualifier so I can get numbers after @ sign ?

Archangel
- 10th August 2008, 18:49
You see it is looping and catching data mid stream, look at the manual under herserin, and serin2 for instructions re: wait . If your data is a fixed length packet you can tell herserin how many units to receive before proceeding to the next operation.
http://www.picbasic.co.uk/forum/showthread.php?t=4047
http://www.picbasic.co.uk/forum/showthread.php?t=3751
http://www.picbasic.co.uk/forum/showthread.php?t=6963

luminas
- 19th August 2008, 06:12
Thanks Joe, it works now.
The problem was the unshielded cable . I changed the cable to shielded, and ground it, the readings are now consistent