|
|
View previous topic :: View next topic |
Author |
Message |
f0raster0
Joined: 05 Nov 2010 Posts: 22
|
data from tag RFID to 16F887 and LCD |
Posted: Sat Apr 06, 2013 5:12 pm |
|
|
Hi mates, I need your help.. I have a reader HID and I'm trying read a tag using a PIC16F887 + LCD16x2
Thanks for your time and any help
My problem:
-At the moment and after pass my tag several times I am reading HEX 66 F2 62 62 62 42 but I must read HEX 90 62 FD 59
My configuration
Lector->Max232->PIC16F887->LCD (LCD to port D)
Test:
-reader connected to PC using a converser RS232-USB I can read my correct data in hyperterminal
-reader connected max232->PIC--max-->conversorRs232-USB-->PC Hyperterminal just I can see data like: F0 00 F0 F0 00 00 00 F0 F0 F0 F0 F0 F0
PIC16F887 (DIP 40)
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en026561
reader HID R10
http://www.keyscan.ca/Languages/Spanish/PDFs/es_iclass_r10.pdf
CCS version 4.068
Code: | #include <16F887.h>
#FUSES HS,NOWDT,MCLR
#use delay(clock=20000000)
#use rs232(baud=57600, xmit=pin_c6, rcv=pin_c7, bits=8,parity=N, ERRORS)
#use fast_io(b)
#use fast_io(c)
#include <lcd.c>
int const lenbuff=6;
char a=0;
int xbuff=0x00;
char cbuff[lenbuff];
#int_rda
void serial_isr()
{
char rcvchar= ' ';
rcvchar=0x00;
if(kbhit())
{
rcvchar=getc();
cbuff[xbuff]=rcvchar;
xbuff++;
}
if(xbuff>=1) //
{
putc(rcvchar); //test to PC
//xbuff=0x00;
}
}
void init_cbuff(void){
int i;
for(i=0;i<lenbuff;i++){
cbuff[i]=0x00;
}
xbuff=0x00;
}
void main() {
set_tris_c(0x10111111);
lcd_init();
disable_interrupts(global);
enable_interrupts(int_rda);
enable_interrupts(global);
init_cbuff();
lcd_putc("\f");
a=128; //test LCD
while(TRUE)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"%X",a); //test LCD
lcd_gotoxy(1,2);
printf(lcd_putc,"%X",cbuff[2]); // just one
//tag example (HEX): 90 62 FD 59
}
} |
Last edited by f0raster0 on Thu May 30, 2013 3:00 am; edited 6 times in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sat Apr 06, 2013 7:13 pm |
|
|
This post sounds familiar....but..
1) replace the 'HID reader' with a PC running a terminal program. Test by sending data from the PC keyboard. When you get your PIC program to work correctly then reconnect your 'HID reader'.
Without a link or datasheet about your "HID reader' I (we) have no idea as to the data is is supplying. In fact I have no idea what an 'HID reader' is other than a piece of test equipment designed for testing of HID light bulbs.
2) whenever you post saying 'bad data, or not as expected', you should show both good data (what you expect) and bad data (what you get). With 'serial data' it could be an incorrect setup, timing error, bit shifting,???....so the more information you supply, the better the responses from this forum.
3) also, when using serial (aka RS-232), put 'errors' in the #use rs232(....options...), it'll keep the hardware UART (if used) from stopping due to errors.
hth
jay |
|
|
f0raster0
Joined: 05 Nov 2010 Posts: 22
|
|
Posted: Sat Apr 06, 2013 8:17 pm |
|
|
thanks I have edited my information above
Last edited by f0raster0 on Sun May 05, 2013 6:28 am; edited 3 times in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sun Apr 07, 2013 5:45 am |
|
|
hmm... going to that link causes my IE8 to 'bluescreen' ! Even the homepage....arrgh....
Simple test...if you connect the reader to a PC running a terminal program, do you get correct data ?
If so, great...hardware is good..
Have a look at the ex_sisr.c example in the examples folder. It's an example that CCS supplies to show how to implement an interrupt driven,buffered serial port.
oh.. have you added 'errors' to the use RS232(...options...)? It's a _must do_ .
hth
jay |
|
|
f0raster0
Joined: 05 Nov 2010 Posts: 22
|
|
Posted: Mon May 06, 2013 2:04 am |
|
|
I can't find the problem.
To sending data from hyperterminal to PIC it doesn't backs my test-message puts("Hello test"); just give me "ppppppppppppppp".
-CCS version 4.068
Could CCS has some problem with interruptions for my PIC16F887?
-PIC 16F887 DIP40 (I have two 16F887)
-I am waiting for a new crystal (4Mhz and 20MHz) at moment I am using 20Mhz.
-My max232 work fine with Arduino and my reader R10
Here is my test PC-max232-PIC16F887-PC
Code: | #include <16F887.h>
#FUSES HS,NOWDT,MCLR
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=pin_c6, rcv=pin_c7, bits=8,parity=N, ERRORS)
#include <lcd.c>
char ch;
#int_rda
void serial_isr()
{
ch = getchar();
puts("Hello test"); //doesn`t work
}
void main()
{
lcd_init();
enable_interrupts(global);
enable_interrupts(int_rda);
while(TRUE)
{
lcd_gotoxy(1,1);
printf(lcd_putc, "test LCD"); //work ok
lcd_gotoxy(2,1);
printf(lcd_putc, "\n\r value %c",ch); //doesn't work
}
} |
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon May 06, 2013 8:21 am |
|
|
puts(.....) // takes too much char receive time !!!!!!
in your ISR is a disaster !!!
also the kbhit will always be true as thats why the isr was called
a bigger receive buffer and structure for correctly removing chars would help
&&
lastly enable the RDA int BEFORE global ints |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon May 06, 2013 2:25 pm |
|
|
Using puts() in a INT_RDA handler is normally bad practice because it takes longer to send your string than it takes to receive one character. This will cause your receive UART to overflow and loose data.
Having said that, in your test program I would at least have expected to see part of the "Hello test" message. Not seeing this suggests a major problem for which I see 2 possible causes:
1) What happens when you create a simple test program without interrupts that sends the "Hello test" message to the PC?
2) Your v4.068 compiler is very old and known to have problems. The V4 compiler started only to work a bit as expected around the v4.075 version, that is about 10 releases newer than you are using. |
|
|
f0raster0
Joined: 05 Nov 2010 Posts: 22
|
|
Posted: Tue May 07, 2013 12:27 am |
|
|
ohh noo mates..¡¡
Quote: | I would at least have expected to see part of the "Hello test" message |
I have changed my crystal of 20MHz to 4MHz then my test:
PC-max232-PIC16F887-PC works fine :-)
I bought two crystal I'm waiting these after I will check my first code..
and yes, I will do a couple changes in my code
Quote: |
puts() in a INT_RDA handler is normally bad practice
lastly enable the RDA int BEFORE global ints
|
hey again on microchip for my pickit2 same remark :-P yes, I backed to the PICs with my old stuff
Quote: | 2) Your v4.068 compiler is very old |
thanks a lot
Edit: ok, thanks
Quote: | ..resistor in series with the 20MHz crysta.. ..crystal application notes from Microchip |
Last edited by f0raster0 on Tue May 07, 2013 1:02 am; edited 2 times in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue May 07, 2013 12:41 am |
|
|
Common problem with the 887. You need a resistor in series with the 20MHz crystal.
Basically the oscillator on this chip, has a higher gain than many, and can tend to lock onto the wrong harmonic if driven hard. The resistor just slightly attenuates the signal.
Read the crystal application notes from Microchip.
This is one reason why you will find many of the 'old hands' here telling posters to _always_ start with a 'flash an LED' test when something doesn't work. Verifying just what frequency a chip is running at, is an essential 'first test'.
Best Wishes |
|
|
f0raster0
Joined: 05 Nov 2010 Posts: 22
|
|
Posted: Sat May 11, 2013 7:44 pm |
|
|
The problem was 20MHz Crystal. I have changed it and my test works fine
Here my code for test
Code: |
#include <16F887.h>
#FUSES HS,NOWDT,MCLR
#use delay(clock=20000000)
#use rs232(baud=57600, xmit=pin_c6, rcv=pin_c7, bits=8,parity=N, ERRORS)
#include <lcd.c>
char ch;
#int_rda
void serial_isr()
{
ch = getchar();
puts("Hello test"); //ok
}
void main()
{
lcd_init();
enable_interrupts(int_rda);
enable_interrupts(global);
while(TRUE)
{
lcd_gotoxy(1,1);
printf(lcd_putc, "test LCD"); //ok
lcd_gotoxy(2,1);
printf(lcd_putc, "\n\r value %c",ch); // ok
}
} |
|
|
|
f0raster0
Joined: 05 Nov 2010 Posts: 22
|
|
Posted: Thu May 30, 2013 2:57 am |
|
|
Hey again
After solved my test.. I have been trying with my main code..
I want to read a tag and show it in LCD without apply power reset for read the next tag.
How can I finish the While(true) after the string is showed in LCD?
because at the moment my code read just one tag after any power reset.
I have used "break; " into of the While(true) but finish the While(true).. :-(
also used
Do {
if (xbuff<4)
} While(true);
Here my main-code, thanks for any help/idea :-)
Code: | #include <16F887.h>
#FUSES HS,NOWDT,MCLR
#use delay(clock=20000000)
#use rs232(baud=57600, xmit=pin_c6, rcv=pin_c7, bits=8,parity=N, ERRORS)
#include <lcd.c>
int const lenbuff=4;
int xbuff=0x00;
char cbuff[lenbuff];
char rcvchar;
#int_rda
void serial_isr()
{
rcvchar=0x00;
if(kbhit())
{
rcvchar=getch();
cbuff[xbuff++]=rcvchar;
}
}
//---------------------------------
void init_cbuff(void)
{
int i;
for(i=0;i<lenbuff;i++)
{
cbuff[i]=0x00;
}
xbuff=0x00;
}
//---------------------------------
void main()
{
disable_interrupts(int_rda);
enable_interrupts(int_rda);
enable_interrupts(global);
lcd_init();
init_cbuff();
While(True)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"%X %X %X %X",cbuff[1],cbuff[2],cbuff[3],cbuff[4]);
}
} |
|
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu May 30, 2013 6:33 am |
|
|
Hi,
Think about the problem a little bit. How big is your character buffer? How many elements are filled the first time you read an RFID tag? How many elements are filled the second time you read an RFID tag? Is there sufficient storage space inside cbuff[] to store the data from subsequent RFID tag reads the way your code is written?
Hint: you need to reset xbuff to zero after each complete read of an RFID tag....
A couple of other things: You should add a little bit of a delay after your lcd_init() routine to give the LCD sufficient time to power-up. Your init_cbuff routine is totally unnecessary. Since you execute this code only once at power-up, you can just zero the array and the counter when you declare these variables.
John |
|
|
f0raster0
Joined: 05 Nov 2010 Posts: 22
|
|
Posted: Fri May 31, 2013 2:32 am |
|
|
Hello John, thanks mate..
I have used " if(xbuff>=4) xbuff=0x00;" (again, I had delete it), but yes, without "init_cbuff();", so now it look perfect :-P
Code: | void serial_isr()
{
rcvchar=0x00;
if(kbhit())
{
rcvchar=getch();
cbuff[xbuff++]=rcvchar;
}
if(xbuff>=4) xbuff=0x00;
} |
|
|
|
|
|
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
|