I am trying to communicate two 16f877 .
It works like this:
PIC1: It reads PORTB and sends that data to PIC2, then it reads RCREG to see if other PIC2 has sent some data, and sends that data to PORTA.
PIC2: It reads RCREG to see if other PIC2 has sent some data and then reads PORTA and sends that data to PIC1.
But is not working. What is wrong with this code. Can't get it.
The code is :
;---------------------------------------------------------------------------
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207
;---------------------------------------------------------------------------
Actualy this up code is for "Transmitter" i.e. PIC1.
The code for "receiver" i.e. PIC2 is rather same:
;---------------------------------------------------------------------------
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207
;---------------------------------------------------------------------------
Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to
be set in order to configure pins RC6/TX/CK and
RC7/RX/DT as the Universal Synchronous Asynchronous
Receiver Transmitter.
Hi !
Thank you for your assistance.
I set TRISC to be all input. But still is not working.
The reason I don't set config information in the assembly program is that I set fusese in WinPicProg 1.91. and that setting overrides anything I set in assembly program. I set "POWER UP" and "Brown out" as allways and XT as I use crystal, other options are clear.
Is it possible that the problem might be in waiting PICs each others response ?
1. To use PORTA as digital you must set ADCON1 register, i.e.
movlw b'00000110' ; all analog pins = digital
movwf ADCON1
2. Allso, two wires in my hardware were disconnected - TX and RX ) . What a idiot I am ) Can't help my self in this stupid mistakes ever )
Now it works.
But very important question arises:
I know that is not posible for transmiter to know if receiving side has got the signal , but is there a way for receiving side to know if connection TX-RX is broken, i.e. the transmitting wire of PIC1 TX is not connected to RX of PIC2?
Assuming you are not transmitting only 0xFF or 0x00. You could always check if there is a change on the RX and TX pin every now and then with a simple "btfss PORTX,BitX" kind of thing