write_with_readback: ldi r16, 0xFF ; Set all pins as output out DDRx,r16 ; -"- out PORTx, r16 ; Set the PORTx values in r16,PINx ; Read the PINx values in r17,PINx ; Read the PINx valuesWhen running this example program at full speed in the ICE200 or in a real chip, the value read back in r16 will not end up being the value written at the first line, but will contain the value the port pins had the cycle before the port was written. This is the correct behavior. The PINx value must be synchronized, and therefore it is delayed, one cycle to avoid erratic port behavior caused by metastability. r17 will therefore contain the value written to the port. However, when the program is single stepped, the value of the PINx will change immediately after the single-step and the value of r16 will contain the same value as before.
Changing pin values on an I/O port from AVR Studio when the ICE200 emulator is stopped does not represent any problem. However, note that, as for the single stepping case, the pin values are changed immediately.
Clearly this is not a real problem, but it is important to be aware of the effects of the two cases described above. If not, an incorrect program might seem to work in the emulator, but will not work in the real chip.
See Also