Contenuto principale

Serial Receive

Receive data over Arduino SAM D21 core serial port

Since R2026a

  • Arduino SAMD Serial Receive

Libraries:
Simulink Support Package for Arduino Hardware / Advanced / SAMD

Description

Use the Serial Receive block to receive a variable-length array of data on the Arduino® SAMD21 core serial port and configure a serial communication interface on hardware using a SERCOM channel.

To use the SERCOM interrupts for serial reception, configure the Hardware Interrupt block for SAMD boards. This block allows you to enable and manage SERCOM receiver interrupts, such as receive complete and receive error interrupts.

During simulations without hardware, the Serial Receive block receives zeros. If you use this block in a model that has the Standard Servo Read, Standard Servo Write, or Continuous Servo Write block, specify longer sample times to avoid overruns.

Note

The Serial Receive block supports C/C++ code generation using Embedded Coder®.

Warning

Do not connect the serial port pins to an RS-232 serial interface, such as the DE-9M connector on a computer, without limiting the input voltage. The RS-232 standard allows higher voltages that can damage your hardware. For more information, read the documentation for your Arduino hardware.

Supported Arduino Boards

  • Arduino MKR 1000

  • Arduino MKR Wi-Fi® 1010

  • Arduino MKR Zero

  • Arduino Nano 33 IoT

Examples

Ports

Output

expand all

Data received from the Arduino serial port. When no data is available on the Arduino serial port, the block outputs zeros.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean

Status of the read operation.

  • 0 — Length of received data is less than or equal to the data length specified in the Data length parameter.

  • 1 — Length of received data is greater than the data length specified in the Data length parameter.

Dependencies

To enable this port, set Data length option to Length via dialog or Length via input port.

Data Types: uint8

Length of received data in bytes. If this port outputs zero, the block did not receive any serial data during the timeout period.

Dependencies

To enable this port, set Data length option to Length via input port.

Data Types: uint8

Parameters

expand all

Enter the serial communication channel number for serial transmission. The following table lists the SERCOM channel and their associated pins on each board. Choose a SERCOM channel on your board and connect your serial device to the corresponding receive pin.

Arduino BoardsSERCOM ChannelPin
Arduino MKR 1000, Arduino MKR Wi-Fi 1010, Arduino MKR ZeroSERCOM 2Pin 3
SERCOM 3Pin 7
Arduino Nano 33 IoTSERCOM 0Pin 5
SERCOM 4Pin 3

To open the Arduino pin mapping table, click View pin map. For more information on the fixed ports and the allocated pins for the block, see Pin Mapping for Arduino Timer-Independent Blocks.

Select the data format of receiving data.

The maximum number of Data type the block can receive (not bytes).

If Data length option is set to Variable length, then the received data cuts off at Maximum data length. If Data length option is set to Length via input port, then the received data length is the value at the input port or the value of Maximum data length, whichever is smaller.

Dependencies

To enable this parameter, set Data length option to Length via input port or Variable length.

Select this option to generate an interrupt when the data reception is complete on the Arduino serial port.

When you enable this parameter in the Hardware Interrupt for SAMD block, specify the appropriate Interrupt group, Interrupt name, and Events to serve parameter values.

Select this option to generate an interrupt if any of the following USART receiver errors occurs:

  • Frame error — Missing stop bit in the receiving data

  • Buffer overflow — Receiver buffer is full and additional incoming data was lost

  • Parity error — Parity of the receiving characters does not match the expected value

When you enable this parameter in the Hardware Interrupt for SAMD block, specify the appropriate Interrupt group, Interrupt name, and Events to serve parameter values.

Select an option to specify the data length.

  • Length via dialog — Specify the data length with the Data length parameter.

  • Length via input port — The block receives the data length from Length port.

  • Variable length — The block receives data until the value you specify in the Terminator parameter matches the data on the Arduino serial port. The block waits until the timeout value when the data is not available on the Arduino serial port. When you use variable data length, the block outputs the length of received data at the Length output port.

Specify the number of Data type the block receives (not bytes). If this parameter is set to more than 1, the output is a vector. Make sure that the data length you specify is the same as that in the Serial Transmit block.

Specify the number of data bytes the block must receive on the Arduino serial port for the data type you set in the Data type parameter.

Dependencies

To enable this parameter, set Data length option to Length via dialog.

Specify a header that indicates the beginning of your data block.

Provide the header using the uint8 representation of the corresponding ASCII characters. This table shows some examples of ASCII characters, the corresponding array to use for Header, and a MATLAB® command to generate that array.

Example ASCII CharacterMATLAB CommandParameter Value
"#"uint8('#')[35]
"81"uint8('81')[56 49]
"Start"uint8('Start')[83 116 97 114 116]

You can also specify this parameter using the hexadecimal representation of the ASCII characters.

Specify a terminator that indicates the end of your data block.

Provide the terminator using the uint8 representation of the corresponding ASCII characters. This table shows some examples of ASCII characters, the corresponding array to use for Terminator, and a MATLAB command to generate that array.

Example ASCII CharacterMATLAB CommandParameter Value
"#"uint8('#')[35]
"81"uint8('81')[56 49]
"End"uint8('End')[69 110 100]

You can also specify this parameter using the hexadecimal representation of the ASCII characters.

Specify how often the block reads data available on the Arduino serial port.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2026a