View previous topic :: View next topic |
Author |
Message |
nina
Joined: 20 Apr 2007 Posts: 111
|
max232 tx / rx |
Posted: Sun Jun 20, 2010 8:40 pm |
|
|
hi everybody....
Scenario is:
pic----max232----pc
Is it mandatory use ports tx and rx from pic to connect to max232?
Or can I specify another port as tx and rx using:
#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_B7, stream = name)
What does it mean stream? How does it work? Could you give me a example where can I use it?
thank you
nina |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Mon Jun 21, 2010 12:29 am |
|
|
No the hardware UART pins rx tx aren't mandatory since if you don't use them the CCS compiler will generate a software emulation on the alternative pins.
The max232 doesn't care which pins it is connected to.
Now using the hardware pins has very strong advantages since it can be interrupt driven. The software emulation of the uart is constraining in that your code must always read the software Rx pin in a tight loop so as to not miss any character.
STREAM has its best advantage when there is more than one USE RS232 statement since it labels each one. It is of value even when there is only one use rs232 statement since it can clarify the code and make it more obvious. getc(name) |
|
|
trirath
Joined: 14 Jun 2010 Posts: 20 Location: Pathunthanee Thailand
|
|
Posted: Mon Jun 21, 2010 1:51 am |
|
|
Just for your advantage please you see CCS Example SISR.C
which used receive msg with RDA Interrupt you can change this RDA into RB0 Interrupt (for test) instead and assign adding stream Name you want(Also PIN RX,TX need to be changed too).
And also need change putc(data); into fputc(STREAM NAME,data)
In actually, even if you use existing uart of PIC as example you can add stream name too. It have advantage in case of you need have more than 1 uart in a same PIC for assign which way you want to sent or receive.
Thank you |
|
|
nina
Joined: 20 Apr 2007 Posts: 111
|
tx/rx |
Posted: Mon Jun 21, 2010 6:22 am |
|
|
thank you very much for all explanation...
16f628 just has 1 tx and 1 rx.
If i want use another pins like RB2 (as tx) , RB3 (as rx) and use them with int_RDA, do I have to use max 232 connect to RB2 and RB3 to read values coming or going?
Tks
Nina |
|
|
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Mon Jun 21, 2010 7:17 am |
|
|
You can't. The serial interrupt uses the dedicated Tx and Rx pins (C6 and C7). If you are using other pins for tx and rx then you have to code them in software. It's not difficult but there is no buffering capability and you have to bit-bang to get the bits. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jun 21, 2010 2:29 pm |
|
|
Yes, the CCS compiler can generate a software UART for you, but:
- It does not support the interrupts.
- Is sensitive for timing errors (from timer interrupts, etc) for both the Tx and Rx.
- Only supports half duplex (can not send and receive at the same time).
- Requires (a lot) more processing power.
- Maximum baudrate of about 28k8 on a 16MHz PIC18.
- Can not buffer data in the background.
If your chip has a hardware UART, then use it. The only good reason for wanting to use a software UART on the other pins is when you need more than 1 UART. All other reasons I can think of are to do with a bad design.
Save yourself a lot of time and use the hardware UART. The software UART has limitations that will cost you a lot of time in the future (I speak from personal experience). |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Mon Jun 21, 2010 2:38 pm |
|
|
The best thing to do is to become very familiar with the data sheet on your PIC. Look it over multiple times and study the sections that you will be dealing with even more. All Interrupts use built-in hardware that, if it gets it's data from the outside world, is tied to a particular pin. If you want to receive data via RS232 and use the interrupt then you _must_ use the pins that are specified in the data sheet.
Ronald |
|
|
nina
Joined: 20 Apr 2007 Posts: 111
|
rs/tx |
Posted: Tue Jun 22, 2010 4:36 am |
|
|
Thank you everybody for all explanation...
The reason of my question is because I got RF modules (simple and cheap) to interface with PC and PIC and another PIC (receiver). So it will comunicate with COM_PC and COM_PIC.
I have seen those RF modules with linear output and digital output (receiver) and data input and rf output (transmiter). What does it mean those pins?
Which one do I need connect at TX and RX?
Thank you again.
Nina |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Tue Jun 22, 2010 10:00 am |
|
|
nina wrote: | I have seen those RF modules with linear output and digital output (receiver) and data input and rf output (transmiter). What does it mean those pins? | You need to work with the digital pins to get/send data. On some chips the linear pin gives analog signal strength.
nina wrote: | Which one do I need connect at TX and RX? | Depends on which device is the sender and which is the receiver. Connect the devices like this:
(sender's TX pin)-->(data pin of TX module) ~ ~ RF ~ ~ (data pin of RX module)-->(RX pin of receiver)
Rohit |
|
|
nina
Joined: 20 Apr 2007 Posts: 111
|
tx/rx |
Posted: Tue Jun 22, 2010 7:22 pm |
|
|
Rohit
Could you give an example where can I use linear pin?
tks
nina |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Wed Jun 23, 2010 10:05 pm |
|
|
nina wrote: | Could you give an example where can I use linear pin? | I'm sorry, I haven't ever used this functionality before. Maybe someone else can help. Here's what I got after a bit of googling:
Quote: | RSSI / Carrier Detect (pin 3) The Received Signal Strength Indicator provides a DC output voltage proportional to the RF input signal. The amplitude of the RSSI voltage increases with increasing RF signal strength. A simple transistor interface can yield a carrier detect logic output. |
Something similar is written in the datasheet for a Parallax RF module http://www.active-robots.com/products/parallax/datasheets/communication/27982-433%20MHzRFTransceiver-v1.0.pdf
Rohit |
|
|
trirath
Joined: 14 Jun 2010 Posts: 20 Location: Pathunthanee Thailand
|
|
Posted: Sat Jun 26, 2010 7:28 pm |
|
|
visit http://www.silaresearch.com/source.php (Thai) choose PKIT-5R for receiver and PKIT-5T for transmitter.
There are free source code that have advantage for this even if use old version CCS. |
|
|
|