mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-09-14 10:33:49 +00:00
complete canbus receive interrupt function
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// loovee, 2014-6-13
|
||||
|
||||
#include <SPI.h>
|
||||
#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++) {
|
||||
|
||||
Reference in New Issue
Block a user