Aaron Aaron - 2 months ago 6x
C Question

Why would comparisons on my Xmega work when a breakpoint is set on that line, but not when running normally?

I am using an Xmega384C3, and all I am trying to do is send a signal down an output port and read it on an input port. I have

set as an output port, and
set as an input port. The corresponding pins on each port are shorted together (PortA pin 0 to PortC pin 0, etc).

My issue appears in the following code:

uint8_t i;
int count = 0;

for(i=2; i<8; i++) {
PORTC.OUT = (1 << i);

if (count == 6) {

I basically just want to read that when I send a logic high down a pin on
, that I can read it on the corresponding pin on
. When I let the code run normally, it does not find any matches and therefore never increments count. However if I add a break point on the line where the if comparison occurs, it then evaluates to true and increments count as expected. Additionally, I can see the ports have the correct values in Atmel Studio's I/O view feature. Any ideas?


It was a timing issue of not allowing long enough for the value on the pin to reflect what I set it as in the code. The issue was resolved by adding a 1 micro second delay using the delay function _delay_us(1) from the delay.h library.