Xenon - Serial2 - Compile Error

I am trying to test Serial2 on the Xenon. The docs show the following code (https://docs.particle.io/reference/device-os/firmware/xenon/):

// EXAMPLE USAGE
// IMPORTANT: Include the header file for Serial2
#include "Serial2/Serial2.h"

void setup()
{
  Serial1.begin(9600);
  Serial2.begin(9600);

  Serial1.println("Hello World!");
  Serial2.println("Hello World!");
}

However, this is giving a compile error “‘Serial2’ was not declared in this scope”.

@Jimmie, I can confirm. I’ll pass the info on to the Particle folks.

Thank you @peekay123.

1 Like

Thanks for reporting this! We are currently incorrectly not defining Wiring_Serial2 on all Gen 3 devices, whereas it should have been defined on Xenons. We’re going to fix this in the upcoming release, however for now you may add the following workaround to the top of your source file:

// Workaround for Serial2 on Xenon
#if PLATFORM_ID == PLATFORM_XENON && SYSTEM_VERSION <= SYSTEM_VERSION_v080RC27
#define Wiring_Serial2 1
#define Serial2 __fetch_global_Serial2()
extern USARTSerial& __fetch_global_Serial2();
void serialEvent2(void) __attribute__((weak));
#endif // PLATFORM_ID == PLATFORM_XENON && SYSTEM_VERSION <= SYSTEM_VERSION_v080RC27

#include "Serial2/Serial2.h"
5 Likes