serialEvent2 was not declared in this scope


Hey everyone,

I am trying to use Serial2 in my application. this is based on bluzDK-fimrware release-1.1.47 However on build I am getting an error.

This is my main application where I am including Serial2:

/* Includes ------------------------------------------------------------------*/
#include "application.h"
#include "Serial2/Serial2.h"

/* Function prototypes -------------------------------------------------------*/


int input = D2;
int LED = D7;

/* This function is called once at start up ----------------------------------*/
void setup()
	pinMode(input, INPUT_PULLUP);
	pinMode(LED, OUTPUT);

/* This function loops forever --------------------------------------------*/
void loop()
//    System.sleep(SLEEP_MODE_CPU);
	//This will run in a loop
    digitalWrite(LED, HIGH);
    digitalWrite(LED, LOW);

On build I get the error ‘serialEvent2’ was not declared in this scope. This is on the Serial2.h header file on line 14:

#ifndef __LIB_SERIAL2_H
#define __LIB_SERIAL2_H

#include "spark_wiring_usartserial.h"

// instantiate Serial2
static Ring_Buffer serial2_rx_buffer;
static Ring_Buffer serial2_tx_buffer;

USARTSerial Serial2(HAL_USART_SERIAL2, &serial2_rx_buffer, &serial2_tx_buffer);

void serialEventRun2()
    __handleSerialEvent(Serial2, serialEvent2);  //ERROR ON THIS LINE!!!!!


I see that this file is including spark_wiring_usartserial.h which declares the serialEvent2 function so I do not see why this error is occurring. Ideas?


Bluz only supports Serial1, and you don’t need to include any header files to make it work. The nrf51 only has 1 UART.

Do you need two separate UART’s?


Hi @eric ,

I was going to use the Second serial port(Pins D0 and D1) during development of firmware. I am communicating to a device over serial but still want a second serial port I can monitor for debugging. This doc page shows there is a second serial port that can be referenced through Serial2:
Is that info no longer valid?


Yes, that info is not valid. The nrf51 only has 1 physical UART, so we don’t support Serial2. I will remove those references.


Thanks Eric. I totally understand the struggle with keeping documentation up to date!


Updated the docs:


I think the doc page is still incorrect. It mentions 2 serial ports and does not say Serial1 throughout.

I am wondering if I could use something like SoftwareSerial in an application that has a serial input device (a sensor) and still needs to be debugged in the usual way with Serial1? (Even if theoretically so, there might well be a memory space issue anyway.)

If not I suppose I would need to use an serial-to-SPI converter chip to get this serial sensor data into bluz?


Thanks for the pointers in the docs, I will get that cleaned up.

Unfortunately we don’t have a soft serial library, and the nrf51 only has one UART. I had come across a clever solution before that someone used, and that is to fake it by using the one UART but reassigning it to different pins. So we could have the Serial1 work as it does now, and have a Serial2 that just uses different pins. When you called one or the other, behind the scenes it would just reconfigure the UART with the new pins if necessary. This would work, but may be slow as we would have to reconfigure the UART each time you swapped.

Still, if you think this would work, let me know and I can open an issue to track it.