From a3325c874adcea1cc166bce410a4c9310307265f Mon Sep 17 00:00:00 2001 From: wangcoolc <1387172050@163.com> Date: Mon, 7 Dec 2020 17:45:11 +0800 Subject: [PATCH] complete canbus receive interrupt function --- .../receive_interrupt/receive_interrupt.ino | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/examples/receive_interrupt/receive_interrupt.ino b/examples/receive_interrupt/receive_interrupt.ino index 549118f..69cba15 100644 --- a/examples/receive_interrupt/receive_interrupt.ino +++ b/examples/receive_interrupt/receive_interrupt.ino @@ -3,7 +3,7 @@ // loovee, 2014-6-13 #include -#include "mcp_can.h" +#include "mcp2518fd_can.h" /*SAMD core*/ #ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE @@ -14,12 +14,10 @@ // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 -const int SPI_CS_PIN = 9; -const int CAN_INT_PIN = 2; - -MCP_CAN CAN(SPI_CS_PIN); // Set CS pin - +const int SPI_CS_PIN = BCM8; +const int CAN_INT_PIN = BCM25; +mcp2518fd* controller; unsigned char flagRecv = 0; unsigned char len = 0; unsigned char buf[8]; @@ -27,10 +25,10 @@ char str[20]; void setup() { SERIAL.begin(115200); - while (!SERIAL) { - ; // wait for serial port to connect. Needed for native USB port only - } - while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k + while(!Serial){}; + controller = new mcp2518fd(); + controller->mcp_canbus(SPI_CS_PIN); + while (CAN_OK != controller->begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k SERIAL.println("CAN BUS Shield init fail"); SERIAL.println(" Init CAN BUS Shield again"); delay(100); @@ -42,6 +40,7 @@ void setup() { void MCP2515_ISR() { flagRecv = 1; + SERIAL.println("into MCP2515_ISR\n\r"); } void loop() { @@ -54,9 +53,9 @@ void loop() { // If either the bus is saturated or the MCU is busy, // both RX buffers may be in use and reading a single // message does not clear the IRQ conditon. - while (CAN_MSGAVAIL == CAN.checkReceive()) { + while (1 == controller->checkReceive()) { // read data, len: data length, buf: data buf - CAN.readMsgBuf(&len, buf); + controller->readMsgBuf(&len, buf); // print the data for (int i = 0; i < len; i++) {