Errors using CAN lib

Hello everybody,

I’ve written a short sketch using the CAN library for the arduino due and get These two error Messages:

  1. CAN_read:28: error: a function-definition is not allowed here before ‘{’ token

This error refers to the following line of code:

void printFrame(CAN_FRAME &frame) {
  1. CAN_read:63: error: expected ‘}’ at end of Input

line 63 is the end of the sketch.

I already counted the brackets, so that shouldn’t be the Problem. Can anyone help me?

Here is the full code:

#include "variant.h"
#include <due_can.h>

#define Serial SerialUSB

void setup() {
  // put your setup code here, to run once:
  // Initialize CAN0 ,Set the proper baud rate here

  //By default there are 7 mailboxes for each device that are RX boxes
  //This sets each mailbox to have an open filter that will accept extended
  //or standard frames
  int filter;
  for (filter = 0; filter < 3; filter++) {
  Can0.setRXFilter(filter, 0, 0, true);
  Can1.setRXFilter(filter, 0, 0, true);
  for (int filter = 3; filter < 7; filter++) {
  Can0.setRXFilter(filter, 0, 0, false);
  Can1.setRXFilter(filter, 0, 0, false);

  void printFrame(CAN_FRAME &frame) {
   Serial.print("ID: 0x");
   Serial.print(, HEX);
   Serial.print(" Len: ");
   Serial.print(" Data: 0x");
   for (int count = 0; count < frame.length; count++) {
       Serial.print([count], HEX);
       Serial.print(" ");

  void modifyFrame(CAN_FRAME &frame) {[0] = 0xFF;[2] = 0xFF;


void loop() {
  // put your main code here, to run repeatedly:
  CAN_FRAME input;
  CAN_FRAME output;
  CAN_FRAME preoutput;
  if (Can0.available() > 0) {; 
  //preoutput = input;


Auto format your code and you will see the error.