Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MODBUS
#1
We have a question about reading Modbus RTU:

With A2:
RS485:
RXD:35
TXD:32

With A2V3: 
RS485:
RXD:GPIO15
TXD:GPIO7

With A2  can read, but not with A2V3. Any idea?

// A2v3:
HardwareSerial MBus(1);
MBus.begin(9600, SERIAL_8N1, 15, 7);
pinMode(4, INPUT);  // modo auto

// A2:
HardwareSerial MBus(2);
MBus.begin(9600, SERIAL_8N1, 35, 32);

ModbusMaster node;
node.begin(1, MBus);
uint8_t r = node.readInputRegisters(6, 2);  // FC04 @ PDU 6

Someone could help us?
Reply
#2
you can try to exchange RXD and TXD pin.
Reply
#3
[Image: A2v3-diagram.jpg]

We use that PIN photo to identify A-B PIN.

// src/modbus_reader.cpp
void ModbusReader::applyUartPins(uint32_t baudRate) {
    int8_t rxPin = RS485_RX_PIN;   // 15
    int8_t txPin = RS485_TX_PIN;   // 7
    if (s_rs485SwapTxRx) {
        rxPin = RS485_TX_PIN;      // swap: begin(9600, 8N1, 7, 15)
        txPin = RS485_RX_PIN;
    }
    _serial.begin(baudRate, MODBUS_SERIAL_CFG, rxPin, txPin);
}

```cpp
ModbusResult ModbusReader::readInputRegisters(uint8_t slaveId,
                                              uint16_t startAddress,
                                              uint8_t count) {
    flushRxQuiet();
    _node.begin(slaveId, _serial);
    uint8_t status = _node.readInputRegisters(startAddress, count);
    silentBusGapAfterFrame();
    // On success: values = _node.getResponseBuffer(i);
}

I put here some examples I'm following, including change pin number according your suggestion but is not working. I don't know if there is som example for that board.
Reply
#4
here is KC868-A2v3 board RS485 arduino demo code, you can test with it.
https://www.kincony.com/forum/showthread.php?tid=7962
Reply
#5
Thanks for your link...I detect my mistake and now works fine.
Reply
#6
ok, good.
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)