mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-07-27 19:55:59 +00:00
Move: SERIAL to SERIAL_PORT_MONITOR in examples
This commit is contained in:
@@ -16,13 +16,6 @@
|
||||
***************************************************************************************************/
|
||||
#include <SPI.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
@@ -81,24 +74,24 @@ void set_mask_filt() {
|
||||
|
||||
void sendPid(unsigned char __pid) {
|
||||
unsigned char tmp[8] = {0x02, 0x01, __pid, 0, 0, 0, 0, 0};
|
||||
SERIAL.print("SEND PID: 0x");
|
||||
SERIAL.println(__pid, HEX);
|
||||
SERIAL_PORT_MONITOR.print("SEND PID: 0x");
|
||||
SERIAL_PORT_MONITOR.println(__pid, HEX);
|
||||
CAN.sendMsgBuf(CAN_ID_PID, 0, 8, tmp);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial){};
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
set_mask_filt();
|
||||
}
|
||||
|
||||
@@ -121,21 +114,21 @@ void taskCanRecv() {
|
||||
if (CAN_MSGAVAIL == CAN.checkReceive()) { // check if get data
|
||||
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
|
||||
|
||||
SERIAL.println("\r\n------------------------------------------------------------------");
|
||||
SERIAL.print("Get Data From id: 0x");
|
||||
SERIAL.println(CAN.getCanId(), HEX);
|
||||
SERIAL_PORT_MONITOR.println("\r\n------------------------------------------------------------------");
|
||||
SERIAL_PORT_MONITOR.print("Get Data From id: 0x");
|
||||
SERIAL_PORT_MONITOR.println(CAN.getCanId(), HEX);
|
||||
for (int i = 0; i < len; i++) { // print the data
|
||||
SERIAL.print("0x");
|
||||
SERIAL.print(buf[i], HEX);
|
||||
SERIAL.print("\t");
|
||||
SERIAL_PORT_MONITOR.print("0x");
|
||||
SERIAL_PORT_MONITOR.print(buf[i], HEX);
|
||||
SERIAL_PORT_MONITOR.print("\t");
|
||||
}
|
||||
SERIAL.println();
|
||||
SERIAL_PORT_MONITOR.println();
|
||||
}
|
||||
}
|
||||
|
||||
void taskDbg() {
|
||||
while (SERIAL.available()) {
|
||||
char c = SERIAL.read();
|
||||
while (SERIAL_PORT_MONITOR.available()) {
|
||||
char c = SERIAL_PORT_MONITOR.read();
|
||||
|
||||
if (c >= '0' && c <= '9') {
|
||||
PID_INPUT *= 0x10;
|
||||
|
||||
@@ -21,13 +21,6 @@
|
||||
|
||||
#define SPI_CS_PIN 9
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
@@ -37,7 +30,7 @@ mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
@@ -45,27 +38,27 @@ void setup() {
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) {
|
||||
#endif
|
||||
|
||||
SERIAL.println("CAN init failed, retry");
|
||||
SERIAL_PORT_MONITOR.println("CAN init failed, retry");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN init ok");
|
||||
SERIAL_PORT_MONITOR.println("CAN init ok");
|
||||
#ifdef CAN_2518FD
|
||||
if (CAN.mcpPinMode(GPIO_PIN_0, GPIO_MODE_INT)) {
|
||||
#else
|
||||
if (CAN.mcpPinMode(MCP_TX2RTS, MCP_PIN_IN)) {
|
||||
#endif
|
||||
SERIAL.println("TX2RTS is now an input");
|
||||
SERIAL_PORT_MONITOR.println("TX2RTS is now an input");
|
||||
} else {
|
||||
SERIAL.println("Could not switch TX2RTS");
|
||||
SERIAL_PORT_MONITOR.println("Could not switch TX2RTS");
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
SERIAL.print("TX2RTS is currently ");
|
||||
SERIAL_PORT_MONITOR.print("TX2RTS is currently ");
|
||||
#ifdef CAN_2518FD
|
||||
SERIAL.println(CAN.mcpDigitalRead(GPIO_PIN_0));
|
||||
SERIAL_PORT_MONITOR.println(CAN.mcpDigitalRead(GPIO_PIN_0));
|
||||
#else
|
||||
SERIAL.println(CAN.mcpDigitalRead(MCP_TX2RTS));
|
||||
SERIAL_PORT_MONITOR.println(CAN.mcpDigitalRead(MCP_TX2RTS));
|
||||
#endif
|
||||
delay(500);
|
||||
}
|
||||
|
||||
@@ -4,14 +4,6 @@
|
||||
#include "mcp2515_can.h"
|
||||
#include "mcp2518fd_can.h"
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
@@ -39,7 +31,7 @@ mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
@@ -47,19 +39,19 @@ void setup() {
|
||||
#ifdef CAN_2515
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) {
|
||||
#endif // init can bus : baudrate = 500k
|
||||
SERIAL.println("CAN init failed, retry");
|
||||
SERIAL_PORT_MONITOR.println("CAN init failed, retry");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN init ok");
|
||||
SERIAL_PORT_MONITOR.println("CAN init ok");
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
if (CAN.mcpPinMode(GPIO_PIN_0, GPIO_MODE_INT)) {
|
||||
#else
|
||||
if (CAN.mcpPinMode(MCP_TX2RTS, MCP_PIN_IN)) {
|
||||
#endif
|
||||
SERIAL.println("RX0BF is now an output");
|
||||
SERIAL_PORT_MONITOR.println("RX0BF is now an output");
|
||||
} else {
|
||||
SERIAL.println("Could not switch RX0BF");
|
||||
SERIAL_PORT_MONITOR.println("Could not switch RX0BF");
|
||||
}
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
@@ -67,14 +59,14 @@ void setup() {
|
||||
#else
|
||||
if (CAN.mcpPinMode(MCP_TX2RTS, MCP_PIN_IN)) {
|
||||
#endif
|
||||
SERIAL.println("RX1BF is now an output");
|
||||
SERIAL_PORT_MONITOR.println("RX1BF is now an output");
|
||||
} else {
|
||||
SERIAL.println("Could not switch RX1BF");
|
||||
SERIAL_PORT_MONITOR.println("Could not switch RX1BF");
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
SERIAL.println("10");
|
||||
SERIAL_PORT_MONITOR.println("10");
|
||||
#ifdef CAN_2518FD
|
||||
CAN.mcpDigitalWrite(GPIO_PIN_0, GPIO_HIGH);
|
||||
CAN.mcpDigitalWrite(GPIO_PIN_1, GPIO_LOW);
|
||||
@@ -84,7 +76,7 @@ void loop() {
|
||||
#endif
|
||||
|
||||
delay(500);
|
||||
SERIAL.println("01");
|
||||
SERIAL_PORT_MONITOR.println("01");
|
||||
#ifdef CAN_2518FD
|
||||
CAN.mcpDigitalWrite(GPIO_PIN_0, GPIO_LOW);
|
||||
CAN.mcpDigitalWrite(GPIO_PIN_1, GPIO_HIGH);
|
||||
|
||||
@@ -4,13 +4,6 @@
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
@@ -44,7 +37,7 @@ const int LED = 8;
|
||||
boolean ledON = 1;
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
pinMode(LED, OUTPUT);
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
@@ -52,11 +45,11 @@ void setup() {
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println("Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println("Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
}
|
||||
|
||||
|
||||
@@ -69,13 +62,13 @@ void loop() {
|
||||
|
||||
unsigned long canId = CAN.getCanId();
|
||||
|
||||
SERIAL.println("-----------------------------");
|
||||
SERIAL.println("get data from ID: 0x");
|
||||
SERIAL.println(canId, HEX);
|
||||
SERIAL_PORT_MONITOR.println("-----------------------------");
|
||||
SERIAL_PORT_MONITOR.println("get data from ID: 0x");
|
||||
SERIAL_PORT_MONITOR.println(canId, HEX);
|
||||
|
||||
for (int i = 0; i < len; i++) { // print the data
|
||||
SERIAL.print(buf[i]);
|
||||
SERIAL.print("\t");
|
||||
SERIAL_PORT_MONITOR.print(buf[i]);
|
||||
SERIAL_PORT_MONITOR.print("\t");
|
||||
if (ledON && i == 0) {
|
||||
|
||||
digitalWrite(LED, buf[i]);
|
||||
@@ -87,7 +80,7 @@ void loop() {
|
||||
ledON = 1;
|
||||
}
|
||||
}
|
||||
SERIAL.println();
|
||||
SERIAL_PORT_MONITOR.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
// demo: CAN-BUS Shield, receive data with check mode
|
||||
// send data coming to fast, such as less than 10ms, you can use this way
|
||||
// loovee, 2014-6-13
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
@@ -41,18 +33,18 @@ mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
}
|
||||
|
||||
|
||||
@@ -65,15 +57,15 @@ void loop() {
|
||||
|
||||
unsigned long canId = CAN.getCanId();
|
||||
|
||||
SERIAL.println("-----------------------------");
|
||||
SERIAL.print("Get data from ID: 0x");
|
||||
SERIAL.println(canId, HEX);
|
||||
SERIAL_PORT_MONITOR.println("-----------------------------");
|
||||
SERIAL_PORT_MONITOR.print("Get data from ID: 0x");
|
||||
SERIAL_PORT_MONITOR.println(canId, HEX);
|
||||
|
||||
for (int i = 0; i < len; i++) { // print the data
|
||||
SERIAL.print(buf[i], HEX);
|
||||
SERIAL.print("\t");
|
||||
SERIAL_PORT_MONITOR.print(buf[i], HEX);
|
||||
SERIAL_PORT_MONITOR.print("\t");
|
||||
}
|
||||
SERIAL.println();
|
||||
SERIAL_PORT_MONITOR.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,6 @@
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
@@ -47,8 +40,8 @@ unsigned char buf[8];
|
||||
char str[20];
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
while (!SERIAL) {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while (!SERIAL_PORT_MONITOR. {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2515_ISR, FALLING); // start interrupt
|
||||
@@ -57,13 +50,12 @@ void setup() {
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif // init can bus : baudrate = 500k
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
delay(100);
|
||||
|
||||
}
|
||||
|
||||
void MCP2515_ISR() {
|
||||
@@ -75,21 +67,21 @@ void loop() {
|
||||
// check if get data
|
||||
|
||||
flagRecv = 0; // clear flag
|
||||
SERIAL.println("into loop");
|
||||
SERIAL_PORT_MONITOR.println("into loop");
|
||||
// iterate over all pending messages
|
||||
// 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()) {
|
||||
// read data, len: data length, buf: data buf
|
||||
SERIAL.println("checkReceive");
|
||||
SERIAL_PORT_MONITOR.println("checkReceive");
|
||||
CAN.readMsgBuf(&len, buf);
|
||||
|
||||
// print the data
|
||||
for (int i = 0; i < len; i++) {
|
||||
SERIAL.print(buf[i]); SERIAL.print("\t");
|
||||
SERIAL_PORT_MONITOR.print(buf[i]); SERIAL_PORT_MONITOR.print("\t");
|
||||
}
|
||||
SERIAL.println();
|
||||
SERIAL_PORT_MONITOR.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,6 @@
|
||||
#include <SPI.h>
|
||||
#include "mcp2518fd_can.h"
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
@@ -29,20 +22,20 @@ unsigned char buf[64];
|
||||
char str[20];
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
while (!SERIAL) {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while (!SERIAL_PORT_MONITOR. {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2515_ISR, FALLING); // start interrupt
|
||||
CAN.setMode(0);
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
byte mode = CAN.getMode();
|
||||
SERIAL.printf("CAN BUS get mode = %d\n\r",mode);
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.printf("CAN BUS get mode = %d\n\r",mode);
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
}
|
||||
|
||||
void MCP2515_ISR() {
|
||||
@@ -54,20 +47,20 @@ void loop() {
|
||||
// check if get data
|
||||
|
||||
flagRecv = 0; // clear flag
|
||||
SERIAL.println("into loop");
|
||||
SERIAL_PORT_MONITOR.println("into loop");
|
||||
// iterate over all pending messages
|
||||
// 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()) {
|
||||
// read data, len: data length, buf: data buf
|
||||
SERIAL.println("checkReceive");
|
||||
SERIAL_PORT_MONITOR.println("checkReceive");
|
||||
CAN.readMsgBuf(&len, buf);
|
||||
// print the data
|
||||
for (int i = 0; i < len; i++) {
|
||||
SERIAL.print(buf[i]); SERIAL.print("\t");
|
||||
SERIAL_PORT_MONITOR.print(buf[i]); SERIAL_PORT_MONITOR.print("\t");
|
||||
}
|
||||
SERIAL.println();
|
||||
SERIAL_PORT_MONITOR.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,6 @@
|
||||
*/
|
||||
#include <SPI.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
@@ -45,18 +38,18 @@ mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
}
|
||||
|
||||
uint32_t id;
|
||||
@@ -100,6 +93,6 @@ void loop() {
|
||||
for (i = 0; i < len; i++) {
|
||||
n += sprintf(prbuf + n, "%02X ", cdata[i]);
|
||||
}
|
||||
SERIAL.println(prbuf);
|
||||
SERIAL_PORT_MONITOR.println(prbuf);
|
||||
}
|
||||
// END FILE
|
||||
|
||||
@@ -18,13 +18,6 @@
|
||||
#include "mcp2515_can.h"
|
||||
#include <avr/sleep.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
@@ -52,14 +45,14 @@ unsigned long lastMsgTime = 0;
|
||||
char str[20];
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS, MCP_16MHz)) { // init can bus : baudrate = 500k
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
|
||||
// attach interrupt
|
||||
pinMode(CAN_INT, INPUT);
|
||||
@@ -105,14 +98,14 @@ void loop() {
|
||||
|
||||
// print the data
|
||||
for (int i = 0; i < len; i++) {
|
||||
SERIAL.print(buf[i]); SERIAL.print("\t");
|
||||
SERIAL_PORT_MONITOR.print(buf[i]); SERIAL_PORT_MONITOR.print("\t");
|
||||
}
|
||||
SERIAL.println();
|
||||
SERIAL_PORT_MONITOR.println();
|
||||
}
|
||||
}
|
||||
} else if (millis() > lastBusActivity + KEEP_AWAKE_TIME) {
|
||||
// Put MCP2515 into sleep mode
|
||||
SERIAL.println(F("CAN sleep"));
|
||||
SERIAL_PORT_MONITOR.println(F("CAN sleep"));
|
||||
CAN.sleep();
|
||||
|
||||
// Put the transceiver into standby (by pulling Rs high):
|
||||
@@ -123,10 +116,10 @@ void loop() {
|
||||
}
|
||||
|
||||
// Put the MCU to sleep
|
||||
SERIAL.println(F("MCU sleep"));
|
||||
SERIAL_PORT_MONITOR.println(F("MCU sleep"));
|
||||
|
||||
// Clear serial buffers before sleeping
|
||||
SERIAL.flush();
|
||||
SERIAL_PORT_MONITOR.flush();
|
||||
|
||||
cli(); // Disable interrupts
|
||||
if (!flagRecv) { // Make sure we havn't missed an interrupt between the check above and now. If an interrupt happens between now and sei()/sleep_cpu() then sleep_cpu() will immediately wake up again
|
||||
@@ -149,7 +142,7 @@ void loop() {
|
||||
digitalWrite(RS_OUTPUT, LOW);
|
||||
}
|
||||
|
||||
SERIAL.println(F("Woke up"));
|
||||
SERIAL_PORT_MONITOR.println(F("Woke up"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,6 @@
|
||||
#include <SPI.h>
|
||||
#include <SD.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
File myFile;
|
||||
|
||||
#define CAN_2515
|
||||
@@ -50,24 +43,24 @@ unsigned char buf[8];
|
||||
char str[20];
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2515_ISR, FALLING); // start interrupt
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println("Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println("Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
|
||||
if (!SD.begin(4)) {
|
||||
SERIAL.println("SD initialization failed!");
|
||||
SERIAL_PORT_MONITOR.println("SD initialization failed!");
|
||||
while (1);
|
||||
}
|
||||
SERIAL.println("SD initialization done.");
|
||||
SERIAL_PORT_MONITOR.println("SD initialization done.");
|
||||
}
|
||||
|
||||
void MCP2515_ISR() {
|
||||
@@ -91,19 +84,19 @@ void loop() {
|
||||
// read data, len: data length, buf: data buf
|
||||
CAN.readMsgBufID(&id, &len, buf);
|
||||
|
||||
SERIAL.print(id);
|
||||
SERIAL.print(",");
|
||||
SERIAL_PORT_MONITOR.print(id);
|
||||
SERIAL_PORT_MONITOR.print(",");
|
||||
myFile.print(id);
|
||||
myFile.print(",");
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
SERIAL.print(buf[i]);
|
||||
SERIAL.print(",");
|
||||
SERIAL_PORT_MONITOR.print(buf[i]);
|
||||
SERIAL_PORT_MONITOR.print(",");
|
||||
|
||||
myFile.print(buf[i]);
|
||||
myFile.print(",");
|
||||
}
|
||||
SERIAL.println();
|
||||
SERIAL_PORT_MONITOR.println();
|
||||
myFile.println();
|
||||
}
|
||||
|
||||
|
||||
+5
-13
@@ -4,14 +4,6 @@
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
@@ -42,7 +34,7 @@ mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif // Set CS pin
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial){};
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
@@ -50,11 +42,11 @@ void setup() {
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
}
|
||||
|
||||
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
@@ -73,7 +65,7 @@ void loop() {
|
||||
|
||||
CAN.sendMsgBuf(0x00, 0, 8, stmp);
|
||||
delay(100); // send data per 100ms
|
||||
SERIAL.println("CAN BUS sendMsgBuf ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS sendMsgBuf ok!");
|
||||
}
|
||||
|
||||
// END FILE
|
||||
|
||||
@@ -5,13 +5,6 @@
|
||||
#include <SPI.h>
|
||||
#include "mcp2518fd_can.h"
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#define CAN_2518FD
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
@@ -22,18 +15,18 @@ mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial){};
|
||||
CAN.setMode(0); // Set FD Mode
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
byte mode = CAN.getMode();
|
||||
SERIAL.print("CAN BUS get mode = ");
|
||||
SERIAL.println(mode);
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.print("CAN BUS get mode = ");
|
||||
SERIAL_PORT_MONITOR.println(mode);
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
}
|
||||
|
||||
unsigned char stmp[64] = {0};
|
||||
@@ -52,7 +45,7 @@ void loop() {
|
||||
|
||||
CAN.sendMsgBuf(0x00, 0, 15, stmp);
|
||||
delay(100); // send data per 100ms
|
||||
SERIAL.println("CAN BUS sendMsgBuf ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS sendMsgBuf ok!");
|
||||
}
|
||||
|
||||
// END FILE
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
// demo: CAN-BUS Shield, send data
|
||||
#include <SPI.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
@@ -42,24 +35,24 @@ const int ledLOW = 0;
|
||||
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
}
|
||||
|
||||
unsigned char stmp[8] = {ledHIGH, 1, 2, 3, ledLOW, 5, 6, 7};
|
||||
|
||||
void loop() {
|
||||
SERIAL.println("In loop");
|
||||
SERIAL_PORT_MONITOR.println("In loop");
|
||||
// send data: id = 0x70, standard frame, data len = 8, stmp: data buf
|
||||
CAN.sendMsgBuf(0x70, 0, 8, stmp);
|
||||
delay(1000); // send data once per second
|
||||
|
||||
@@ -14,13 +14,6 @@
|
||||
#include <ros.h>
|
||||
#include <std_msgs/Empty.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
ros::NodeHandle nh;
|
||||
|
||||
const int SPI_CS_PIN = 9;
|
||||
@@ -45,16 +38,16 @@ ros::Subscriber<std_msgs::Empty> sub("toggle_led", &messageCb);
|
||||
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
nh.initNode();
|
||||
nh.subscribe(sub);
|
||||
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,13 +6,6 @@
|
||||
*/
|
||||
#include <SPI.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
@@ -45,7 +38,7 @@ mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial){};
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
@@ -53,11 +46,11 @@ void setup() {
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
|
||||
randomSeed(millis());
|
||||
}
|
||||
@@ -111,10 +104,10 @@ void loop() {
|
||||
for (i = 0; i < len; i++) {
|
||||
n += sprintf(prbuf + n, "%02X ", cdata[i]);
|
||||
}
|
||||
SERIAL.println(prbuf);
|
||||
SERIAL_PORT_MONITOR.println(prbuf);
|
||||
|
||||
unsigned d = random(30);
|
||||
SERIAL.println(d);
|
||||
SERIAL_PORT_MONITOR.println(d);
|
||||
delay(d);
|
||||
}
|
||||
// END FILE
|
||||
|
||||
@@ -5,13 +5,6 @@
|
||||
#include <SPI.h>
|
||||
#include "mcp2518fd_can.h"
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
// Set SPI CS Pin according to your hardware
|
||||
// For Wio Terminal w/ MCP2518FD RPi Hat:
|
||||
// Channel 0 SPI_CS Pin: BCM 8
|
||||
@@ -31,7 +24,7 @@ unsigned char len = 0;
|
||||
unsigned char buf[8];
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial); // wait for Serial
|
||||
|
||||
if (CAN_SEND.begin((byte)CAN_500K_1M) != 0 || CAN_RECEIVE.begin((byte)CAN_500K_1M) != 0) {
|
||||
@@ -39,7 +32,7 @@ void setup() {
|
||||
while(1);
|
||||
}
|
||||
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
}
|
||||
|
||||
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
@@ -58,21 +51,21 @@ void loop() {
|
||||
|
||||
CAN_SEND.sendMsgBuf(0x00, 0, 8, stmp);
|
||||
delay(100); // send data per 100ms
|
||||
SERIAL.println("CAN BUS sendMsgBuf ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS sendMsgBuf ok!");
|
||||
|
||||
// ---------------------
|
||||
|
||||
if (CAN_MSGAVAIL == CAN_RECEIVE.checkReceive()) {
|
||||
// read data, len: data length, buf: data buf
|
||||
SERIAL.println("checkReceive");
|
||||
SERIAL_PORT_MONITOR.println("checkReceive");
|
||||
CAN_RECEIVE.readMsgBuf(&len, buf);
|
||||
// print the data
|
||||
for (int i = 0; i < len; i++) {
|
||||
SERIAL.print(buf[i]); SERIAL.print(" ");
|
||||
SERIAL_PORT_MONITOR.print(buf[i]); SERIAL_PORT_MONITOR.print(" ");
|
||||
}
|
||||
SERIAL.println();
|
||||
SERIAL_PORT_MONITOR.println();
|
||||
}
|
||||
SERIAL.println("---LOOP END---");
|
||||
SERIAL_PORT_MONITOR.println("---LOOP END---");
|
||||
}
|
||||
|
||||
// END FILE
|
||||
|
||||
@@ -5,13 +5,6 @@
|
||||
#include <SPI.h>
|
||||
#include "mcp2518fd_can.h"
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
// Set SPI CS Pin according to your hardware
|
||||
// For Wio Terminal w/ MCP2518FD RPi Hat:
|
||||
// Channel 0 SPI_CS Pin: BCM 8
|
||||
@@ -28,7 +21,7 @@ mcp2518fd CAN_SEND(SPI_CS_PIN_SEND);
|
||||
mcp2518fd CAN_RECEIVE(SPI_CS_PIN_RECEIVE);
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial); // wait for Serial
|
||||
CAN_SEND.setMode(0);
|
||||
CAN_RECEIVE.setMode(0);
|
||||
@@ -39,9 +32,9 @@ void setup() {
|
||||
}
|
||||
byte send_mode = CAN_SEND.getMode();
|
||||
byte receive_mode = CAN_RECEIVE.getMode();
|
||||
SERIAL.print("CAN BUS Send Mode = "); SERIAL.println(send_mode);
|
||||
SERIAL.print("CAN BUS Receive Mode = "); SERIAL.println(receive_mode);
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.print("CAN BUS Send Mode = "); SERIAL_PORT_MONITOR.println(send_mode);
|
||||
SERIAL_PORT_MONITOR.print("CAN BUS Receive Mode = "); SERIAL_PORT_MONITOR.println(receive_mode);
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
}
|
||||
|
||||
unsigned char stmp[64] = {0};
|
||||
@@ -62,21 +55,21 @@ void loop() {
|
||||
|
||||
CAN_SEND.sendMsgBuf(0x00, 0, 15, stmp);
|
||||
delay(100); // send data per 100ms
|
||||
SERIAL.println("CAN BUS sendMsgBuf ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS sendMsgBuf ok!");
|
||||
|
||||
// ---------------------
|
||||
|
||||
if (CAN_MSGAVAIL == CAN_RECEIVE.checkReceive()) {
|
||||
// read data, len: data length, buf: data buf
|
||||
SERIAL.println("checkReceive");
|
||||
SERIAL_PORT_MONITOR.println("checkReceive");
|
||||
CAN_RECEIVE.readMsgBuf(&len, buf);
|
||||
// print the data
|
||||
for (int i = 0; i < len; i++) {
|
||||
SERIAL.print(buf[i]); SERIAL.print("");
|
||||
SERIAL_PORT_MONITOR.print(buf[i]); SERIAL_PORT_MONITOR.print("");
|
||||
}
|
||||
SERIAL.println();
|
||||
SERIAL_PORT_MONITOR.println();
|
||||
}
|
||||
SERIAL.println("---LOOP END---");
|
||||
SERIAL_PORT_MONITOR.println("---LOOP END---");
|
||||
}
|
||||
|
||||
// END FILE
|
||||
|
||||
@@ -8,13 +8,6 @@
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/wdt.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
@@ -62,14 +55,14 @@ void sleepMCU()
|
||||
}
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS, MCP_16MHz)) { // init can bus : baudrate = 500k
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
|
||||
CAN.setSleepWakeup(0); // the MCP2515 will NOT wake up on incoming messages,
|
||||
// making it a 'send only' node
|
||||
@@ -87,7 +80,7 @@ void setup() {
|
||||
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
void loop() {
|
||||
SERIAL.println("Sending message");
|
||||
SERIAL_PORT_MONITOR.println("Sending message");
|
||||
|
||||
CAN.sendMsgBuf(0x00, 0, 0, NULL); // Send empty wakeup message
|
||||
|
||||
@@ -110,8 +103,8 @@ void loop() {
|
||||
|
||||
|
||||
// sleep
|
||||
SERIAL.println("Sleep");
|
||||
SERIAL.flush();
|
||||
SERIAL_PORT_MONITOR.println("Sleep");
|
||||
SERIAL_PORT_MONITOR.flush();
|
||||
|
||||
// Put MCP2515 into sleep mode
|
||||
CAN.sleep();
|
||||
|
||||
@@ -5,13 +5,6 @@
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
@@ -46,7 +39,7 @@ unsigned char buf[8];
|
||||
char str[20];
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial){};
|
||||
attachInterrupt(digitalPinToInterrupt(interruptPin), MCP2515_ISR, FALLING); // start interrupt
|
||||
#ifdef CAN_2518FD
|
||||
@@ -54,11 +47,11 @@ void setup() {
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
|
||||
/*
|
||||
set mask, set both the mask to 0x3ff
|
||||
@@ -90,15 +83,15 @@ void loop() {
|
||||
flagRecv = 0; // clear flag
|
||||
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
|
||||
|
||||
SERIAL.println("\r\n------------------------------------------------------------------");
|
||||
SERIAL.print("Get Data From id: ");
|
||||
SERIAL.println(CAN.getCanId());
|
||||
SERIAL_PORT_MONITOR.println("\r\n------------------------------------------------------------------");
|
||||
SERIAL_PORT_MONITOR.print("Get Data From id: ");
|
||||
SERIAL_PORT_MONITOR.println(CAN.getCanId());
|
||||
for (int i = 0; i < len; i++) { // print the data
|
||||
SERIAL.print("0x");
|
||||
SERIAL.print(buf[i], HEX);
|
||||
SERIAL.print("\t");
|
||||
SERIAL_PORT_MONITOR.print("0x");
|
||||
SERIAL_PORT_MONITOR.print(buf[i], HEX);
|
||||
SERIAL_PORT_MONITOR.print("\t");
|
||||
}
|
||||
SERIAL.println();
|
||||
SERIAL_PORT_MONITOR.println();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,6 @@
|
||||
// this demo will show you how to use mask and filter
|
||||
#include <SPI.h>
|
||||
|
||||
/*SAMD core*/
|
||||
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
|
||||
#define SERIAL SerialUSB
|
||||
#else
|
||||
#define SERIAL Serial
|
||||
#endif
|
||||
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
@@ -38,7 +31,7 @@ mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
|
||||
|
||||
void setup() {
|
||||
SERIAL.begin(115200);
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial){};
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
@@ -46,11 +39,11 @@ void setup() {
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL.println("CAN BUS Shield init fail");
|
||||
SERIAL.println(" Init CAN BUS Shield again");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init fail");
|
||||
SERIAL_PORT_MONITOR.println(" Init CAN BUS Shield again");
|
||||
delay(100);
|
||||
}
|
||||
SERIAL.println("CAN BUS Shield init ok!");
|
||||
SERIAL_PORT_MONITOR.println("CAN BUS Shield init ok!");
|
||||
}
|
||||
|
||||
unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
|
||||
Reference in New Issue
Block a user