View previous topic :: View next topic |
Author |
Message |
young
Joined: 24 Jun 2004 Posts: 285
|
RS232 on 12f675 |
Posted: Wed Jul 28, 2004 7:25 am |
|
|
Does any one know if I could use 12f675 pin as RS232 communication port. and if it is possible, how? |
|
|
Ttelmah Guest
|
Re: RS232 on 12f675 |
Posted: Wed Jul 28, 2004 7:34 am |
|
|
young wrote: | Does any one know if I could use 12f675 pin as RS232 communication port. and if it is possible, how? |
Yes, using the 'software' UART the compiler provides.
However you must be aware, that this can only receve or transmit at one time, and really nothing else can be being done by the processor while using the comms.
It depends on what you actually want to do 'with' the serial whether his is likely to do what you want.
Best Wishes |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Jul 28, 2004 7:38 am |
|
|
You can use one of the GP I/O pins with a software UART. Beware the internal oscillator frequency may not be stable enough for reliable comms. You may need a crystal or external clock. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Wed Jul 28, 2004 7:50 am |
|
|
Right now I just need send data, no receiving, so it sound resonable to use one pine and software UART. I have been using external crystal to for RS232 communication at 4Mhz, 12f675 has an internal crystal at 4Mhz, my devcie does not alow me to provide external crystal. so I am thinking to use internal crystal for a try. however, I have never use softare, even hardware uart, would you please tell me how to use it?
thank you! |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Wed Jul 28, 2004 8:26 am |
|
|
Is
Code: |
#use rs232(BAUD=9600, XMIT=PIN_A0, RCV=PIN_A1, BITS=8, PA
RITY=N)
| definition software uart? what is the Hardware definition for 12f675? which pins? can I only define XMIT because I just need send data?
beside my special case, is it possible to use both software uart and hardware uart simultaniously. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Jul 28, 2004 8:36 am |
|
|
The manual entry for use rs232 covers it pretty well. Many of the example programs shipped with the compiler, like EX_ADMM.C use simple serial comms too.
I don't think the 12f675 has a hardware UART so you don't have to worry about it. The compiler will automatically use a software UART. If you only specify the Xmit pin it will leave out the receive code.
Double check the accuracy of the internal "crystal". It is not an actual crystal and you need about 3% or better for reliable comms. It may work at room temperature but fail when hot or cold. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Wed Jul 28, 2004 8:43 am |
|
|
Thank you for help, how to "Double check the accuracy of the internal "crystal""? How do I know if it has about 3% or better reliaility for reliable comms? |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Jul 28, 2004 9:37 am |
|
|
Read the (fine) data sheet from Microchip. Download it from their web site. Print out parts that look interesting. There should be a section about the internal oscillator with graphs of accuracy vs. voltage and vs. temperature.
If you are 3% off in timing after 10 bits you will be 30% of a bit off which is a lot. 5% error will leave you with 50% of a bit error after 10 bits which is asking for trouble. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Wed Jul 28, 2004 9:45 am |
|
|
thanks a lot |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Jul 28, 2004 4:01 pm |
|
|
Have an application using the PIC12F675 running with it�s internal oscilator, receiving and
transmiting at 9600 baud without problems.
I tested the frequency deviation. It�s very close to +/- 1% in the range of 0�C to 75�C .
You will be aware - for mass production - that the accuracy of the internal precision oscillator
could be up to +/- 5% in the full industrial temperature range.
Best wishes,
Humberto |
|
|
Guest
|
|
Posted: Thu Jul 29, 2004 8:37 am |
|
|
If I just need a pin, for example PIN_A5 pin to sent data, I do not need another pin for Receive data. what I should connect the Receive RX to, a Low (0) or High (1) in order for the RS232 to function? |
|
|
Ttelmah Guest
|
|
Posted: Thu Jul 29, 2004 8:48 am |
|
|
Anonymous wrote: | If I just need a pin, for example PIN_A5 pin to sent data, I do not need another pin for Receive data. what I should connect the Receive RX to, a Low (0) or High (1) in order for the RS232 to function? |
You don't use another pin at all.
The transmit and receive 'parts' of the software UART, are seperate. So you can code:
#USE_RS232(BAUD=9600, PARITY=N, BITS=8, XMIT=PIN_A0)
This then only implements the transmit code, and no other pin is needed. The code itself gets placed 'inline', when you subsquently print a character (or more).
The only 'caveat', is that you cannot transmit on pin A3. This pin is input only on the 12F675.
The wiring needed, is to connect the TX pin on the PIC, to a RS232 level translator (technically there are ways to possbly avoid this when using the soft UART, but it is the better solution anyway...). The output of this then connects to the RX pin on the computer (assuming you are talking to a PC). The TX pin of the PC goes nowhere. You might want to connect the RTS pin on the computer, to the CTS pin, and the DTR pin to the DSR pin (this will make the computer know that the port is active).
The ground lines must also connect.
Then you have communications.
Best Wishes |
|
|
Guest
|
|
Posted: Thu Jul 29, 2004 9:06 am |
|
|
I used the following code, however, I could not see any data transfer in hyperterminal?
Code: |
#if defined(__PCM__)
#include <12F675.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,PUT,NOMCLR
#use delay(clock=4000000)
#use rs232(baud=9600, parity=N, xmit=PIN_A5)
void main()
{
while(1) {
putc('a');
}
} |
|
|
|
Guest
|
|
Posted: Thu Jul 29, 2004 10:55 am |
|
|
any suggestions? |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Jul 29, 2004 11:31 am |
|
|
This is where I hook up an oscilloscope to see what bits the PIC is actually sending. If you don't have a scope you can use a logic probe if you set the baud rate really slow, like 100 baud.
See what the PC transmits. That will tell you the shape of the bits it is expecting to receive. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|