data on pins changes when interrupt is used

Thread Starter

aamirali

Joined Feb 2, 2012
412
I have written code which changes port1 bits (bit 19 to 26) & some other statements, & an other interrupt which changes port1 bits (bit 27 & 28).
Problem is when compiler comes to first part & meantime interrupt comes, data on pins got changes other than as expected.

But on checking individually, both parts worked correctly.I also did sigle steeping for both & they worked fine.

Does that mean data goes lost/corrupted. If yes how to avoid this.
 

GopherT

Joined Nov 23, 2012
8,009
There are two possible issues.

First, make sure your interrupt service routine correctly captures the status of all bits (first), makes appropriate interupt adjustments that you want, then restores the status bits to the pre-interupt condition, then return to your code. Make sure any variables and subroutines run during the interrupt are not overwriting variables from the main code (i.e, be carefull with "junk" variable names like: temp, counter, etc, that some people reuse in multiple areas of code). Un-expected changes during the interrupt can change the result of the main code.

Any changes to the input pins during the interupt service may not be noticed unless you specifically monitor changes.

Finally, Capacitance in the circuit attached to each pin may cause a read command (or mov command, to read current data (still in the process of updating) instead of the intended data (what you were expecting the data to be). This is especially true if you manually change bit values the read the port immediately (within 1 to 4 program steps) after the change.
 

RS-232D

Joined Dec 1, 2012
10
I'm thinking gopher gave the best answer probably without any specifics gave. I am presuming you meant single stepping, instead of sigle steeping? If so, then I am really thinking GopherT is right with a timing issue, and fluctuation in a possible read or write. you mentioned the data wasn't as expected. but was it consistently the same?
 

Thread Starter

aamirali

Joined Feb 2, 2012
412
Code is for LPC1317-64P. Mask is used to write specific bits only.Problem occur when ISR occur at same time as data changes on pins.

Edit: These three statements gets converted into 8 assembly instructions.

Rich (BB code):
void change()
{
  ........statemets
 .............
 LPC_GPIO->MASK[1] = ~(0x00f0);            //mask specific bits to write on port 1
 LPC_GPIO->MPIN[1] = 0xa0;                     //write the pins
 LPC_GPIO->MASK[1] = 0x00;                 //remove the mask
 ..................
 .................
}

void interrupt_any()
{
 LPC_GPIO->MASK[1] = ~(0x000f);
 LPC_GPIO->MPIN[1] = 0x0a;        
 LPC_GPIO->MASK[1] = 0x00; 
}
 
Last edited:

tshuck

Joined Oct 18, 2012
3,534
Code is for LPC1317-64P. Mask is used to write specific bits only.Problem occur when ISR occur at same time as data changes on pins.

Edit: These three statements gets converted into 8 assembly instructions.

Rich (BB code):
void change()
{
  ........statemets
 .............
 LPC_GPIO->MASK[1] = ~(0x00f0);            //mask specific bits to write on port 1
 LPC_GPIO->MPIN[1] = 0xa0;                     //write the pins
 LPC_GPIO->MASK[1] = 0x00;                 //remove the mask
 ..................
 .................
}

void interrupt_any()
{
 LPC_GPIO->MASK[1] = ~(0x000f);
 LPC_GPIO->MPIN[1] = 0x0a;        
 LPC_GPIO->MASK[1] = 0x00; 
}
You originally stated that the data is 8 bits and it affects two higher bits when an interrupt occurs. That isn't what this code is doing.

Perhaps you can explain what you see and what you expect to see.

Also, a schematic helps us from guessing too much...
 

Thread Starter

aamirali

Joined Feb 2, 2012
412
Hi
that just for reference I put. This is how bits are changed.I have a tft connected to port & this is how I change data.
 
Top