according to the dsPIC33 family datasheet "one instruction cycle is required between a port direction change or port write operation and a read operation of the same port. Typically, this instruction would be a NOP." (Microchip dsPIC family datasheet, section 10.4 I/O Port Write/Read Timing)
I tried to compile this simple code snippet:
Code: Select all
unsigned int a;
void main(void) {
TRISB=0xFFFF;
a = PORTB;
}
Code: Select all
;experiment.c,3 :: void main(void) {
;experiment.c,4 :: TRISB=0xFFFF;
$0206 $2FFFF0 MOV #65535, W0
$0208 $881630 MOV W0, TRISB
;experiment.c,5 :: a = PORTB;
$020A $801640 MOV PORTB, W0
$020C $88C000 MOV W0, _a
;experiment.c,6 :: }
Code: Select all
PORTB = 0xABCD;
a = PORTB;
So as a workaround it is possible to put a NOP manually; indeed it would be better to generate this code ad the compile level.
Hope this helps you.
picdog
[/code]