Playing with Arduino
A page to record my playing with Arduino
HardwareSerial::HardwareSerial()

Abstract

The HardwareSerial() is a constractor to create an object to perfome serial communication. In Arduino Uno, an object named ‘Serial’ is generated.

The HardwareSerial class is derived from Stream class. The Stream class is for string based stream. It defines virtual functions like available(), read(), peak() and flush(), they need to be implemented in the derived classes, and find(), findUntil(), parseInt() and so on.

The Stream class is derived from Print class. Print class implements displaying character or strings. The write() function to display a character shuould be implemented in the derived classes, in this case, HardwareSerial class. Then we can use print() and/or println().

The constractor of HardwareSerial initializes member variables.

Source Code

HardwareSerial() is defined in hardware/arduino/avr/cores/arduino/HardwareSerial_private.h as below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
HardwareSerial::HardwareSerial(
  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
  volatile uint8_t *ucsrc, volatile uint8_t *udr) :
    _ubrrh(ubrrh), _ubrrl(ubrrl),
    _ucsra(ucsra), _ucsrb(ucsrb), _ucsrc(ucsrc),
    _udr(udr),
    _rx_buffer_head(0), _rx_buffer_tail(0),
    _tx_buffer_head(0), _tx_buffer_tail(0)
{
}

It initializes member variables using argments.

Version

Arduino 1.8.13

Last Update

June 19, 2020

inserted by FC2 system