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 CCS Technical Support

Using RS232 pins as normal i/o - How is it done?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
SteveC



Joined: 09 Jul 2004
Posts: 10

View user's profile Send private message

Using RS232 pins as normal i/o - How is it done?
PostPosted: Fri Jul 09, 2004 8:35 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 09, 2004 10:58 am     Reply with quote

See my post in this thread, which shows how to switch between
a soft and hard USART on the same pins. It has some ideas
which may help you.
http://www.ccsinfo.com/forum/viewtopic.php?t=19737&start=0
SteveC



Joined: 09 Jul 2004
Posts: 10

View user's profile Send private message

PostPosted: Fri Jul 09, 2004 11:10 am     Reply with quote

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 Very Happy

Steve.
SteveC



Joined: 09 Jul 2004
Posts: 10

View user's profile Send private message

PostPosted: Mon Jul 12, 2004 5:57 am     Reply with quote

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

 
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