View previous topic :: View next topic |
Author |
Message |
philippe320
Joined: 30 Dec 2005 Posts: 11
|
2 RS232 streams on a 16F876 |
Posted: Tue May 08, 2007 5:27 am |
|
|
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
|
|
Posted: Tue May 08, 2007 7:50 am |
|
|
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
|
|
Posted: Tue May 08, 2007 10:24 am |
|
|
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 ! !!!
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
|
|
Posted: Tue May 08, 2007 1:02 pm |
|
|
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. |
|
|
|