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:
    Serial.begin(115200);
  
  // Initialize CAN0 ,Set the proper baud rate here
  Can0.begin(CAN_BPS_250K);

  //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;
  //extended
  for (filter = 0; filter < 3; filter++) {
  Can0.setRXFilter(filter, 0, 0, true);
  Can1.setRXFilter(filter, 0, 0, true);
  }  
  //standard
  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(frame.id, HEX);
   Serial.print(" Len: ");
   Serial.print(frame.length);
   Serial.print(" Data: 0x");
   for (int count = 0; count < frame.length; count++) {
       Serial.print(frame.data.bytes[count], HEX);
       Serial.print(" ");
   }
   Serial.print("\r\n");
  }

  void modifyFrame(CAN_FRAME &frame) {
    frame.data.byte[0] = 0xFF;
    frame.data.byte[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) {
  Can0.read(input); 
  printFrame(input);
  //preoutput = input;
  //modifyFrame(input);
  //output=preoutput;
  //Can0.sendFrame(output);
  //printFrame(output);
  }

}

Auto format your code and you will see the error.

Mark