I have set up the PI 3B/2B devices with 64 bit OS ( bookworm & Trixie ) and tested UART RS 485 connection, it is found that the RS-485 libmodbus communication is not working.
I have done all the necessary settings in /boot/firmware/config.txt file to get the UART enable, but still it is failing, below is the settings from config.txt file for your reference.
[all]
enable_uart=1
dtoverlay=disable-bt
dtoverlay=miniuart-bt
dtoverlay=uart0-pi2,rs485,rts_inverted=1
dtoverlay=uart0-rts485
I am using the RPI enabled libmodbus library, where switching between DE/RE is done using the function - modbus_configure_rpi_bcm_pins.
Below is the is the code from Master –
def get_Modbus_client(device="/dev/serial0".encode("ascii"), baud=9600, parity="N".encode("ascii"), data_bit=8, stop_bit=1, timeout=1.5, slave_id=1):
client = None
if is_simulated_environment():
try:
client = Modbus_Windows_Client()
except:
print("Exception")
else:
client = ModbusRtu(device, baud, parity, data_bit, stop_bit)
timeout_sec = client.get_response_timeout()
if client:
client.set_response_timeout(timeout)
# Connect
r = client.connect()
client.flush()
BCM_PIN_DE = 18
BCM_PIN_RE = 18
# Set Slave ID number
client.set_slave(slave_id)
# Enable RPi GPIO Functions
# client.enable_rpi(1)
# Define pin numbers to be used as Read Enable (RE) and Drive Enable (DE)
client.configure_rpi_bcm_pins(BCM_PIN_DE, BCM_PIN_RE)
# Export pin direction (set as outputs)
client.rpi_pin_export_direction()
return client
Kindly check the same and do let me know if I am missing any settings/ parameters to be set which could cause this issue.
I have set up the PI 3B/2B devices with 64 bit OS ( bookworm & Trixie ) and tested UART RS 485 connection, it is found that the RS-485 libmodbus communication is not working.
I have done all the necessary settings in /boot/firmware/config.txt file to get the UART enable, but still it is failing, below is the settings from config.txt file for your reference.
[all]
enable_uart=1
dtoverlay=disable-bt
dtoverlay=miniuart-bt
dtoverlay=uart0-pi2,rs485,rts_inverted=1
dtoverlay=uart0-rts485
I am using the RPI enabled libmodbus library, where switching between DE/RE is done using the function - modbus_configure_rpi_bcm_pins.
Below is the is the code from Master –
def get_Modbus_client(device="/dev/serial0".encode("ascii"), baud=9600, parity="N".encode("ascii"), data_bit=8, stop_bit=1, timeout=1.5, slave_id=1):
client = None
if is_simulated_environment():
try:
client = Modbus_Windows_Client()
except:
print("Exception")
else:
client = ModbusRtu(device, baud, parity, data_bit, stop_bit)
timeout_sec = client.get_response_timeout()
Kindly check the same and do let me know if I am missing any settings/ parameters to be set which could cause this issue.