On my Arduino Mega works for me this:
// Enable debug prints to serial monitor
//#define MY_DEBUG
//#define MY_DEBUG_HWSERIAL Serial // = Serial0 / Rx0 & Tx0 to programming & debug
// Enable serial gateway
#define MY_GATEWAY_SERIAL
#define MY_SERIALDEVICE Serial3 // Rx3 & Tx3 to Gateway
// Enable RS485 transport layer
#define MY_RS485
#define MY_RS485_HWSERIAL Serial1 // Rx1 & Tx1 to RS485 network
#define MY_RS485_BAUD_RATE 9600
#define MY_RS485_DE_PIN 22
I tried to edit a library MyHwAVR.cpp for MY_DEBUG_HWSERIAL, but without any positive result.:
#ifdef MY_DEBUG
#ifndef MY_DEBUG_HWSERIAL
#define MY_DEBUG_HWSERIAL MY_SERIALDEVICE
#endif
void hwDebugPrint(const char *fmt, ... )
{
char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
#ifdef MY_GATEWAY_FEATURE
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
MY_DEBUG_HWSERIAL.print(fmtBuffer);
#else
// prepend timestamp (AVR nodes)
MY_DEBUG_HWSERIAL.print(hwMillis());
MY_DEBUG_HWSERIAL.print(" ");
#endif
va_list args;
va_start (args, fmt );
#ifdef MY_GATEWAY_FEATURE
// Truncate message if this is gateway node
vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args);
fmtBuffer[sizeof(fmtBuffer) - 2] = '\n';
fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
#else
vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args);
#endif
va_end (args);
MY_DEBUG_HWSERIAL.print(fmtBuffer);
MY_DEBUG_HWSERIAL.flush();
//MY_DEBUG_HWSERIAL.write(freeRam());
}
#endif
The code above does not work!