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

Multiple serial communication . . . (newbie)

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



Joined: 29 Oct 2008
Posts: 7

View user's profile Send private message

Multiple serial communication . . . (newbie)
PostPosted: Wed Oct 29, 2008 1:26 pm     Reply with quote

Hi everyone, I need to make an intelligent splitter. What I mean is, I need to connect 3 rs232 interfaces with a PIC (I've chosen the 16F877) and control the data flow.

I try using PICBASIC but I couldn't. I can't loop the 3 pins until the PIC receives data from one of the 3 devices. Sad

Can I do that with CCS and 16F877?

Regards

Ivan.
tranz



Joined: 10 Feb 2007
Posts: 78

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

PostPosted: Wed Oct 29, 2008 1:49 pm     Reply with quote

Well with CCS you can put hardware and software interrupts on those pins and loop the software interrupts. So when the data comes in from any of those 3 terminals your micro would be able to handle the request based on which terminal sends the data first.

Regards

Tranz
ivan_ult



Joined: 29 Oct 2008
Posts: 7

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 2:59 pm     Reply with quote

Tranz, thanks for answer, as I've read the getc function waits until a character has come in, what I need is loop the reception of the 3 rcv pins and play with the data, here is part of my code.
Code:

#use rs232(baud=9600,parity=N,xmit=PIN_B0,rcv=PIN_B1,bits=8,stream=COM0)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B3,bits=8,stream=COM1)
#use rs232(baud=9600,parity=N,xmit=PIN_B4,rcv=PIN_B5,bits=8,stream=COM2)


byte DATA0=0;
byte DATA1=0;
byte DATA2=0;


myloop:
   DATA0=getc(COM0);
   DATA1=getc(COM1);
   DATA2=getc(COM2);
   goto myloop;

As I understand COM1 can't receive data until COM0 receives.

Is that right?

If so, how can I wait for data from any of the input ports ?

Some code. Very Happy


Regards . . .

Ivan.
tranz



Joined: 10 Feb 2007
Posts: 78

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

PostPosted: Wed Oct 29, 2008 4:49 pm     Reply with quote

Well based on your loop
Quote:


#use rs232(baud=9600,parity=N,xmit=PIN_B0,rcv=PIN_B1,bits=8,stream=COM0)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B3,bits=8,stream=COM1)
#use rs232(baud=9600,parity=N,xmit=PIN_B4,rcv=PIN_B5,bits=8,stream=COM2)


byte DATA0=0;
byte DATA1=0;
byte DATA2=0;


myloop:
DATA0=getc(COM0);
DATA1=getc(COM1);
DATA2=getc(COM2);
goto myloop;




COM1 will not receive data till COM0 receives it. What I ment was a hardware interrupt like

Code:

#int_rda
void isr()
{
//functions to be performed when this interrupt occures
}




look up EX_SISR.C example at C:\Program Files\PICC\Examples. Also all the terminals will not work at the same baud rate i.e. 9600. So you need to have different baud rates for different terminals.

When it comes to software interrupts you can use a template like this

Code:

while(1)
{
if (kbhit(COM1))
{
//functions to be performed
}

if (kbhit(COM2)) 
{
//functions to be performed
}
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 5:09 pm     Reply with quote

Please consider, that a software RS232 implementation won't be able to receive simultaneously at more than one pin. At best, it will be aware in time of an incoming character, when the baud rate isn't too high and the loop through the different kbhit() functions isn't too complex.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Oct 29, 2008 9:47 pm     Reply with quote

It is possible to use timers and external interrupts to implement interrupt driver software uarts especially given your baud rates are very low. It would be a lot easier with an 18F than a 16F to achieve this.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 29, 2008 10:21 pm     Reply with quote

You could think along the lines of using a dual bidirectional switch per channel, sort of like a mux-demux arrangement, with one end of each switch connected to the PIC, and the other end connected to a MAX232 or equivalent line driver. This way you can utilize the PIC's UART hardware. You will need to include some sort of signalling or flow control, and you will be able to transmit only intermittent data using this method.

I have successfully used such a system using a 16F628A as a 'master controller' and two RS232-enabled theater lighting controllers. The PIC enable the first switch; it would send a command to the first controller; the controller would respond accordingly. Then it would enable the second switch, and do the same. The data rates were low (19200 baud) and intermittent, so this method served well.

This was just a small test project, but it worked flawlessly.

Rohit
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Thu Oct 30, 2008 8:23 am     Reply with quote

Alternatively, you could bring all 3 serial inputs to to pins of PORTB, and use the interrupt-on-change feature to tell you when something has happened. But then you'd be looking at changes on the line, not the arrival of a complete character or even a predictable time within one bit. Nevertheless, I think it's possible. I just want to see someone else put the time into writing the code ;-)
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Thu Oct 30, 2008 8:36 am     Reply with quote

I did a very similar type function in the past as the previous post stated. I had multiple lines that I needed to see with an interupt. I took the three input lines through diodes so the signals did not interfere with each other, and fed them into B0. Then watching for an interupt on B0 change, I would check each input to see which one it was. This was done on a 16F690 at 8Mhz. It would probably work for slower baud rates, but you would really have to play around with it some. Good luck.
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
ivan_ult



Joined: 29 Oct 2008
Posts: 7

View user's profile Send private message

PostPosted: Thu Oct 30, 2008 2:12 pm     Reply with quote

First, thanks everybody for answer.

I've solved the issue, a simple program (part of the code)
Code:

myloop:
   if (kbhit(PC))
      {
      PC_DATA=fgetc(PC);
      fputc(PC_DATA,INSERTER);
      flash_tx1();
      }
   if (kbhit(INSERTER))
      {
      INS_DATA=fgetc(INSERTER);
      fputc(INS_DATA,PC);
      fputc(INS_DATA,ETHERNET_SERIAL);
      flash_tx0();
      }
   goto myloop;

The program works fine (I probe it with 3 serial devices), the problem is when I connect one of the ports to an specific machine (actually old machine from 80's) I get trash in the data.

So, somebody knows something about noise reducing circuits?

Thanks in advance.


Ivan
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