We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a strange problem in my code. I cannot receive characters via the serial port.
I've read up on the TI and RI interrupts and I think I am handling these correctly.
The program goes to the serial I/O isr, but just sits at the gets(comin,4) line. When I examine comin in the watch window and input chars via the SIN = xx (where xx is an ascii code), I can see the comin array remains empty.
Below is the serial I/O interrupt routine (my application does not need Tx)
pre void uart_rx_isr (void) interrupt 4 using 3 { signed char index=0; EA=0;
if (RI == 1) { gets(comin,4); command = atoi(comin); } RI=FALSE; /* finished isr - clear flag */ TI=FALSE; /* TI will not be used - always clear it*/ EA=1; }
/pre
Here is a fragment from main() - you can see that I set TI=1 initially to set the UART up
pre
TI=TRUE; /* always set TI=1 initially to allow serial printing */ RI=0;
loop: //RI=0; //IDLE
while ((1));
goto loop; } /pre
Appreciate some pointers here.
Jason
HI.
i have tidyed yo're code.
void uart_rx_isr (void) interrupt 4 using 3 { signed char index=0; EA=0; if (RI == 1) { gets(comin,4); command = atoi(comin); } RI=FALSE; /* finished isr - clear flag */ TI=FALSE; /* TI will not be used - always clear it*/ EA=1; }
TI=TRUE; /* always set TI=1 initially to allow serial printing */ RI=0; loop: // RI=0; //IDLE while ((1)) ; goto loop; }
they're a lot of things wrong.
the bigest i think is yo're interrupt. it gets called when they're is one char from uart. but you call 'gets" to get more char's. where do u think they will come from?
u must change yo're isr to collect the char's. one at a time.
also u must clear ri if it is set. not evry time.
r u using tx anywear? if u do not then u do not set ti.
Alway's yo're freind.
Zeusti.
Thanks Zeusti. Iwill try your recomendations tonite.
I don't know this processor architecture so I don't know if the following is even supported, but maybe the OP is using serial communication with a FIFO which explains why he tries to read more than one character...?
/*------------------------------------------------*/ /* Interrupt service routine to handle the Rx input which comes in via RxD on pin 11 */ /* of the 89LPC922 */ void uart_rx_isr (void) interrupt 4 using 3 { int index=0; EA=0; if (RI==1) /* if RI is set then execute the RxD routine, else jump over and exit*/ do { comin[index] = (getchar()); index++; } while (index<4); RI = FALSE;/* clear the RI interrupt flag and exit */ EA=1; } /*---------------------------------------------*/ <PRE/> This works!
void uart_rx_isr (void) interrupt 4 using 3 { .... while (index<4);
show such a lack of understanding that you need to go back to basics and do some studying
first study question: a) what is the value if 'index' at the first entry to the while():? b) what will happen then?
Erik
the questions above is for the OP, DO NOT answer them for him/her.
I know your love of showing off by doing the thinking for the posters, but that does NOT help them
Zeusty likes to proclaim himself as "professor", "horrified", "honored" etc. Given Eric's comments, I suggest a new one: "Reprimanded Zeusty" :-)
question for ERIC.
what do u think the line from his isr does:
int index=0;
so index is good when it enters the loop.
<quote> such a lack of understanding that you need to go back to basics and do some studying </quote>
he has a lot wrong and i did not give all answers. just the one with the big big problem.
but u just confuse and indicate that something is wrong when it is right. not done well but not wrong.
Always yo're freind.
at the beginning i said i will stay for a while.
my time is now over and i need to leave.
so i say goodbuy.
Forever yo're freind.
Ho Zeusti, do care to come back! We will be missing you! Please don't go! Who will guide the flock :-)
Erik . . . . .
these are set at the top of the program as static ints and initialized to zero. I only showed code fragments remember. In main() these same variables are also manipulated. So, its taken care of.
Please try bit more accomodating of newbies.
Anyway, back to more intersting topics.
MY CODE IS WORKING!!!!
For those that were constructive, thank you!
Just to clarify, I was referring to comin[] in my statement above.
Zeutsi is correct - index is initialized at the start of the isr.
MY CODE IS WORKING!!!! for a while if index ever get to 4 you are stuck (oh I know "that will never happen")
I DO "accomodate of newbies", just not with pat solutions from which nobody learns anything.
For those that were constructive if you consider leaving you free not to think "constructive", you will never get abnywhere.
For what it's worth:
Assuming that you are expecting a four character response (and only a four character response), I cannot see what would be wrong with your while loop.
That said, as one of the respondents indicated, it would be sensible to rethink the interrupt service routine to accumulate one character per interrupt call.
Additionally I would suggest that you ignore some of the responses that seem to crop up in this forum from the self proclaimed and/or belligerent experts. Do yourself a favour, search the forum to examine their posting history and style; and make up your own mind.
Only 4 chars will ever be used and no more in this application.