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.
#include "Canopus_Modbus.h"
ModbusMaster node;
#include <Rak3172_Canopus.h>
#define V_RS485 PB12
#define V1
uint8_t result;
void setup()
{
pinMode(V_RS485, PWR_ON);
pinMode(PB2, OUTPUT);
Serial.begin(115200);
Serial.print("\r\n*****************RAK3172_CANOPUS*******************");
Serial_Canopus.begin(9600, SERIAL_8N1);
}
void loop()
{
//***************READ node 1**************************
node.begin(1, Serial_Canopus); //slave ID node
Serial.printf("");
Serial.printf("\r\n\n\nExample read modbus RTU for RAK3172_Canopus board");
result = node.readHoldingRegisters(0, 1);//Read 40000 to 40009
delay(10);
if (result == node.ku8MBSuccess) //Read success
{
for (uint8_t i = 0; i < 10; i ++ )
{
Serial.printf("\r\nValue 4000%d: %d", i, node.getResponseBuffer(i));
}
}
else Serial.print("Read Fail node 1"); //read fail
digitalWrite(PB2, !digitalRead(PB2)); //blink led
delay(500);
}
And this is my code, using frames (when i run this code i see tx led blinking but with a dim light):
#include <Rak3172_Canopus.h> // Include the Rak3172_Canopus library header file.
#include "Canopus_Modbus.h"
#include "Rak3172_Canopus.h"
#define V1
#define RS485_VCC PB12
byte Temp[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0a};
byte responseBuffer[50]; // Taille du tampon de réponse
float Value, Val1;
void setup() {
Serial.begin(115200);
Serial_Canopus.begin(9600, SERIAL_8N1);
pinMode(RS485_VCC, OUTPUT);
digitalWrite(RS485_VCC, PWR_ON); //On power Vrs485
//pinMode(V_SS5, PWR_ON);
}
float temp(){
// node.begin(1, Serial_Canopus); //slave ID node
RS485_Tranmit;
Serial_Canopus.write(Temp, sizeof(Temp));// Envoyer la requête au capteur
// Lire la réponse
RS485_Receive;
delay(200);
int responseLength = Serial_Canopus.available();
if (responseLength > 0) {
for (int i = 0; i < responseLength; i++) {
responseBuffer[i] = Serial_Canopus.read();
}
Value = (responseBuffer[3] << 8) | responseBuffer[4];
Value = Value/100;
Serial.print("temperature : ");
Serial.print(Value);
Serial.println(" °C");
} else {
Serial.println("Aucune réponse reçue.");
}
return Value;
}
void loop() {
Serial.println("________________________");
temp();
delay(1000);
}
notice 1 : i use a Seeed studio EC sensor (RS485, 12V) i use a externel alimentation with this sensor and the seem gnd for all the system.
notice 2 : i have also an conveter usb to RS485 for test.