Modbus Protocol Not working on AVR128DA48 Curiosity Nano Board #437
Replies: 10 comments 2 replies
-
I don't really know anything about modbus, but where did the library come from? I do not accept names of libraries, because they are meaningless, any popular library has dozens or hundreds of forks, none of which document the changes or whether they're meant for public consumption. URL of the github repo or name of it in library manager if it's there. What's the actual topology of a modbus network look like and over which type of interface is it implemented? Serial? Something else? I'm trying to get a better idea of what I'm going to be looking at, and whether it seems more likely to be a core issue or a modbus library issue. |
Beta Was this translation helpful? Give feedback.
-
@rakeshdhanda Moved to the DxCore repo as you are using DxCore (presumably, since that's the one that supports AVR128DA48 |
Beta Was this translation helpful? Give feedback.
-
Are you using half-duplex modbus? I have used https://github.com/CMB27/ModbusRTUSlave with earlier releases of DxCore-1.5 with good success on a 32DB32. When initializing the serial port for use by ModbusRTUSlave in half duplex mode i use the following:
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Thanks for your suggestion, I tried this Modbus library also but the same thing is happening that it is working on Arduino Uno Board and not on AVR128DA48 Board. Given Below is the Board Settings in the Arduino Ver (1.8.19) that I am doing while working:-
This sketch demonstrates how to setup ModbusRTUSlave with 2 coils. The master/client will need to be cofigured using the following settings:
Circuit:
Created: 2022-11-19 */ #include <ModbusRTUSlave.h> const byte id = 1; const unsigned int numCoils = 2; const byte tonePin = 22;//8; Default value in the code byte buf[bufSize]; boolean toneActive = 0; // This is a function that will be passed to ModbusRTUSlave for reading coils. // This is a function that will be passed to ModbusRTUSlave for writing to coils. void setup() { void loop() { |
Beta Was this translation helpful? Give feedback.
-
Give me a day or two to get my rs485 boards running and sort out (hardware and DxCore) versions. Maybe something has slipped. |
Beta Was this translation helpful? Give feedback.
-
Modbus RTU over rs485 half-duplex seems to work fine for me using DxCore versions 1.5.4 and 1.5.6. I suspect the same for 1.5.5 tho i didnt try. I dont have any DA's to try. Server:
Client:
When you open the serial port with the RS485 flag set, the core will drive the xdir pin associated with that serial port to enable the output drivers of your rs-485 interface chip as appropriate. In this case the core is doing something special related to rs-485 for you. When the RS485 flag is not set, the core does nothing different (to the best of my knowledge) than any other serial operation. In this case, any modbus related stuff is solely in the hands of your library, your hardware, and your code. see here https://github.com/SpenceKonde/DxCore/blob/master/megaavr/extras/Ref_Serial.md#rs485-mode If it were me, i would go back to basics: is the baudrate between client and server correct? is tx/rx reversed? parity? one of your pins inverted? a broken wire? You know, the ah-shit stuff. Maybe even pull out the scope. If you think it might help, pare your code down to a bare minimum on your working system, verify it still fails on your new board, post it here, and i can try it. Good luck! |
Beta Was this translation helpful? Give feedback.
-
migrated to discussion as there is a lively debate over the cause, and others are reporting success. As more becomes known, issues may be created here or in other repos. |
Beta Was this translation helpful? Give feedback.
-
I dont think i was suggesting you should use half duplex, I only meant to ask if you were using half duplex hardware were you aware of the half duplex flags that dxcore offers. And you are correct: if you are using a plain old full-duplex serial port to communicate you should not be configuring the software for half-duplex. Additionally, half-duplex is more complex. I would agree you should try to get things running on a simple serial port, then move to half duplex if needed. But it looks like you are mixing hardware and software serial. The da has plenty of hardware serial ports, use those. Assuming you have a functional serial connection to Serial0 (PA0, PA1) of the Curiosity module, try something along these lines:
|
Beta Was this translation helpful? Give feedback.
-
Not doing anything with USART2 on it's alt pins by any chance? |
Beta Was this translation helpful? Give feedback.
-
This is my first post so please excuse me if I have done some mistakes or did not follow the rules of a post.
My below code is working well on Arduino UNO but it is not working on AVR128DA48 Curiosity Nano Board. I am using Modscan PC software to check the working of the code. Can someone please help me understand what is wrong with my code or why this board/Chip not supporting the working code of UNO ?
Working Code on Arduino UNO:-
//END of Code
I am using the below Library for Modbus Slave and it is working well on Arduino Uno
Modbus-Master-Slave-for-Arduino-master.zip
I am getting valid response in case of UNO as per above Image but no response in case of AVR128DA48.
I will be thankful for your help.
Beta Was this translation helpful? Give feedback.
All reactions