NamNamIoT / RAK3172_CANOPUS

Examples for Canopus_RAK3172 board
https://canopus-iot.com/
MIT License
55 stars 8 forks source link

[Example Modbus Slave doesn't working] #7

Closed duyle1402 closed 5 months ago

duyle1402 commented 5 months ago

Hi a Nam, I tested your example code Rak3172 working as Modbus slave but it's doesn't work, I am using your example and Modbus Poll working as master for reading data from Rak_v1 I don't know exactly where is the problem. I tested some simple cases and wiring or hardware is not problem.

  1. I had tested simple transmit and receive in this UART1 of Rak3172 and its work fine.
  2. I had tested your example code with Esp32 (change the UART(Serial 1 -> Serial 2)) and it's working well,

But when I am using this code for Rak3172 and it can't run. Any suggest for me, Did I forget anything? Thanks.

NamNamIoT commented 5 months ago

Hi @duyle1402 ,

Because you tested the code with UART2 (UART2 <=> USB) and it works fine, the problem lies in the UART1 <=> RS485 conversion. Check some of the following conditions: -What Baud rate are you operating at? The circuit board uses 1nF capacitors combined with 56k resistors to take care of auto DE and RE so it is actually designed to work well at baud rates of 4800 - 115200, I think it will cover almost all speeds. popular that we often use. -Have you enabled power for the RS485 block? Help me determine accurately using a meter (VOM). If there is no power (3.3V) at the RS485 terminal, try connecting 3.3V power on the I2C terminal to the RS485 terminal (use wire). Because there exists a hardware error regarding power activation on version 1.

NamNamIoT commented 5 months ago

I have update code (add description) Plz pull again. thank you.

duyle1402 commented 5 months ago

Thanks a Nam for quickly reply, Here is my code I tested with Uart1 and it's work, i had ENABLE for RS485 block.

`#define BUFFER_SIZE 64 // Rak define

define LED PA8

define mA_PIN PB3

define VSS_PIN PB5

define VRS_PIN PB12

define PWR_ON LOW

define PWR_OFF HIGH

void setup() {

pinMode(LED, OUTPUT); pinMode(VRS_PIN, OUTPUT); digitalWrite(VRS_PIN, PWR_ON); //On power Vrs485 pinMode(VSS_PIN, OUTPUT); digitalWrite(VSS_PIN, PWR_ON); //On power Vsensor // Khởi tạo cổng serial với tốc độ baud là 9600 Serial.begin(115200); // uart 2 for minitor Serial1.begin(9600); // uart 1 } void loop() { // check data if (Serial1.available() > 0) { // create receive buffer char receivedData[BUFFER_SIZE]; int i = 0; // Biến chỉ mục cho buffer while (Serial1.available() > 0) { receivedData[i] = Serial1.read(); i++; delay(10); } // end of receive data by null receivedData[i] = '\0'; // print data Serial.print("Received: "); Serial.println(receivedData); }

// send data to computer if (Serial1.available() > 0) { Serial1.println("data from rak through uart 1"); delay(1000); } } ` Result: Test-rak-uart1

  1. Like you said, i used VOM to check voltage of Rs485 and it had power wiring
NamNamIoT commented 5 months ago

So, how about Read/Write with Modbus poll now bro? If it still not work, jelp me take some picture like this: image

duyle1402 commented 5 months ago

Wait me a minutes and I will update result soon,

duyle1402 commented 5 months ago

I sill cant read data, Here modbus's display images RAK-2

  1. Images wiring wiring-i2c-jump-rs485
  2. I had follow the orgial modbus slave lib at https://github.com/Trialcommand/Arduino-Modbus-RTU-Slave And I see that you change _frameDelay = 5; //24000/_baud; The others is same as this lib, I guest this is problem of Rak and RUI3 or We are missing some thing important
NamNamIoT commented 5 months ago

Cuz you recieved character correct in side RAK, and transmit from Modbus Poll success. It mean Rx of RAK work good. So I beliver it related to DE-RE or Tx of RAK.

Can you see both led on board (led tx and rx of modbus, color blue) flicker? A 15sec video of how the leds blink would be helpful to me.

NamNamIoT commented 5 months ago

Helpme change this to value 0 image

duyle1402 commented 5 months ago

Hi a Nam, To facilitate communication, I can connect with you via zalo or whatapp and we will post the results after solving the problem so everyone can follow along if they encounter the same problem?

NamNamIoT commented 5 months ago

My whatsapp: https://wa.me/84969809444

duyle1402 commented 5 months ago

Sloved: At these moments, the newer version we can download is 4.1.0, try Update RUI3 version to the 4.1.1 (not stable version), I think Rak Team will release this version soon. Can follow this link to download: https://forum.rakwireless.com/t/rui3-best-practice-collection-of-rui3-example-code/11256 After update RUI3 version, this example will work. Thanks, a Nam for helping.

sl446 commented 4 months ago

I am experiencing an issue with the Canopus version 1 board. The Modbus Master example code available on GitHub is not working, and my own code that uses the frames is also not working. I could not find the library you mentioned when I tried to download it.

NamNamIoT commented 4 months ago

Dear @sl446, Nice to know you. Since this topic is closed, could you help me open a new issue and add some descriptive information like the status of the modbus Tx and Rx leds working? The correct connection diagram is A to A, B to B and the register address you want to read, along with your code.

This will make it easier to track for those who encounter similar problems in the future. I have received your feedback via email and whatsaap, since you need to solve it quickly, I hope it can be done via anydesk to reduce your waiting time.