diablodude64
Member
Hello,
I have the following program running on an Arduino Mega 2560 that i'd like to move over to a Teensy. The problem I am having is that when I run it on the Teensy, it cuts the first digit off from the result and the response rate in the serial monitor changes to about once every second. As a side note, I know the teensy has the transmitterEnable() functionality and I was wondering if I could get help implementing that here instead of the preTransmission/postTransmission functions. Thanks in advance.
I have the following program running on an Arduino Mega 2560 that i'd like to move over to a Teensy. The problem I am having is that when I run it on the Teensy, it cuts the first digit off from the result and the response rate in the serial monitor changes to about once every second. As a side note, I know the teensy has the transmitterEnable() functionality and I was wondering if I could get help implementing that here instead of the preTransmission/postTransmission functions. Thanks in advance.
Code:
#include <ModbusMaster.h>
#define MAX485_DE 2 //Enable transmit pin for MAX485 (both RE/DE tied together)
// instantiate ModbusMaster object
ModbusMaster node;
void preTransmission()
{
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_DE, 0);
}
void setup()
{
pinMode(MAX485_DE, OUTPUT);
digitalWrite(MAX485_DE, 0);
// Baudrate for serial monitor if you want to see responses
while (!Serial);
Serial.begin(38400);
//Baudrate of modbus device is 38400
while (!Serial1);
Serial1.begin(38400);
// Modbus slave ID is 9 and MAX485 is connected to RX1/TX1
node.begin(9, Serial1);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
uint8_t result;
//Need data from starting address 0x41 with length 2
result = node.readHoldingRegisters(0x41, 2);
Serial.println(node.getResponseBuffer(0x00) / 10.00);
}