Serial CAN Module Works Over Software Serial but Not Hardware Serial on Mega 2560

Hi everyone,

I’m using a Serial CAN module (GitHub Library) with an Arduino Mega 2560 and running into an issue where the module works fine over SoftwareSerial, but not on any of the hardware serial ports.

The module communicates correctly over SoftwareSerial pins 11 and 10, but when switching to hardware serial (e.g., Serial1, Serial2, Serial3), it doesn’t work.

Checked with an oscilloscope, the module’s TX pin outputs 3.3V logic, and the module is powered via 5V.

Tried a logic level shifter (3.3V → 5V), bit no improvement, Still doesn’t work on hardware serial.

Tried multiple hardware serial ports (Serial1, Serial2, Serial3), None worked.

SoftwareSerial works flawlessly, but I’d prefer to use hardware serial for reliability and performance.

Any ideas why SoftwareSerial works, but hardware serial doesn’t?

#include <Serial_CAN_Module.h>

Serial_CAN can;

void setup() {
  Serial.begin(9600);
  while(!Serial);

  // WORKS WITH SOFTARE SERIAL
  can.begin(11, 10, 9600);

  // DOESN'T WORK WITH HARDWARE
  // can.begin(Serial1, 9600);
 
  if(can.canRate(CAN_RATE_500)) {
    Serial.println("set can rate ok");
  } else {
    Serial.println("set can rate fail");
  }
}

void loop() {}

Thanks in advance!

Please read a note in the "Hardware Connection" section of the page that you linked yourself:

Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

Yes, but this is for using SoftwareSerial, how does this affect HardwareSerial? Can you please elaborate, since I'm new with Arduino... :sweat_smile:

Silly question. Do you have the module Tx connected to Serial1 Rx (pin 19) and module Rx connected to Serial1 Tx (pin 18)? or were they swapped?

Yeah, I connected module Tx to Serial1 Rx, and module Rx to Serial1 Tx. Tried swapping them also, but no luck... :sweat_smile:

Could you show a code, where you try to use Hardware Serial with the library?