|
|
View previous topic :: View next topic |
Author |
Message |
MFK
Joined: 24 Oct 2007 Posts: 12
|
PIC 18F4520 with RS232 |
Posted: Mon Jan 28, 2008 3:23 pm |
|
|
Hi ,
i want to set up a system with an RFID device , which sends all 1.5 seconds 38byte of data. I want to collect this data with the PIC and send them to the PC. I don't know if have a schematic problem ? When I connect everything and let the system run I don't really get the data i want to have to. When I hold the serial pin direct to the pin on the breadboard where I take the data to the PC , the right data is shown.
Here's a thematic picture.
http://picasaweb.google.com/Mark.Knechtle/PIC/photo#5160636416797567186
I use an easy program which should just take the whole stream and send it to the PC.
My Program looks like :
Code: | #include "....PIC files\18F4520.h"
#use delay(clock=20000000)
#use rs232(baud=57600, xmit=PIN_C6, rcv=PIN_C5,RESTART_WDT,stream=READER)
#use rs232(baud=57600, xmit=PIN_C4, rcv=PIN_C7,RESTART_WDT,stream=PC)
#include <stdio.h>
#include <input.c>
void serial()
{
int i=0;
char inputstream;
inputstream=getchar(Reader);
sprintf(PC,inputstream);
}
void main()
{
while(true)
{
serial();
}
}
|
You can assume that I hopefully connected the Max chip right and that the Grounds are on one Level.
Is it possible that the noise through the Breadbord gets tooo high or do I have general problems.
Thanks.
greetz |
|
|
Ttelmah Guest
|
|
Posted: Mon Jan 28, 2008 3:37 pm |
|
|
First comment. Why are you using sprintf?. sprintf, is the function to send data to a _string_. You need to use fprintf, to send formatted data to a stream. fputc, would be the 'better' choice for the single characters you are sending.
Second (and potentially big) problem. You are not using the hardware serial in either direction. To use the hardware serial I/O, _both_ of the hardware pins must be selected on a single stream. You have the TX pin on one stream, and the RX pin on the other. This will force the use of software serial on both streams. As such, data cannot received, while a character is being sent on the other stream, and data _will_ be lost. Assign both the hardware pins to whichever stream normally receives data (reader), and use software serial on the other stream.
Best Wishes |
|
|
MFK
Joined: 24 Oct 2007 Posts: 12
|
|
Posted: Mon Jan 28, 2008 4:42 pm |
|
|
Hi thanks for the fast reply. I'm not sure if I understand you complete. I tried to avoid the hardware serial pins C6 and C7 , I tried before with these without the max and it didn't work.
I can't sent any data to the reader , theres coming only one pin from it to receive.
Do I have to use C6 and C7 with the UART protocol or can I just only use the pins on any Port for example D6 and D7.
So I can't assume when I read the stream, that it will finish reading the stream and then start sending the data. Ok now it comes to my mind that I make an array with 38 bit , read until its full, and send afterwords :-)
Thanks. |
|
|
Ttelmah Guest
|
|
Posted: Tue Jan 29, 2008 3:17 am |
|
|
Hardware port, cannot, work without a level translator chip (MAX232 or similar). This was why it didn't work...
Software ports, can be made to work to 'some extent' without this, using resistors, and the 'invert' option, but not really 100% reliably. Go back to using the hardware port, or you have 'no hope', if the data is coming in continuously.
Use the hardware port to receive the data. The hardware buffer, will allow data to be received, _while_ you are sending the output data.
Don't worry, if you don't want to use both pins of the hardware port. Set both up in the #use line, then either simply ignore the other pin (code won't be generated for this, if you don't use it), or turn it off. A search in the forum, will find examples (several posted by me), of how to turn off half the hardware port.
Yes, reading the whole string, storing it, and outputting it in the gaps, will be safer, _provided_ the gaps are long enough, and you can 'know that you have identified the start of the 'packet'.
Best Wishes |
|
|
MFK
Joined: 24 Oct 2007 Posts: 12
|
|
Posted: Tue Jan 29, 2008 11:54 am |
|
|
Hi Ttelmah,
i really made some progress with your help. I did go one step back. I used the PIC with my software development board and Pin C6 as transmit pin. I just send a few characters from the PIC to my MAX controller and from there to my PC, just to check if my max is well connected, and it worked. My problem is now , when i change my PIC to the breadboard it doesnt work anymore. I use a 20 MHZ oscillator at the pins OSC1 and OSC2 with 2 15pF capacitors to ground.
My fuses look like this
Code: | #include <18F4520.h>
//#device ICD=TRUE
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=20000000) |
Do you have any advices ????
I really appreciate.
Thanks. |
|
|
Bob Sacamano
Joined: 17 Jan 2008 Posts: 16 Location: Somewhere Cold, USA
|
|
Posted: Tue Jan 29, 2008 1:05 pm |
|
|
You have the LVP fuse set. How are you programming the chip? An ICD does not use low-voltage programming. You probably need to use the NOLVP fuse. _________________ "And you want to be my latex salesman." |
|
|
MFK
Joined: 24 Oct 2007 Posts: 12
|
|
Posted: Tue Jan 29, 2008 1:41 pm |
|
|
I upload the program via ICD, take the chip out an connect it in the Bread Board. |
|
|
Bob Sacamano
Joined: 17 Jan 2008 Posts: 16 Location: Somewhere Cold, USA
|
|
Posted: Tue Jan 29, 2008 1:48 pm |
|
|
Change the LVP fuse to NOLVP. _________________ "And you want to be my latex salesman." |
|
|
MFK
Joined: 24 Oct 2007 Posts: 12
|
|
Posted: Wed Jan 30, 2008 8:22 am |
|
|
Even after correcting the Fuses it wasn't possible to program the PIC in the Software Prototype Board , disconnect the voltage and use it afterwards in the breadboard.
I made me an adapter for the breadbord for the ICD cable. It works when i write my program over the ICD at the PIC. Afterwards it works fine.
But I still don't know where my problem was ???????
Thanks for the help. |
|
|
|
|
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
|