Claritydnb
Member
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?
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
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: