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

2 RS232 streams on a 16F876

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



Joined: 30 Dec 2005
Posts: 11

View user's profile Send private message

2 RS232 streams on a 16F876
PostPosted: Tue May 08, 2007 5:27 am     Reply with quote

Hello,

I'm using 2 RS232 streams, defined as follow :

Code:

#define SPM2   1
#define IRS    2
//                                        TX          RX
#use rs232(stream=SPM2, baud=19200, xmit=PIN_C6, rcv=PIN_C7)
#use rs232(stream=IRS , baud=57600, xmit=PIN_C2, rcv=PIN_C1, bits=8, parity=N)


I'm using the #INT_RDA interrupt to get byte from the ports in real-time :
can you tell me if the following code is legal or not :
Code:

#INT_RDA
void rda_isr() {
BYTE c;

if (kbhit(SPM2)) {

 c=fgetc(SPM2);

 // then treatement of the data

} //if SPM2

else  if (kbhit(IRS)) {
   c=fgetc(IRS);
 // then treatement of the data

} //if IRS

} //rda_isr


Because I'm receiving data from the SPM2 stream (the hard RS232),
but not on the IRS stream (the soft one)
(allthough I can send data on the IRS stream)

Thanks in advance
Philippe
Foppie



Joined: 16 Sep 2005
Posts: 138
Location: The Netherlands

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

PostPosted: Tue May 08, 2007 7:50 am     Reply with quote

this is not possible, int_rda will only trigger if the hardware uart receives a byte. If you want to use a interrupt for the other port as well you should use a chip with 2 uart. Else you should try to collect the bytes of your soft uart in your main program.

Hope this helps, Jos
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue May 08, 2007 10:24 am     Reply with quote

Quote:

Because I'm receiving data from the SPM2 stream (the hard RS232),
but not on the IRS stream (the soft one)

The behavior is according to your code.

The interrupt capability #INT_RDA is applicable only to devices with hardware
built-in UART. For most 16F series, this correspond to xmit=PIN_C6, rcv=PIN_C7

Quote:

if (kbhit(SPM2)) {
c=fgetc(SPM2);

It is not necesary to use kbhit() inside the hardware interrupt handler, it is redundant.
It is late to use it there, because before the statement if (kbhit(SPM2)), the START bit
already was detected by the hardware.
Thats why you are in the interrupt ! Idea !!! Shocked

To handle 2 RS232 streams with dedicated interrupts having only one UART, you
should re-wire the rcv_pin to the External Interrupt and capture the incoming
char inside the EXT_INT handler.

http://www.ccsinfo.com/forum/viewtopic.php?t=27826&highlight=stream

http://www.ccsinfo.com/forum/viewtopic.php?t=26808&highlight=stream


Humberto
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Tue May 08, 2007 1:02 pm     Reply with quote

I think philippe320 wanted to check for a byte on one stream or a byte on the other....
but..
A while(kbhit()) is handy in the ISR if you want to stay in ISR till the
2byte buffer is empty.
not jump out and back in. If for example you Rx another byte
while in the ISR. Sort of like checking
Flag bit RCIF. It is cleared when the RCREG
register has been read and is empty.
...edit...
checked for myself.
Code:
....................   while(kbhit(PC)){
0089:  BCF    03.5
008A:  BTFSS  0C.5
008B:  GOTO   0BE
....................     r_buf[r_i]=fgetc(PC);


Im'm no asm expert but its playing with c.5 and thats RCIF.
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