From e2a6702c4cd9165437e8126e7edd79f3a78eda1d Mon Sep 17 00:00:00 2001 From: wangcoolc <1387172050@163.com> Date: Tue, 24 Nov 2020 16:13:24 +0800 Subject: [PATCH] Modified mcp2518fd spi_CS spi_INT on wio terminal --- examples/receive/receive.ino | 26 ++++++++++++++++++-------- examples/send/send.ino | 13 +++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/examples/receive/receive.ino b/examples/receive/receive.ino index 5bb1937..e99faa4 100644 --- a/examples/receive/receive.ino +++ b/examples/receive/receive.ino @@ -1,5 +1,4 @@ // demo: CAN-BUS Shield, send data -// loovee@seeed.cc #include "mcp2518fd_can.h" @@ -10,29 +9,40 @@ #define SERIAL Serial #endif -//Mcp_Factory my_Factory; - // 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 = 23; +const int SPI_CS_PIN = BCM8; +const int CAN_INT_PIN = BCM25; + mcp2518fd* controller; +unsigned char flagRecv = 0; + void setup() { SERIAL.begin(115200); + while(!Serial){}; controller = new mcp2518fd(); - controller->mcp_canbus(SPI_CS_PIN); - while (0 != controller->begin()) { // init can bus : baudrate = 500k + controller->mcp_canbus(SPI_CS_PIN); + while (0 != controller->begin()) { // init can bus : baudrate = 500k SERIAL.println("CAN BUS Shield init fail"); SERIAL.println(" Init CAN BUS Shield again"); delay(100); } SERIAL.println("CAN BUS Shield init ok!"); + attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2518fd_ISR, FALLING); // start interrupt +} + +void MCP2518fd_ISR() { + flagRecv = 1; } void loop() { - controller->mcp2518fd_receiveMsg(); - delay(100); // send data per 100ms + if (flagRecv) { + controller->mcp2518fd_receiveMsg(); + delay(100); + } + // send data per 100ms } // END FILE diff --git a/examples/send/send.ino b/examples/send/send.ino index 7ce1b79..30c7556 100644 --- a/examples/send/send.ino +++ b/examples/send/send.ino @@ -1,5 +1,4 @@ // demo: CAN-BUS Shield, send data -// loovee@seeed.cc #include "mcp2518fd_can.h" @@ -10,19 +9,17 @@ #define SERIAL Serial #endif -//Mcp_Factory my_Factory; - - // 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 = 23; +const int SPI_CS_PIN = BCM8; mcp2518fd* controller; void setup() { SERIAL.begin(115200); + while(!Serial){}; controller = new mcp2518fd(); - controller->mcp_canbus(SPI_CS_PIN); - while (0 != controller->begin()) { // init can bus : baudrate = 500k + controller->mcp_canbus(SPI_CS_PIN); + while (0 != controller->begin()) { // init can bus : baudrate = 500k SERIAL.println("CAN BUS Shield init fail"); SERIAL.println(" Init CAN BUS Shield again"); delay(100); @@ -44,7 +41,7 @@ void loop() { } } - controller->mcp2518fd_sendMsgBuf(stmp); + controller->mcp2518fd_sendMsgBuf(stmp,8); delay(100); // send data per 100ms }