Jump to content

Nano Pi with RS485


Rafal

Recommended Posts

Hi I would like to ask you how to use MAX485 module to communicate 2 NanoPi Neo Core 2.
I would like to use UART0 (it is GPIO4 and 5). I connection my module similar to this picture:


https://www.google.com/search?q=max+485&client=ubuntu&hs=ern&channel=fs&tbm=isch&source=iu&ictx=1&fir=FN56jmGIPP4yJM%3A%2CBP52RgiAvdjG4M%2C_&vet=1&usg=AI4_-kQK1TQEVXzv7J4_kJ8nEnLbgH0X5w&sa=X&ved=2ahUKEwjxy57J2oHhAhVpsosKHZTnCnAQ9QEwBHoECAUQDA#imgrc=Jkfuqm9JL_mJXM:&vet=1

 

I wrote python3 code send.py :

import RPi.GPIO as GPIO
import time
import serial
import os

EN_485 = 24
GPIO.setmode(GPIO.BOARD)
GPIO.setup(EN_485,GPIO.OUT)

print("Test1")
send_str = input("Wiadomosc testowa 123123123")
ser = serial.Serial(port='/dev/ttyS0',baudrate =115200,bytesize=8,stopbits=1,timeout=1)
last_time = time.time()
print("Test2")
now_time = time.time()
GPIO.output(EN_485,True)
time.sleep(0.01)
n = 80

try:
    while n>0:
        ser.write(send_str)
        n=n-1
        time.sleep(0.5)
        print(n)

except KeyboardInterrupt:
    GPIO.output(EN_485,False)

But when I started program it 'freeze' on the line ser=serial.Serial(port[...]). So it print only "Test1" and waiting. Maybe someone have any idea why this program stop and waiting in this line?


 
Link to comment
Share on other sites

34 minutes ago, Rafal said:

Maybe someone have any idea why this program stop and waiting in this line?

UART0 is "in-use" by the kernel as "serial-debug", you need to disable that to get access to it.

Better try to use UART1 or UART2 available on the header ...

Link to comment
Share on other sites

In my experience RS485 (especially at 115200 baud) is VERY troublesome without a suitable UART, which the Allwinner H5 does not contain.  If you are designing the protocol then maybe (I did), otherwise consider alternatives.

 

I suggest using a Beaglebone Black instead.  The OMAP UART has what's needed.

 

Link to comment
Share on other sites

...or, if you really have your heart set on a NanoPI or other Allwinner/Rockchip device, consider adding an NXP SC16IS750 UART beside your MAX485 chip.  Awesome UART, deep FIFOs, 9 bit mode, automatic RS485 turnaround.  Then write a devicetree overlay for add this SPI device (don't forget an interrupt pin), and build a kernel with the sc16is7xx driver included. 

 

Link to comment
Share on other sites

1 hour ago, richardk said:

NXP SC16IS750 UART

Yes ! I like this family ...

I've built an OPiPC+ Piggy back board that has 2 SC16IS752, dual UART, that make 4 additionnal UARTs along the 3 already available on OPi+ header, total of 7 RS485 buses.

1 hour ago, richardk said:

suitable UART, which the Allwinner H5 does not contain

That can be workarounded : adding emulation "em485" using plain GPIOs, I've a private patch for that inspired by the patches done by Giulio Benetti :

https://lkml.org/lkml/2018/6/1/344

 

Link to comment
Share on other sites

Hi thank you for yours ideas. I work with module MAX485+ and work perfect with AVR micro-controller. I would like to have RS-485 protocol to my nanoPi. I saw we can easily connect raspberry pi to max485 module :
https://www.google.com/search?client=ubuntu&channel=fs&tbm=isch&sa=1&ei=hJOPXLSpDaSurgTl6LfoCg&q=MAX485+rpi+&oq=MAX485+rpi+&gs_l=img.3...793957.793957..794407...0.0..0.82.82.1......1....1..gws-wiz-img.3g77RWZ6_Xc

So we can connect Rpi to this module but nanoPi doesn't work?

 

Link to comment
Share on other sites

2 hours ago, Rafal said:

So we can connect Rpi to this module but nanoPi doesn't work?

This is all about the DE pin which control the HalfDuplex direction.

Either you implement the "em485" patch within the 8250_dw serial kernel driver for automatic direction control using RTS pin, or you do it into you own application using plain GPIO, enabling the DE only during transmit.

Link to comment
Share on other sites

Hi Martinayotte,

 

I would be interested in the em485 patch for orange pi pc board. The goal would be to use it with uart to rs485 MAX3485 for modbus communication. 

Do you know when it would be available ? 

Are there any limitations in terms of reliability / baud rate  / parity / stop bit / etc.. ?

 

I am ready to help, test, and make donation. 


Best regards,

 

Etienne

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines