This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ISR Corruption Issue

Hello, Clancy.  

We were having a problem with I2C (though realistically, it probably affects the whole commBuff ISR, regardless of whether it's I2C or SPI).  What we've narrowed it down to is a switch statement in the ISR.  

We are sending 8 commands per second via I2C and after a while (it ranges from a few minutes to half an hour), the chip appears to lockup.  However, on closer inspection, the chip itself is still running.  However, it appears that some variables in the ADC ISR are being corrupted/changed, causing our CalcDAC routine to fail to run anymore.  The basic code looks like this:

void commBuff_ISR (void) interrupt 6    using 3
{
        unsigned char commData;

EA = 0;    /* Added 04-23-13 */

        commData = COMBUF; /* Read Data from COMBUF */

        if((CommandState!=7)&&(CommandState!=8)&&(CommandState!=10)&&(CommandState!=11)&&(commData==0x24))
        {
                        CommandState = 0;
        }


        switch (CommandState)
        {
                case (0):
                        if (commData == 0x24) /* 0x24 = '$' */
                        {
                                CommandState +=1;
                        }

                        else if (commData == 0x62)      /* 0x62 = 'b' */
                        {
                                COMBUF = DigOut;
                        }
                        break;
                default:
                        break;
        }
EA = 1;    /* Added 04-23-13 */
}

This is just to display the functionality of the code (not the entirety of the code.  We actually have 14 additional switch cases that are not shown here).  What I found is that the switch statement seems to be causing some kind of issue that is causing corruption in the ADC ISR.  If I change the switch statement to an if statement instead, it seems to fix the issue.  
I posted about this in the keil forums (under the name of John Dough. I've had issues with the people in that forum in the past.  At this point, I don't give them my name there anymore):

http://www.keil.com/forum/22943/
 They seem to suggest it's related to the PGA400 itself rather than Keil (personally, I have a hard time believing that but I thought I would talk to you about it).  Do you know anything about this or why it would cause issues between the ISRs?
Any help you can give me would be appreciated.  Thanks!
-Jeremy
  • Jeremy,

    My apologies for the delay in this response.  I thought that I had replied awhile ago, but apparently it didn't go through.  My bad.  I've attempted to re-create this issue but haven't had any luck so far.  I ran it for three hours sending 5 SPI commands per second after adding the code you supplied above to the commBuff ISR, and had no issues.  I'll do the same thing again using I2C tomorrow.

    Have you made any progress?  Can you share some code with me that causes this issue on your end?  It does sound likely that this is a compiler problem.  Can you try using a different compiler?  Maybe even an older version of Keil?  Have you tried looking at the assembly code around the affected region like Steve suggested?

    Thanks,

    -Clancy

  • Jeremy,

    Today, I tried it for an hour using I2C instead of SPI, and I'm still not having the lock-up issue that you mentioned.  Do you have any updates on your end?

    -Clancy

  • This thread will be closed for the time being due to lack of activity.

  • Sorry for the extremely late reply, Clancy.  Honestly, our code is huge and there's a lot going on and, short of posting our code here (which we can't do), I'm not sure how I can recreate it, short of spending a lot of time creating an example program that doesn't have a lot of our core code in it.  I'll just send you an email directly if I manage to do that.  But I can't post our code, especially in a public forum.  

  • Jeremy,

    Of course I understand not being able to post your code here.  I was more asking if you had created a shorter test program specifically for this issue that you could share.

    How would you like to proceed?  Is there anything I can do on my end to help?

    -Clancy