Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: ArduinoModbus porting question

Threaded View

  1. #1
    Junior Member
    Join Date
    Nov 2019
    Posts
    6

    ArduinoModbus porting question

    Hello all. I am looking to use a teensy 4.1 as a Modbus RTU Client over RS485. It seems that it is attempting to use the Serial port associated with the USB. I need it to operate on Serial1. Is there a way to do this?
    Code:
    #include <Arduino.h>
    #include <Metro.h>
    #include <SPI.h>
    #include "mcp23s17.h"
    #include <Wire.h>
    #include "MCP342x.h"
    #include <FlexCAN_T4.h>
    #include <ArduinoRS485.h>
    #include <ArduinoModbus.h>
    
    bool clientStarted = 0;
    
    void setup()
    {
    clientStarted = ModbusRTUClient.begin(57600);
      while (!clientStarted){
        Serial.println("Client Error");
      }
    }
    
    void loop {
    
          ModbusRTUClient.beginTransmission(15, HOLDING_REGISTERS, 0x100, 6);
          ModbusRTUClient.write(ALowOutput);
          ModbusRTUClient.write(AHighOutput);
          ModbusRTUClient.write(BLowOutput);
          ModbusRTUClient.write(BHighOutput);
          ModbusRTUClient.write(CLowOutput);
          ModbusRTUClient.write(CHighOutput);
          
          if (!ModbusRTUClient.endTransmission()){
            Serial.println ("failed! ");
            Serial.println (ModbusRTUClient.lastError());
          }
          else{
            Serial.println("Success");
          }
    }
    The teensy just locks up at the begin(57600) function. After that it won't respond to teensyduino or run the program. It seems like it is trying to start on the same serial port. Thanks in advance for your help
    Last edited by Claritydnb; 06-09-2021 at 03:02 PM. Reason: modifying code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •