Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How about using two RS-232 in PIC

Status
Not open for further replies.

swapgo

Full Member level 2
Joined
Jun 24, 2004
Messages
128
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,298
Location
India
Activity points
1,244
rs232 18f8722

Hi All,

I think it is possible to use 2 UARTS in PIC.

I am using pic18f8722. I use CCSC pcwh compiler.

Has anyone tried this before?

What is the maximum baudrate supported by the PIC? I want to try 19200.

Actually my project involves 3 UARTS.

Any help is appreciated.

Thanks and Regards
Gopi
 

ccs rs232 18f8722

Hi,

If simultaneous full duplex is not needed then you can simply use AND gates to read from as many (theoritical ) USART from one only. Handshake and interrupt based reads does the job.

Regards

Sougata
 

Re: TWO RS-232 in PIC

Hi Swapgo,
Yes, you can do it by using streams. For example:
#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7,stream=HOSTPC)
Then when you use the stream:
fputc(c,HOSTPC);

The method is in the CCS help file.
Here is a clipping:
Code:
The #USE RS232 (and I2C for that matter) is in effect for GETC, PUTC, PRINTF and KBHIT functions encountered until another #USE RS232 is found.

 

The #USE RS232 is not an executable line.  It works much like a #DEFINE.

 

The following is an example program to read from one RS-232 port (A) and echo the data to both the first RS-232 port (A) and a second RS-232 port (B).

 

#USE  RS232(BAUD=9600, XMIT=PIN_B0, RCV=PIN_B1)

void  put_to_a( char c ) {

   put(c);

}

char  get_from_a( ) {

    return(getc()); }

#USE RS232(BAUD=9600, XMIT=PIN_B2,RCV=PIN_B3)

void put_to_b( char b ) {

   putc(c);

}

main() {

   char c;  

   put_to_a("Online\n\r");

   put_to_b("Online\n\r");

   while(TRUE) {

     c=get_from_a();

     put_to_b(c);

     put_to_a(c);

   }

}

 

The following will do the same thing but is more readable and is the recommended method:

 

#USE RS232(BAUD=9600, XMIT=PIN_B0, RCV=PIN_B1, STREAM=COM_A)

#USE RS232(BAUD=9600, XMIT=PIN_B2, RCV=PIN_B3, STREAM=COM_B)

   

   main() {

      char c;

      fprintf(COM_A,"Online\n\r");

      fprintf(COM_B,"Online\n\r");

      while(TRUE) {

        c = fgetc(COM_A);

        fputc(c, COM_A);

        fputc(c, COM_B);

      }

    }
I usually don't use streams though. I usually just put a
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
before each use. For example, if I have a serial port on pin c6 and c7 as above (these pins are for the hardware USART,) and another on bins b5 and b6, then before using that port I would put #use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B6)

As for baud, 19,200 should be possible, you just want to choose a crystal which will give least error at that rate.

Hope this helps, but if you have any questions, I'll try to answer.
Best wishes,
Robert
 

Re: TWO RS-232 in PIC

Thanks Robert,

Will 20Mhz be able to generate a baud rate of 19200 without errors.(I mean with less error).

I have to use 4800,9600 and 19200 in the same PIC IC. Will you recomend any PIC IC?

The Flash requirement will be about 6K.

Thanks a Lot

Regards
Gopi
 

Re: TWO RS-232 in PIC

Hi Gopi,
Well, you said you had a 18F8722, which has a lot of features. You will get a lot out of the data sheet, especially on the two EUSARTs which this beast has. I think it has auto baud rate detection as well. I didn't think about that when I first responded. I'd use one for the fast port, and another for the 9600. Then use a software port for the slow one. This pic should handle it well, at 20 MHz. What is it you are doing, anyway?
By Flash requirement, did you mean program memory?
You have a full 128k (bytes) of program memory. You also have almost 4k of ram, so you should be able to fit a huge program on this baby.
As for the oscillator, you have the high speed phase locked loop oscillator option, although using this can be tricky. (I usually avoid it for now.) What this means is that if you want to use a 10 MHz crystal, you can multiply that by 4x to have a 40 MHz clock. Ten million instructions per second. WoW! This high frequency can have lots of problems on a circuit board, though, and myself, usually don't go past 20, for now. That is what I'd recomend for you, too. However, I urge you to go get the data sheet on this baby, and enjoy it. You have a lot of power there, may as well use it.
Gopi, do you know about the CCSforum? There are some really smart, and helpful people there. I usually just read, on that board. :)

Let me know what you decide.
Regards,
Robert
 

Re: TWO RS-232 in PIC

Hi Robert,

Thanks!!!

I will visit the ccsc forum as u suggested!.

The flash I mentioned is program memory!!!

I plan to go for lower version of PIC ICs (16 series) because of the cost.

But for development I start developing with higher version and gradually port it to lower end!!!

Thanks again for your answers

Regards
Gopi
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top