I have been using an Arduino MEGA to communicate with an inverter using the hardware Serial with no problem.
I'm trying the same code on an UNO R4, however, I can't use the hardware Serial as I need to read the Serial output , so I'm trying Software serial. However, I get a NAKKS response from the inverter so I wondered if there is a difference between what the Software Serial and Hardware Serial would output?
According to the schematic of the Uno R4 WiFi, pins 0 and 1 are not the pins that are used for communication with the PC; this is a difference with the normal Uno.
So you should be able to use pins 0 and 1 for communication with your inverter. Now the big question is how to refer to them. You can try
Serial1.begin()
_UART1_.begin() (or one of the other _UARTx_ objects.
Assuming that the Serial1 was for the Mega, why did you change the baudrate for mySerial?
From programmer's point of view, UNOR4WiFi is direct drop-out of UNOR3; so, UNOR4WiFi has one Hardware UART Port marked as RX(0)/TX(1) and any two permissible DPins could be configured to work as Software UART Port (post #6).
Wuld appreciate to see a testable sketch using UART1 Port for UNOR4WiFi.
I don't have the board; just replace SUART in your code for the R4 by Serial1 and test and use pins 0 and 1.
And your point is?
One only makes one's life miserable when using SoftwareSerial if there are other options.
By the way, have you ever tried to use pin change interrupts on an Uno while using SoftwareSerial as well ; SoftwareSerial claims all PCINT vectors; you will have to hack the SoftwareSerial library to circumvent that. If not mistaken, the same applies to the Mega.
I want to leave 0, 1 for Serial0 Port for communication with PC/IDE/SM. Like MEGA and ESP32, I would like to use some other DPins for UART1 Port -- something like (in line with ESP32):
Pins 0 and 1 are not used for communication with the PC on the Uno R4. The same applies to 32U4 based boards and a lot of new Arduinos. If the processor uses native USB, the serial pins are free.
The Baudrate for the inverter is super slow (2400). When I tried to use the Hardware serial I was getting an error message from the UNO, something about not being able to complete a process in time. I'll have to set it up again to and paste it here. That's why I switched to try the Software Serial to see if I could get it to work that way.
@ptillisch and @sterretje are right in saying that 0, 1 are not used for Serial Monitor/PC. The US (D+/D-) signals are demodulated/converted by the MCU itself similar to ESP32-C3. Unfortunately, the following line is not compiled:
Serial1.begin(9600, SERIAL_8N1, 0, 1);
@ptillisch
The referred link of your post #8 does not contain UNOR4WiFi Board.
The pin number arguments on the begin function are a non-standard API created unilaterally by the ESP32 platform developers. When using the UNO R4 WiFi board, Serial1 is associated with pins 0 and 1 specifically.
There is something similar in the UNO R4 WiFi's core (except pins are configured via the constructor rather than a function):
But I don't see a reason to use that feature in this case since it is already done for you with Serial1:
There was no reason that I did not read that post; unfortunately, I could not apprehend the meanings. Apologize for my cognitive limitations.
People say that UNOR4WIFi is the drop-out of UNOR3. So, RX-->0/TX-->1 should be UART0/Serial0 which is not true and this can be known only by consulting the schematic of UNOR4WiFi.
Thank you for the heads up about the USB Serial Vs UART Serial1. That makes a lot of sense!
However, I'm still getting a NAKss response using the UNO R4. I'm going o try again with a MEGA and see if I can spot the difference.