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
Per,
Thank you for your (relevant) input.
The OP now surely has enough to aid his understanding ;)
'my code monkey manual states that...'
Yeah, I thought so... so I wrote it down... just to be CLEAR about it.
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA
I suggest you read and understand the WHOLE thread - Heck, I hope you don't read data sheets in this manner! I read and understood both the 'code' and the datasheet (in this case "the bible")
www.nxp.com/.../80C51_FAM_HARDWARE_1.pdf
"the interrupt system will generate an LCALL to the appropriate service routine, provided this hardware-generated LCALL is not blocked by any of the following conditions: 1. An interrupt of equal or higher priority level is already in progress.
Adj. 1. dependant - contingent on something else
See www.thefreedictionary.com/dependant
Your link states: dependant Noun a person who depends on another for financial support USAGE: Avoid confusion with dependent.
anyhow, unless you post again, not related to the Ops problem, but to my postings, I will let this be my final word.
erik
Just one more note about atoi().
The function is intended for use with C strings, but all atoi() implementations I have seen don't care about the existence of a terminating zero as long as there are any other non-digit character terminating the number.
But good-quality code should very explicitly make sure that there always are any form of termination of the number. And relevant code should be grouped together, so the termination character should either be transmitted on the serial link, and used to flag the potential start of an atoi() call, or the termination should be explicitly performed very close to the source lines that receivers the four digit characters and assigns them to the array. The goal is to allow the developer to see a block of code, and without scrolling showing all relevant code to understand what is happening. When too much source lines are needed to get a clear overview, it is time to factor the code into multiple, simpler, functions.
Performing some assigns in an interrupt handler, and some assigns to the same array in the main loop is not a good solution, since that results in a loss of overview. Without the overview, a code change in one section of the code is then likely to introduce bugs because the other section was not updated correspondingly.
The use of "magic numbers" - the value 4 for number of characters - makes this problem even bigger. If the serial transmission is changed to send 5 characters instead, then the loop waiting for all characters has to be changed. And the code line that assigns the termination character has to be changed, unless the code is rewritten to instead increment a character pointer.
Thanks Per and Stephen.
I will re-structure the interrupt to collect chars one at a time. Its clear this is not optimal
For the atoi() problem, I can easily add an alpha char to the front of the string. I always terminate these command strings with a '\n' so this should sort that issue out if I check this and then do the atoi() afterwards.
Anyway, I'll be off line for a few days - other problems to deal with right now.
Again, appreciate the help.
Jason.
Just to clarify
SIN = 57 SIN = 48 SIN = 49 SIN = 50 SIN = 10 (line feed)
I did not list all the chars I was inputting via the simulator.
Erik,
A little ENGLISH lesson for you ...
The word dependant when used in the context:
"...totally dependant upon the rest of the code."
is not a noun.
So, yet again, you have tried to indicate a fault in something that is correct.
A little advice - If you want to argue about semantics, ensure you have a cogent argument.
Regardless of context, "dependant" is always a noun, unless it is a misspelling and should actually read "dependent".
"Dependent" can be a noun, in which case it's an alternative form of "dependant", or an adjective.
Erik is correct, and the link he gives explains things quite nicely.
Please don't go around trying to teach people incorrect English.
<Extremely big sigh>
Consider British English.
The link that you attribute to Erik (which I actually gave to him) clearly shows a definition for dependant as an adjective (adj=adjective).
If you use a search engine or look in a British English dictionary, you can check for yourself.
Here is another link:
www.audioenglish.net/.../dependant.htm
Just for the record, I will change one thing:
So, yet again, you have tried to indicate a fault in something that is not incorrect.
Your link does.
"USAGE: Dependant is the generally accepted correct spelling in British usage for the noun and always refers to people: if you are single and have no dependants. The adjective should be spelt dependent: tax allowance for dependent (not dependant) children. American usage spells both adjective and noun with an e in the last syllable."
<Even bigger sigh>
Look at the Thesaurus entry and my other link and the many others.
Shame you can't see my British English dictionary that I have right in front of me.
Regardless, all this chatter didn't do anything to reveal the meaning of this gem:
"I see in the above posts that drawing the OPs attention to values made someone think I was ignorant of what they were, as in if I say "do you see the sunset" I am unaware of it ????"
Jesus Christ (sorry, Jack Sprat! I had to) people, can't you find a proper forum to discuss English spelling...? I think we had enough. Don't you agree?
Hello Tamir,
I totally agree - Besides which, I'm all sighed out!
You will hear no more on the subject from me.
Stephen.
look, up in sky! Its a bird, its a plane its... its Super Code Monkey!
No offense. Well partially none.
Vince,
No idea what your on about (or on), but your post made me laugh.