Serial received data not recognised

105 views Asked by At

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".

2

There are 2 answers

2
Akash Nil On BEST ANSWER

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.

0
Amol Saindane On

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