View previous topic :: View next topic |
Author |
Message |
densimitre
Joined: 21 Dec 2004 Posts: 45
|
How #RDA_int works? vs kbhit() ? |
Posted: Wed Jun 29, 2005 10:02 pm |
|
|
Hi
Im interesed in to know how #rda_int works---
1.- How many bytes arrives to activate the interrupt?
2.- Does the interrupt returns to the previous state of program after receive a char on usart?
3.- If my modem echoes the AT commands sent to it, i should be disable the rda_int wainting finish the command?.
4.- what diference exist between rda_int versus kbhit for this purpose?
Thank you very much
Bye |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Thu Jun 30, 2005 1:07 am |
|
|
densimitre wrote: |
1.- How many bytes arrives to activate the interrupt?
|
1 byte is enough to fire the ISR.
densimitre wrote: |
2.- Does the interrupt returns to the previous state of program after receive a char on usart?
|
Yes.
densimitre wrote: |
4.- what diference exist between rda_int versus kbhit for this purpose?
|
kbhit() is for polling the buffer. You can use kbhit() like this
Code: |
int8 i = 0, c = 0x00;
while (i < TIMEOUT)
{
if (kbhit()) // check if there is a character
{
c = getc(); // waits until the character arrives. it can wait FOREVER.
break;
}
delay_us(10); // delay depends on you data rate
++i;
}
if (i == TIMEOUT)
{
// handle timeout
}
|
#int_rda is a declaration of the ISR. |
|
|
densimitre
Joined: 21 Dec 2004 Posts: 45
|
|
Posted: Thu Jun 30, 2005 11:18 am |
|
|
Thank you
Then, if a want receive a string like "<CR><LF>OK<CR><LF>", the rda_int drives each character individually and exit the isr routine, to receive next charecter again?
Example:
the modem echoes the AT (tested using hyperterminal), then rda_int fires for A char and T char? one after one?..or fires once for entire string?
Sorry for the questions, but i am a lit confused...
Bye |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Thu Jun 30, 2005 12:27 pm |
|
|
#INT_RDA should be used only if the involved microcontroller has
the internal built-in hardware USART.
kbhit() is used widely to implement a software USART only to detect the START bit.
Using hardware USART, kbhit() return TRUE if a character has been received and is
waiting to be read in the hardware buffer.
A software USART can be enhanced if it's combined with #INT_EXT and
int_ext_edge(H_TO_L) function to get an interrupt when receiving
a char in RS232.
Then inside the #INT_RDA or #INT_EXT isr you can use the function getc()
to get the incoming character.
kbhit() From the manual
Quote: |
If the RS232 is under software control this function
returns TRUE if the start bit of a character is being sent
on the RS232 RCV pin. If the RS232 is hardware this
function returns TRUE is a character has been received
and is waiting in the hardware buffer for getc() to read.
This function may be used to poll for data without
stopping and waiting for the data to appear. Note that in
the case of software RS232 this function should be
called at least 10 times the bit rate to ensure incoming
data is not lost.
|
Keep well,
Humberto |
|
|
|