read()

Description

Function to read data from the CAN FIFO buffer.

Syntax


CAN.read()

Parameters

None

Returns

When there are data in the FIFO buffer, return 1 byte of data.
When there is no data in the FIFO, return -1.

Example

#include <CANBus.h>
unsigned char ch;
void setup() {
    Serial.begin(115200);
    CAN.begin(CAN_500KBPS);
}

void loop() {
    if (CAN.requestFrom() > 0)         // Check to see whether data is received.
    {
        while (CAN.available() > 0)    // Check to see whether there are data in the FIFO
        {
            ch = CAN.read();           // Read data from FIFO
            Serial.print(ch);          // Output data value
            Serial.print("\t");
        }
        Serial.println();
    }
}

See also

requestFrom()
available()


Libraries Reference Home

The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.