-
-
Notifications
You must be signed in to change notification settings - Fork 44
Getting error: 0xef #14
Comments
Error 0xEF is indeed not defined. Could you share your code? |
I have connected to my modbus slave software via modbus(rs485) to Serial converver. |
The error comes from an error code returned by the modbus slave. See these lines: esp32ModbusRTU/src/ModbusMessage.cpp Line 247 in f85417c
Could you switch lines A and B? (I know, my readme is not clear on this but so is the specification) |
Hi, I am trying to read a RS485 distance meter and I am getting error: 0xe0 I have used pins 16 and 17 for serial2 comm and pin 4 as
For your reference please check device included device manual. mhmodbus-rtu (Ultrasonic level sensor RS485 ).pdf Assistance highly welcome. |
How does your circuit look like? What parts do you use? I tested with
Error 0E indicates a timeout. Your sensor isn't receiving the data or isn't responding. You could attach a logic analyzer to the RX/TX of the ESP (NOT the RS485 line!) and see what is going out/coming in. |
Dear bertmelis, thanks for taking the time to respond to my message. That was the basis for my circuit. I have done some tests. Also changed the code to send some commands on the line: modbus.readInputRegisters(0x01, 00, 2); I also have ordered an USB to RS485 converter to try to see what is actually coming from the Distance meter and it is to arrive soon. Just update the circuit so the MAX485 operates at 5v. No change. Please see project picture below. Thanks again |
Can you swap A and B? on the MAX485 board? If I found the right circuit on the Internet, this board biases the A line to Vcc and the B line to ground (can be checked with your multimeter) whereas it should be opposite. More info on the topic: https://en.wikipedia.org/wiki/RS-485#Signals |
Mind that your ESP uses UART and treats HIGH as binary 1 and LOW as binary 0. That's why the Serial needs to be "inverted". If somebody reads along, please correct me if I'm wrong. It's been a long time since I left school |
Hi, did invert A/B and there is a change in another code I have that uses ModbusMaster.h (//https://github.com/4-20ma/ModbusMaster) instead of (esp32ModbusRTU.h) Originally the former returned "illegal Function" but when I change A<->B then it starts returning "Response timed out"
Using esp32ModbusRTU.h with A and B as originally described: Swapping A<->B:
I did not figure out why the 4 on the line above as I am connecting with Serial2 pins 16 and 17.
As I said, I ordered a USB to RS485 adapter to check communication between the PC and the Distance Meter and it is to arrive soon. Thanks |
Make sure you have this #define MAX485_RE_NEG 4
#define Slave_ID 1
#define RX_PIN 16
#define TX_PIN 17
esp32ModbusRTU modbus(&Serial1, MAX485_RE_NEG);
// in void setup()
Serial1.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN, true); don't forget to connect DE and /RE. Can't see on your picture if that's the case. |
Hi, DE & RE as in the Fritzing diagram above. Code as of now:
Console output still: USB to RS485 will arrive tomorow and will provide additional info to aid finding the problem. |
What you can do is use I use Termite (in Windows) for that, with the Hexadecimal view plugin (https://www.compuphase.com/software_termite.htm). You might as well use Realterm. |
Do you mean the A and B from the USB to Serial adapter in parallel with the Arduino Serial2 (in my case)? |
I'm not completely following... When you pass Serial instead of Serial1 to the modbus object, the modbus messages will show up on your terminal. You'll want to display them in hex instead of ASCII, but that depends on your terminal software. You then just leave out Serial1 as it is not used. |
I am also a bit lost here. I understood your suggestion to be attaching the USB to RS485 converter that is arriving on the PC and the A&B wires to the A&B wired of the Distance meter (that are currently connected to the RS232 to RS486 (*) converter to see what the ESP32 is sending and receiving as the sketch executes. In any case I will first connect the USB to RS485 adapter to the PC and A&B to the Distance meter and send the commands directly to it and see if it is working as expected. Then I will try the connection above or even remove the distance meter all together and try the two RS485 between them to see what happens. Will keep you posted, thanks so far |
I have got the RS485 to USB converter but no good comunication so far. First I tested with a simple sketch to transfer console input:
What I type on the Serial Console goes through the ESP32 and reaches Termite. Now with the main sketch as below:
Did not find a reason for, in the first test with just a serial input and Termite input, why what I type on Termite is not echoed on the ESP32 serial console. Also cannot understand what the main sketch is sending to the Termite terminal. Can you make something out of it? |
You've connected the level converter wrong. high voltage is MAX485 side, low is ESP. The MAX485 should be powered with 5V, not 3.3V. You might as well fried your pins doing this. |
Still testing with the manual input of commands.
|
Strange. Maybe some task priority issues. I'll check things out. You can fiddle yourself if you alter the task priority directly in the code. |
Just to be sure: how much time passes between sending the request and receiving the error? Should be about 5 secs. |
I am not that advanced, don't know how to change task priority. |
Just tested again. |
Just tested with another sketch I have for modbus.
Console and Termite as below: In this case, when the distance meter is connected to A&B instead of the USB to RS485 addapter the error is: "Illegal Function" Thanks |
I might spotted a but in the Arduino core. I'll try this evening. |
Can you try after changing the false to true on this line: |
My esp32-hal-uart.c looks different:
|
Arduino? Platformio? Something else? Which version? |
Arduino IDE ESP32 1.0.4 |
Thank you for testing. I can't find what's wrong though. The following weeks I'll be on holiday so I have very limited access. But I'll try to support. |
Hi, thanks for your time. If you get something new it will be of help. |
Hello,
Im new to esp32 i want to implement a modbus RTU master using esp32.
I took serial2 as modbus and made as per that. the esp32 initialized as master and it sending request to slave slave also responding but I am getting
sending Modbus request...
error: 0xef
I used Serial port monitor to debug and got
I cant find this ef anywhere in the library files and from where it is printing. what is this error?
The text was updated successfully, but these errors were encountered: