Hi all, New to this forum in a posting perspective but it's been a great help in a lot of areas from the start of my 8051 classes this year and last year so for that thanks. Im coming near the end of my final year project and I'v come across a slight problem with my interrupt implementation. I have RTFMed about all I can find on interrupts from any number of sources before you tell me to Please read the manual. The problem is that my ISR is triggered fine the first time sets a flag goes back carries out a function ... due to it not being a good idea to have function calls within an ISR ... resets flag and then sits reading the clock again however when I try to interrupt again it will not carry out the ISR this next time.
I have : reset external interrupt flag; reset condition variable flag; even attempted to re-enable external interrupt (even though this is probably not required);
The code is a long one so Id rather not post the entire thing here if anyone wants to take a look at it who has a good idea as to what I'm doing wrong or if anyone wants to suggest a specific part to post to look at the ISR or the menu its being called from please contact me. I will however not be sending this code on to anyone who's just looking for something to copy as I've read the manual to get it this far. I'd also be very happy to have someone look over the code in general for bad programming implementation if they would ... I'm a student in this subject but I've a keen interest in the field.
Also I'm Irish but this website is picking me up in America for some reason ?
Regards Robbie.
In all fairness, you did write "The 'C' programming language", not library.
Yes, that was deliberate.
That, and the "such" - meaning a direct comparison operator of multiple array elements.
I agree that memcmp() from the standard Library would seem like an ideal choice here.
In all fairness, I'm surprised nobody else picked this up.
;-)
Hmm would this take up more space to include or will my new error check suffice for my application ? I reworked it again after the potential for error cancellation.
Yeah im now lost tired and clueless.
i tried this as my last attempt I'm not even sure if this would work
void recieve(void) interrupt 4 { if (RI == 1) { RI = 0; card_id[s] = SBUF; s++; } }
like I said I haven't received any instruction on my course in interrupts so this is not going my way at all. I've tried a number of sites and books at this stage but im noot getting it at all.
Robert: in this code
You are very close. The way I would implement this is something like:
void recieve(void) interrupt4 { char c; if (RI==1) // a character recieve caused the interrupt { RI=0; c=SBUF0; // get the character } switch (state) { case WAITING_ID: { // // whatever you have to do to determine if this is an ID. state=WAIT_END; break; } case WAIT_END: { // whatever you have to do to determine if this is the end... if (end_of_packet) { state= DONE; } break; } case WAITING_START: { // whatever it takes to recognize that this is the start of the packet state=WAITING_ID; // prepare your buffer, and if this is based on a fixed length string, perhaps // initialize a counter and use it to determine when the packet ends. } } } elsewhere, you watch for state==DONE and then process the packet. When you are done, set state=WAITING_START; so that the state machine knows how to handle the next character. This code is skimpy on details, because I don't know how you recognize the start of the rfid read, and how you would recognize the id you want to extract, or recognize the end. If the packet is a fixed length, the simplest thing is to use a counter that starts at 0 when you recognize the start state, and decrement it, buffering the character until you find the ID, or else the end of the message. In a nutshell, this is a state machine that gets updated on each received character and reaches a DONE state after the full message is recognized. The main loop watches for the state to be tagged as DONE, then grabs the data, and resets the state to waiting for start (it might also reset the length etc.) This code as written probably won't run, and is certainly not a complete state machine for your application, but should give you an idea of what to do. The statemachine would recognize a start, buffer the data into a buffer until it recognizes an end. That can possibly be done by either a message count, or by analyzing the packet. I often implement protocols like this, and favor using a STX and EOT type protocol when I don't have binary data.
Thanks very much to everyone who gave me plenty to consider and so much food for thought I eventually found the problem with the ISR it turns out my code was working fine and I cannot believe no one saw the problem was that I was resetting IE instead of IE0. Now that was the most obvious problem however only today did notice it. So sometimes it is in fact the most simple solution that fixes these problems but look for complicated solutions and they will easily be found. Thanks again all, Robbie Dowdall.
Oh and a special thanks to Eric and Andrew for finding those errors that would have made me look a little thick :)