LoPy + SP3485 + Modbus Lib Test. Register Read Error
-
@daniel i checked your commit and the time.sleep_ms(5) should be outside the while not loop, or it wont work. And the machine.idle() stay there ;) (Just putting a image because Insert Code Block isnt working here)

Also, dont know if for any other baud rates that 5 ms will work. That's why ill try the Schneider module which have higher baud rates than this Eastron im using right now.
Best regards
Nelson Pinto -
@Neuromystix thanks! We are tesing with some intersil devices and before and after that commit it always works. And we never get the extra zeroes before or after...
Please let me know the results of your next tests.
-
@daniel it always worked fine with a module that had auto flow control. But with this modules which have some sort of enable pins, there's always some troubles.
Anyway, the 0x00 problem is easy to solve, so if anyone else have the same thing just need to delete it.Tomorrow ill give some more feedback.
Best regards
Nelson Pinto -
@daniel Hi.
Today i tested the three modules i have. Started with initial library without any changes. And using a Schneider IEM 3255 energy meter.
Module with auto flow control. Everything ok.

Chinese module with DE+RE enable pins. Also everything working, without any change in the original library.

Then, the Sparkfun module. As always, getting CRC errors. When comparing the waveforms from this module with those from c25b, its easy to see from where the zeros come from. In the image the upper waveforms are from c25b and they are clean in both ends. Also, the TX pin stay HIGH when idle. In Sparkfun module TX pin is at LOW state when idle, so when UART is reading it always catch that zeros.


Sparkfun SP3485 datasheet says that when EN pin is LOW, if the difference between A-B modbus line is positive (A-B > 0.2 V), then TX output should be 1. When the difference is negative (A-B < 0.2 V), TX output should be 0. In case when nothing is connected in A-B, TX goes HIGH. Same behavior with MAX485 chip from c25b module.
If i left A-B floating in Sparkfun, nothing happens in TX which should go HIGH. In c25b its everytime HIGH, except when EN LOW and some data appears in A-B.So the problem was not in the library but in Sparkfun module behavior. Anyone who need to use one of those, have to delete that extra 0x00 bytes in the received data.
Best regards
Nelson Pinto -
@Nelson thanks for testing all this. So, at the end, how does the timing for the control pin during transmit/receive should look like? Should we adapt the timing based on the baud rate (like 2ms fixed delay + the timing of 2 characters)?
Cheers,
Daniel -
@daniel I dont think it's necessary to adapt anything. Since only in Sparkfun module i need some adjustments. All the other modules worked fine, as yours. So leave the library as you published first, without any changes.
I tested baud rates 19200 and 38400, and everything worked fine with the original library.
With Sparkfun module ONLY, i changed _uart.wait_tx_done(2) to _uart.wait_tx_done(5) and added response = response[1:len(response)-1] inside _validate_resp_hdr, between raise OSError('no data received from slave') and resp_crc = response[-Const.CRC_LENGTH:]. Leaved it working for 2 hours, reading some registers each 5 seconds and dont get any error. So i think its something module related not about library ;)Best regards
Nelson Pinto -
@neuromystix @daniel I think the best thing is to leave this parameter outside the lib so that you can modify them according to the RS485 converts. Modify the lib and I carry 1300 readings without problems.
Greetings. -
Hello,
After testing with several devices, we have seen that the best strategy for the control pin is the one in this commit: https://github.com/pycom/pycom-modbus/commit/6eb00535ef63fa1e4d38f16667779124f1d0a75f
Cheers,
Daniel -
@daniel Tomorrow i'll try it again with Sparkfun module. I've been working with max485 module last days, done more them 50 thousand readings with only some random errors (less than 10).
Best regards
-
@daniel Tryed it today and it works without problems in my modules.
For some reason, the Sparkfun SP3485 fail safe feature don't appears to be working here. So i added pull up and down 1k resistors to RS485 line, as said in Analog Devices application note AN-960, and the module start to work correctly. So my problem is solved and your library works like a charm ;)
Best regards
Nelson Pinto -
@daniel Good afternoon, the modifications work perfect.
Best regards.
Mariano.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login