No serial write on hardware Serial1, UNLESS I assert DTR on SerialUSB.

Hi,

I’m doing a project on a custom 32u4 board (setup as Micro) with Caterina bootloader, using this ModbusSlave lib. I’m trying to communicate with a Modbus master. My program communicates with a Modbus master via h/w Serial1. Receiving data works fine, but writing data back to the master fails unless I assert DTR on USB Serial first.

This is the ModbusSlave.cpp transmit procedure (lines 374-380):

        // send buffer
        serial.write(bufOut, lengthOut);

        // wait for the transmission of outgoing data
        // to complete and then set rs485 control pin to read
        // [ on SoftwareSerial use delay ? ]
        serial.flush();

then nothing is output on serial, unless I assert DTR on Serial. I know the board is running without the Serial, I tried with a LED blink etc.

Note:

  • serial is initialized as Serial1 = h/w serial prot
  • Serial is SerialUSB = USB serial port

I don’t see why Serial1 is looking for DTR on Serial.

Hope someone has some suggestions…

Mach3_BOB.h (340 Bytes)

Mach3_BOB_error.ino (2.36 KB)

From your code

void setup() {
  Serial.begin( 57600 );
  while (!Serial); //This line instructs the code to sit here doing nothing until the USB serial connection is opened. 
  Serial1.begin( MODBUS_BAUDRATE );
  modbus.begin( MODBUS_BAUDRATE );

Hi DrAzzy,

Thanks for the reply. Sorry, that was a leftover from things I tried. Removing the while(!Serial) (or all references to Serial alltogether) doesn't solve the issue. Same behavior.

Update: I found this is unrelated to the mentioned library. I will ask moderator to delete this thread.

Out of curiousity, what was the problem?

Hi AWOL,

That I don't know yet. But turns out that Serial1.write does not work at all without DTR asserted on Serial. So regardless of the library and all..

I started a new thread in Networking with updated test code.

The new thread: