|
|
View previous topic :: View next topic |
Author |
Message |
SteveC
Joined: 09 Jul 2004 Posts: 10
|
Using RS232 pins as normal i/o - How is it done? |
Posted: Fri Jul 09, 2004 8:35 am |
|
|
Hello,
I've searched the forum, but not found an answer to this one. My application is based on an 16F873 (although developing on a PICDEM2 Plus) and has two RS232 ports. One port is the main port to communicate with a peripheral, and the other port is a passthrough port that connects to a PC for control of the peripheral. My device takes the place of the PC for simplified operation, but must not get in the way of operations if a PC is connected. The code is here:
Code: |
#include <16F877.h>
#fuses XT,WDT,PUT,NOBROWNOUT
#use delay(clock=4000000, restart_wdt)
#use rs232(baud=4800,parity=N,xmit=PIN_C6,rcv=PIN_C7, RESTART_WDT)
boolean outside_active; // Used to monitor for activity from outside world. If any then need to immediately disable keypad activity, and just pass all comms back and forth.
struct rs232_port
{
boolean empty1; // RC0 and RC1 used for 32.768KHz crystal drive on PICDEM2, so not used for ease
boolean empty2; //
boolean TX2; // Data to outside world
boolean empty3; // RC3 and RC4 are connected to the temp sensor on the PICDEM PCB, so not used for ease.
boolean empty4;
boolean RX2; // Data from outside world
boolean TX1; // Data to xxxxxxxx
boolean RX1; // Data from xxxxxxxx
} rs232;
#byte rs232 = 7 // This puts the entire structure on to PORT C (at address 7)
void passthrough()
/* Called when global outside_active is true. passthrough just takes all transitions from external RS232 and passes them to
the xxxxxx, and all comms from xxxxxxxx and passes them to the external RS232. This is an infinite loop. Once called
it doesn't exit until switch off!
*/
{
while (1) // Repeat forever!
{
RS232.TX1=RS232.RX1;
}
}
void main() {
setup_counters(RTCC_INTERNAL, WDT_18MS);
set_tris_a(0x3f); // 6-bit port - All inputs
set_tris_b(0xf1);
set_tris_c(0xbb); // 10111011
RS232.TX1=0;
RS232.TX2=0;
passthrough();
// Now for the main loop
do
{
// monitorserialdata();
// getserialdata();
// displaydata();
} while (true); // Stay in the loop forever
} |
(The commented out bits are not relevant to the problem, and this code is just for testing!)
Fundamentally I want the state of the RS232 TX pin (from PIC) to mimic the state of the RX pin (i.e. this should just be a loopback), and that's all.
The problem is that it doesn't work when I have the #use RS232 clause. If I comment it out then passthrough works fine. Problem is that I need the RS232 set up - I can read the RS232.RX1 pin, as that is tested to determine that there's been outside activity, and the test works. So, how do I arrange it so that I can poke bits to the TX pin after the RS232 clause? Is there a way to override the #use RS232? I've tried another #use RS232, set to talk to different pins, but that doesn't fix it either.
Thanks for reading.
Steve. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
SteveC
Joined: 09 Jul 2004 Posts: 10
|
|
Posted: Fri Jul 09, 2004 11:10 am |
|
|
Hello,
Thank you very much for the reply - I'm off for the weekend now, and won't get a chance to get back onto this until Monday, but I'll check out the information over the weekend.
I really appreciate the help
Steve. |
|
|
SteveC
Joined: 09 Jul 2004 Posts: 10
|
|
Posted: Mon Jul 12, 2004 5:57 am |
|
|
Hello again,
The answer is now obvious! I just need to disable the uart!
Code: | bit_clear ( RCSTA, SPEN ); // Disable serial port |
Then I found this in the compiler readme.txt dated 4th July 2004: Quote: | A new function has been added: SETUP_UART that works the same as SET_UART_SPEED.
A new feature of this function is when a FALSE (or 0) is passed it turns off the UART
and when a TRUE (or 1) is passed in it turns the UART on. Passing in a baud rate also
turns on the UART. |
Doh!
Thanks again.
Steve. |
|
|
|
|
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
|