|
|
View previous topic :: View next topic |
Author |
Message |
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
What interrupt state to use in software RS 232 |
Posted: Fri Aug 04, 2006 11:18 am |
|
|
Hi,
I am using the INT_EXT interrupt to detect incoming RS 232 data on a software usart (in 16F648A) , In the ISR i use the kbhi function to get the character.
Is it ok to use H_TO_L or L_TO_H for the level detection ???
Also is the kbhit() fnction required , could I not just use fgetc(stream) instead, like this
Code: |
#int_ext
void ui_isr()
{
nUIRcv=fgetc(UI);
bUIRcvFlg=1;
}
|
thanks
arunb |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Aug 04, 2006 12:31 pm |
|
|
Quote: |
Is it ok to use H_TO_L or L_TO_H for the level detection ???
|
You must define H_TO_L in the edge detection definition.
RS232 levels definitions:
Received Data (RxD): When no data is transmitted, the signal is held in
the mark condition (logic '1', negative voltage). In the TTL side: is a HIGH level
You will find good info of the RS232 Standard in:
http://www.camiresearch.com/Data_Com_Basics/RS232_standard.html#anchor1155404
Quote: |
Also is the kbhit() fnction required , could I not just use fgetc(stream) instead, like this
Code:
#int_ext
void ui_isr()
{
nUIRcv=fgetc(UI);
bUIRcvFlg=1;
}
|
kbhit() it is not necesary inside an edge detector interrupt like INT_EXT.
Is is redundant. kbhit() is usefull when you do not want to wait forever - like
getc() does - to detect an incoming char inside a loop. In this case kbhit()
is usefull but taking care that the loop should not be longer that 1/10 of the expected
byte (=~ 1 bit long) to not lost a char.
fgetc(stream) is used when you have multiple UART handlers, to tell the PIC in
wich pin is expected a char "to get".
#use RS232(rcv=PIN_n, ...,STREAM=From_Device_A)
fgetc(From_Device_A) redirect the getc() to the pre-defined stream pin, that way the
microcontroller is aware from where the chars will come from.
If you use only one RS232, it is not necesary the fgetc(stream) function, using solely getc()
will be enough, because the PIC already "knows" the Rx pin.
Using the INT_EXT capabilities to detect the Start bit edge should 'capture' the incoming
char with the help of any of the built in functions like getc(), fgetc(stream), etc.
Humberto |
|
|
|
|
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
|