CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

RS232 on 12f675
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

RS232 on 12f675
PostPosted: Wed Jul 28, 2004 7:25 am     Reply with quote

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
PostPosted: Wed Jul 28, 2004 7:34 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 28, 2004 7:38 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 28, 2004 7:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 28, 2004 8:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 28, 2004 8:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 28, 2004 8:43 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 28, 2004 9:37 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 28, 2004 9:45 am     Reply with quote

thanks a lot
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Jul 28, 2004 4:01 pm     Reply with quote

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








PostPosted: Thu Jul 29, 2004 8:37 am     Reply with quote

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







PostPosted: Thu Jul 29, 2004 8:48 am     Reply with quote

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








PostPosted: Thu Jul 29, 2004 9:06 am     Reply with quote

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








PostPosted: Thu Jul 29, 2004 10:55 am     Reply with quote

any suggestions?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Jul 29, 2004 11:31 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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