Reputation: 451
I am connecting PIC with Raspberry PI through a serial port. My max485 transmit and receive enable pin is controlled by gpio pin. My received data is printed successfully. But it is not performing the desired function.
while True:
GPIO.output(repin, False)
port.flushInput()
time.sleep(.oo5)
port.write(bytes(address))
time.sleep(.01)
GPIO.output(repin, Ture)
port.flushInput()
data=port.readline()
if data:
address=address+1
if data == "ok" :
print "reached"
print data
if not data:
print "no data"
when I am receiving OK. It prints "ok" but it didn't print "reached". And when data is not received it is printing a blank value instead of "no data".
Upvotes: 0
Views: 94
Reputation: 703
There is nothing wrong in your code. If you write PIC program correctly then the problem is coming from the proper termination resistors of max485.connect twisted pair cable ground with proper resistance.
Upvotes: 1
Reputation: 1598
Check your UART_Write
method at PIC
micro-controller side. Are you sending \r
or \n
extra along with ok
? You can clarify that by using debugger at PIC
and monitoring the PIC
UART write register in watch window, which is TXREG
Upvotes: 1