Replies: 3 comments 2 replies
-
not able to test this immediately but I recall this working: #undef Serial
#define Serial Serial3 |
Beta Was this translation helpful? Give feedback.
-
if that doesn't work I am positive I have used: #define serC Serial1
#define serG Serial2 and then search-replace all the Serial. stuff over to serC or whatever. |
Beta Was this translation helpful? Give feedback.
-
I will note that you may encounter problems if you have code in multiple compilation units if you do it that way - It was meant for advanced users: You would add a board definition for your specific hardware by copy-pasting an existing one and then removing options that were forced by that hardware from the tools submenu, and copy the variant file and edit it to specify things like that. But as long as your code is all in a single compilation unit, #undef Serial before the define will remove the warning. |
Beta Was this translation helpful? Give feedback.
-
I'm working with a couple of different homebrew AVR128DBxx boards. One is a 28 pin dip, another is a 32 pin flat and another is a 64 pin flat. For several different reasons the primary (console) UART varies from board to board. On one it's UART2 ALT, another it's UART3 and another it's UART5. But I want to have it look to the software that it's all the same UART, so when I jump from one board to another I don't need to change all the Serial.printf() statements to Serial3.print(f). So I've been do the following
#define Serial Serial3
This works fine, operationally. But I always get a compiler warning:
`p:\Users\p\Documents\Arduino\HDLC-REDO-220907-01\HDLC-REDO-220907-01.ino:1:0: warning: "Serial" redefined
#define Serial Serial3
In file included from sketch\HDLC-REDO-220907-01.ino.cpp:1:0:
C:\Users\p\AppData\Local\Arduino15\packages\DxCore\hardware\megaavr\1.4.10\cores\dxcore/Arduino.h:651:0: note: this is the location of the previous definition
#define Serial Serial0 // Error here? Check for missing ; previous line in sketch.
`
I'd like to find a workaround that doesn't cause the compiler warning (and I don't want to turn off compiler warnings).
Is there a better way to use a common Serial.print() or Serial.printf() to send data to a different UART, without getting a compiler warning?
Beta Was this translation helpful? Give feedback.
All reactions