It takes at least 87.5ms for each of those SEROUT debug statements to execute at 2400 baud. My guess is that both sides are getting sync'd up into not receiving each others inputs and they both end up missing each others outputs.
How about getting rid of them and try to use LEDs to see if either program is getting what it should? Maybe use a couple of switches on one, and LEDs on the other, and get one PIC to follow the other PIC.
Failing that, how about this:
SLAVE
----------------------------------------------------------
Include "Modedefs.bas"
DEFINE OSC 4
DE_OR_RE VAR PORTC.5 ' DE and RE Pin of SN75176
LEDPIN VAR PORTD.2 ' LED to confirm PIC is running
DATARECEIVED VAR BYTE
'======== HSEROUT, HSERIN SETTINGS ==========
DEFINE HSER_RCSTA 90h
define HSER_TXSTA 24h
define HSER_SPBRG 103
DEFINE HSER_CLROERR 1
RCIF VAR PIR1.5:TXIF VAR PIR1.4:ADCON1 = 7:TRISC = %10000000
pause 200:HIGH LEDPIN
Main:
hserin 10,MAIN,[WAIT ("S"),DATARECEIVED] ' Looking for "S0"
IF DATARECEIVED = "0" THEN
HSEROUT ["R1"] ' Send R1
else
hserout ["RZ"] ' Send something to signify SOMETHING received
ENDIF
GOTO MAIN
END
--------------------------------------------------------------------------------
MASTER
--------------------------------------------------------------------------------
Include "Modedefs.bas"
DEFINE OSC 4
DE_OR_RE VAR PORTC.5 ' DE and RE Pin of SN75176
RS232_DEBUG_PIN VAR PORTB.5 ' Debugging to PC
LEDPIN VAR PORTD.2 ' LED to confirm PIC is running
DATARECEIVED VAR BYTE
'======== HSEROUT, HSERIN SETTINGS ==========
DEFINE HSER_RCSTA 90h
define HSER_TXSTA 24h
define HSER_SPBRG 103
DEFINE HSER_CLROERR 1
RCIF VAR PIR1.5:TXIF VAR PIR1.4:ADCON1 = 7:TRISC = %10000000
PAUSE 200:HIGH LEDPIN
Main:
HSEROUT ["S0"] ' Send "S0"
SEROUT RS232_DEBUG_PIN,N2400,["WAITING FOR REPLY..", 13, 10] ' DEBUG TO PC
hserin 100,Main,[WAIT ("R"),DATARECEIVED]
SEROUT RS232_DEBUG_PIN,N2400,["REC:",DATARECEIVED, 13, 10] ' DEBUG TO PC
GOTO Main
END




Bookmarks