RS 485 Impossible to communicate with other device
Good morning,
I try to use RS 485 to communicate between my IND.I/O (Master) and on other device (Slave) to have power and tempretures, but it doesn't worked. I precise, my code work well with an arduino Uno.
I leave one switch on 120 ohm with the jumper (I remove the two others 560 ohm) , the pin TxEnablePin is 9, Name of the port is Serial...
I d'on't understant what's happen. If anybody can help me that will be nice.
Thank a lot for your help.
Olivier
*************************************************************
#include <SimpleModbusMaster.h>
//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 200 // the scan rate
#define retry_count 10
// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 9
#define LED 9
// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 8
// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
PACKET1,
PACKET2,
PACKET3,
TOTAL_NO_OF_PACKETS // leave this last entry
};
// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];
// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];
unsigned long previousMillis;
// Fct de paramétrage
// ******************
void setup()
{
// SerialUSB.begin(115200);
// SerialUSB.println("setup()");
// init : BUS RS 485
// ********************
// Initialize each packet
modbus_construct(&packets[PACKET1], 2, READ_INPUT_REGISTERS, 61, 1, 0); //PAC : [reg. 61] recupération de la puissance instantannée en W
modbus_construct(&packets[PACKET2], 2, READ_INPUT_REGISTERS, 5, 1, 1); //PAC : [reg. 5] recupération AC unit Temperature reference (de 10° à 42°) ou température de la PAC servant de reférence à la modulation de la puissance electrique
modbus_construct(&packets[PACKET3], 2, READ_HOLDING_REGISTERS, 4, 1, 2); //PAC : [reg. 4] [LECTURE] AC unit Temperature setpoint (de 16° à 30°) ou température a atteindre par la PAC.
// Initialize the Modbus Finite State Machine
modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs); // Init du protocole BUS RS 485
}
void loop()
{
modbus_update();
if (millis() - previousMillis > 500) {
SerialUSB.println(String(regs[0]/1.0,1) + "W");
SerialUSB.println(String(regs[1]/1.0, 0) + "°C");
SerialUSB.println(String(regs[2]/1.0, 0) + "°C");
previousMillis = millis();
}
}
Hi Tom,
Thanks for your reply. I meant I get zeros, even if SerialUSB.begin() is commented out.
I found the switch and the RS 485 works now.
Thank again for your help.
Hi, that looks all good, except you have commented out the SerialUSB.begin() so you won't see any feedback in the Serial Monitor. Or do you mean you only get zeros?
There is a hardware switch on the baseboard that needs to in the lower position to enable RS485 (towards the A/B terminals) but that should be in that position by default. You only need it if you want to disconnect D0/D1 from the RS485 port to use it for something else.
Your answer
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
Keep Informed
About This Forum
This community is for professionals and enthusiasts of our products and services.
Read GuidelinesQuestion tools
Stats
Asked: 5/4/21, 2:11 PM |
Seen: 1425 times |
Last updated: 5/6/21, 3:22 PM |