mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-09-14 18:42:56 +00:00
Modified mcp2518fd spi_CS spi_INT on wio terminal
This commit is contained in:
@@ -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<mcp2518fd> 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
|
||||
|
||||
@@ -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<mcp2518fd> 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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user