Could this happen when the 2 pics are on seperate power supplies?
Might have something to do with all of those pauses you've got sprinkled in the code. If the pauses don't line up right (the moon, saturn, mars, etc), one part of the project, either the master or the slave, misses a reception at one time or another, and/or gets caught in the middle of one or the other...basically a sync'ing issue.
Hi Skimask
Must I remove all the pauses?
I am working on 2400 Baud and want to give enough time to transmit the data.
Thank you
Koossa
That's just it, you're giving it enough time to TX the data, but in the process of Pausing for 100ms afterwards, you might've missed 200-ish bits of serial data. The receive buffer is only 2 bytes deep (1 if you want be conservative). I'd say pause for 1 byte time, 4ms (2400 baud = .416ms/bit = 4.16ms/byte) instead of 100ms.
The SERIN and SEROUT commands won't let the program continue until they're finished transmitting or receiving.
HSERIN/HSEROUT, not sure about them, as I generally access the serial port registers directly rather than using the commands.
I would assume that they would act the same as SERIN and SEROUT for continuity purposes, but, I would hope that they would be 'non-blocking' commands (unless WAIT is used with HSERIN of course).
Don't know if I understand you correctly, but here is my new code
MASTER PIC
<HR>
<p> 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 &n bsp; VAR PORTD.2 ' LED to confirm PIC is running
DATARECEIVED VAR BYTE
'======== HSEROUT, HSERIN SETTINGS ==========
DEFINE HSER_RCSTA 90h
define HSER_TXSTA 20h
define HSER_SPBRG 103
DEFINE HSER_CLOERR 1
RCIF VAR PIR1.5
TXIF VAR PIR1.4
ADCON1 = 7
TRISC = %10000000
Main:
HIGH LEDPIN ' Indicate PIC is running
HIGH DE_OR_RE ' Make ready for TX
PAUSE 4
HSEROUT ["S0"] ' Send "S0"
LOW LEDPIN
LOW DE_OR_RE ' Make ready for RX
PAUSE 4
SEROUT RS232_DEBUG_PIN,N2400,["WAITING FOR REPLY..", 13, 10] ' DEBUG TO PC
if RCIF then
hserin 100,Main,[WAIT ("R",DATARECEIVED]
ENDIF
SEROUT RS232_DEBUG_PIN,N2400,["REC:",DATARECEIVED, 13, 10] 'DEBUG TO PC
GOTO Main
END</p>
<HR>
SLAVE PIC
<hr>
<p> Include "Modedefs.bas"
DEFINE OSC 4
DE_OR_RE VAR PORTC.5 ' DE and RE Pin of SN75176
LEDPIN &n bsp; VAR PORTD.2 ' LED to confirm PIC is running
DATARECEIVED VAR BYTE
'======== HSEROUT, HSERIN SETTINGS ==========
DEFINE HSER_RCSTA 90h
define HSER_TXSTA 20h
define HSER_SPBRG 103
DEFINE HSER_CLOERR 1
RCIF VAR PIR1.5
TXIF VAR PIR1.4
ADCON1 = 7
TRISC = %10000000
Main:
HIGH LEDPIN ' Indicate PIC is running
LOW DE_OR_RE ' Make ready for RX
PAUSE 4
LOW LEDPIN
if RCIF then
hserin 100,Main,[WAIT ("S",DATARECEIVED] ' Looking for "S0"
IF DATARECEIVED = "0" THEN
&n bsp; HIGH DE_OR_RE ' Make ready for RX
&n bsp; PAUSE 4
&n bsp; HSEROUT ["R1"] ' Send R1
ENDIF
endif
GOTO MAIN
END</p>
<hr>
As soon as I connect the Master pic to the power I get the following, does not matter if the Slave pic is running or not, it return the same data.
<b>
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
REC:˙
WAITING FOR REPLY..
</b>
Thank you
Koossa
I think you've got the idea...but one other thing I just thought about...
You're checking RCIF in the code. If you're checking RCIF, that means there's already a byte in the receive buffer. HSERIN probably waits for the next byte to come along (basically ignoring what's already in the buffer). If you're already WAITing for a specific character, then why also wait for a flag in hardware? Also, you can make use of the TIMEOUT in the SERIN/HSERIN to keep your code from getting stuck.
Thank you, I will remove the RCIF and see what happens.
There is a 100ms Timeout in my code.
Koossa
Bookmarks