Add: more comments about CANFD examples

This commit is contained in:
turmary
2021-01-15 19:15:49 +08:00
parent 6dc4e7d197
commit efad5bb364
5 changed files with 104 additions and 52 deletions
+18 -4
View File
@@ -1,6 +1,6 @@
/*
* demo: CAN-BUS Shield, send random id/type/data
* This code has a little same with linux can-utils 'cangen -mv'
* This code has a little same with linux can-utils 'cangen -v'
*
* Copyright (C) 2020 Seeed Technology Co.,Ltd.
*/
@@ -31,8 +31,14 @@ const int CAN_INT_PIN = 2;
#ifdef CAN_2518FD
#include "mcp2518fd_can.h"
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
#define MAX_DATA_SIZE 64
#endif
// TEST TEST MCP2518FD CAN2.0 data transfer
#define MAX_DATA_SIZE 8
// To TEST MCP2518FD CANFD data transfer, uncomment below lines
// #undef MAX_DATA_SIZE
// #define MAX_DATA_SIZE 64
#endif//CAN_2518FD
#ifdef CAN_2515
#include "mcp2515_can.h"
@@ -42,8 +48,16 @@ mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
void setup() {
SERIAL_PORT_MONITOR.begin(115200);
while(!SERIAL_PORT_MONITOR){}
while (!SERIAL_PORT_MONITOR) {}
#if MAX_DATA_SIZE > 8
/*
* To compatible with MCP2515 API,
* default mode is CAN_CLASSIC_MODE
* Now set to CANFD mode.
*/
CAN.setMode(CAN_NORMAL_MODE);
#endif
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
delay(100);