At 21:06 30/05/99 -0700, you wrote: >Hi all, > >Didn't manage to get hold of the right caps yet, but I replaced the LS parts >with HCT's, (now the whole circuit is HCT) and this seemed to help, but not cure >the problem - comms errors are now much less frequent. However, I did find some >very bizarre timing dependancies in the code. > >PORTC is attached to a 74573 transparent latch, and PORTD is attached to a 74245 >transceiver, both of which are enabled. The 573 outputs' low 5 bits are attached >to the PC parallel port's 5 input lines (BUSY,ACK,SEL,PE,FAULT). The 245's >inputs come from the parallel port's D0-D7 lines. > >My main comms function receives 16 bits from the PC, and sends 8 bits to the PC. > >The PC AUTOFD line is attached to pin B7 on the PIC, and, along with the BUSY >input (bit 4 on the 573) is used as a handshake line. > >PCSwap > bsf PORTA,ENABLE ; portA controls the enables on the latch and > ; transceiver > movf SHADOW_C,0 ; retrieve previous PORTC value > movwf PORTC ; write to PORTC > bsf PORTA,ENABLE ; enable transparent latch and transceiver >lp1 btfsc PORTB,7 ; wait for low on PC AUTOFD line > goto lp1 > movf PORTD,0 ; retrieve first byte from the PC > movwf PC_RECV_0 ; store first byte > movf PC_SEND,0 ; get byte to send to PC > andlw b'00001111' ; want to send low nibble first > iorlw b'11100000' ; keep spare bits high, keep bit 4 low > movwf PORTC ; write data > bsf PORTC,4 ; *now* raise the handshake line >lp2 btfss PORTB,7 ; wait for high on PC AUTOFD LINE > goto lp2 > movf PORTD,0 ; retrieve second byte from the PC > movwf PC_RECV_1 ; store second byte > swapf PC_SEND,0 ; get byte to send to PC (swap nibbles) > andlw b'00001111' ; mask off what was the high nibble > iorlw b'11110000' ; keep spare bits high, keep bit 4 high > movwf PORTC ; write data > bcf PORTC,4 ; *now* lower the handshake line > bcf PORTA,ENABLE ; disable latch and transceiver > movwf SHADOW_C ; keep copy of last port C value > bcf SHADOW_C,4 ; for retrieval next time > return ; go do other stuff.... > >The corresponding PC code is: > > Set byte 0 data on D0-D7 > Lower AUTOFD > Wait for BUSY hi > Read 4-bits of data from the other 4 input pins > Set byte 1 data on D0-D7 > Raise AUTOFD > Wait for BUSY low > Read 4-bits of data from the other 4 input pins > >This works fine. However, when I move some lines of code around, so that > > movf PORTD,0 ; retrieve first byte from the PC > movwf PC_RECV_0 ; store first byte > movf PC_SEND,0 ; get byte to send to PC > andlw b'00001111' ; want to send low nibble first > iorlw b'11100000' ; keep spare bits high, keep bit 4 low > movwf PORTC ; write data > bsf PORTC,4 ; *now* raise the handshake line Read write modify instruction BSF PORTC.4 Reads the state written to PORTC, then writes it back Try andlw b'00001111' ; want to send low nibble first iorlw b'11100000' ; keep spare bits high, keep bit 4 low movwf PORTC ; write data iorlw b '00010000; movwf PORTC > >becomes > > movf PC_SEND,0 ; get byte to send to PC > andlw b'00001111' ; want to send low nibble first > iorlw b'11100000' ; keep spare bits high, keep bit 4 low > movwf PORTC ; write data > movf PORTD,0 ; retrieve first byte from the PC > movwf PC_RECV_0 ; store first byte > bsf PORTC,4 ; *now* raise the handshake line > >(and similarly for the second byte/nibble) > >things stop working. Note that I'm still not raising the handshake line until >the very end, and also that the PIC isn't messing with the data until the PC has >acknowledged it. It's not a timing thing as far as the PC goes, because I've >single-stepped through the PC code, and it still goes wrong! > >It's a completely synchronous protocol - the slight timing difference shouldn't >make a difference, but it does. Grrr.. Interestingly, the modified code crashes >with astonishing regularity. It looks like the PIC is getting the wrong data >from PORTD, and since the first byte is treated as an "instruction" of sorts, >it's jumping off into other code, and crashing. > >Sorry for the length of this post, but it's hard to describe the problem with >any brevity! So, does this still sound like a bypassing problem? > >Cheers, >Ben > >