-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with RS485 direction control #68
Comments
I did some more testing and found that when reading the response I always get first a single byte 0x00 and after that the actual response frame. The single byte causes the reported So I did a simple modification throwing away always the first single byte of the response. This basically works. However quite often the response frame is not received completely, leading to CRC error. So I was wondering if software direction control via IO pin has actually been tested and if it is reliable? |
Have you fitted a 120 ohm resistor on the line connection on the slave. I run RS485 over wifi and all my slaves need a 120 ohm resistor as they all think they are the last one on the cable. |
I have a regular RS485 bus with 120 Ohm termination. The bus itself works fine. When using HW direction control I don't get any errors. |
@ondrej1024 Hello!
I'm using this lib for >>> host.read_coils(slave_addr=10, starting_addr=125, coil_qty=16)
[True, True, True, True, True, False, False, False, False, True, True, True, False, False, False, True]
>>> host.write_multiple_coils(slave_addr=10, starting_address=125, output_values=[1,1,0])
True
>>> host.read_coils(slave_addr=10, starting_addr=125, coil_qty=3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/umodbus/common.py", line 136, in read_coils
File "/lib/umodbus/serial.py", line 289, in _send_receive
File "/lib/umodbus/serial.py", line 322, in _validate_resp_hdr
OSError: invalid response CRC Look that first I don't know if your problem is the same of that, or if your problem has something to do with this problem, but the @brainelectronics opened an issue for that #52 |
I use only reading/writing holding registers, no coils. Anyway I found that I have some issue with the ground reference of my circuitry. With a proper reference I always get a valid response from the slave, so SW direction control is working fine. However I still see an initial 0x00 byte in the RX buffer immediately after sending the request. So I have to take care of this, otherwise I get a CRC error. I don't have an explanation for this. |
Hey @ondrej1024 may you can give release 2.3.5 a try again? MicroPython v1.20.0 is recommended as it introduces the |
Yes, I will test this the next days and report back. |
I have tested release 2.3.5 now with MP 1.20.0 but I still see the same issue. I get CRC error. This is the code I use:
And this is the error message:
The above code works fine with release 2.3.4 and this patched version of serial.py: |
Hi again @ondrej1024 may you can give release 2.3.7 another try again? |
Just wanted to say this is likely a hardware issue and add a potential fix for anyone else that ends up here from searching. I use the same SP3485. The datasheet says that if ~RE and DE are both pulled high (as they are when using a common GPIO to enable transmission) then the RO output should be High-Z. On my shoddy breadboard setup, RO was actually getting pulled low. This looks like a start bit on the UART RX, resulting in the reception of a 0x00 character. Adding a pullup on RO is a hardware fix. If you need a software bodge fix, clear any bytes received before the peripheral should have had a chance to respond. while self._uart.any() > 0:
# print('ditching bad rx')
self._uart.read() For example, somewhere in the micropython-modbus/umodbus/serial.py Lines 278 to 287 in e9ab05a
|
I agree, also my problem seems to be a hardware issue. There is no pullup on the RO line here and, although I haven't tried to solder one, I am pretty sure it would fix it. So I guess we can close this issue now. |
Description
I am using a ST3485 RS485 transceiver with the DE/RE pins shortened and connected to a GPIO pin.
Running as Modbus master, the request is received correctly by the slave but the response is not received and
umodbus
throws an error (see below).I suspect some timing issue with the transceiver switching to read mode but can't quite find the root cause of this.
Any ideas?
Reproduction steps
Initialization:
mbm0 = ModbusRTUMaster(pins=(Pin(GP_UART0_TX), Pin(GP_UART0_RX)),ctrl_pin=GP_UART0_DC, uart_id=0)
Send request to slave
mbm0.read_holding_registers(42,1,1)
MicroPython version
MicroPython v1.19.1-994-ga4672149b
MicroPython board
Raspberry Pico
MicroPython Modbus version
Relevant log output
User code
No response
Additional informations
No response
The text was updated successfully, but these errors were encountered: