mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-07-27 19:55:59 +00:00
Move: CAN baudrate definitions to common header mcp_can.h
This commit is contained in:
@@ -271,11 +271,6 @@
|
||||
#define B1RTSM 0x02
|
||||
#define B0RTSM 0x01
|
||||
|
||||
// clock
|
||||
|
||||
#define MCP_16MHz 1
|
||||
#define MCP_8MHz 2
|
||||
|
||||
// speed 16M
|
||||
|
||||
#define MCP_16MHz_1000kBPS_CFG1 (0x00)
|
||||
@@ -448,30 +443,6 @@
|
||||
#define CANDEFAULTIDENTEXT (CAN_EXTID)
|
||||
|
||||
|
||||
typedef enum {
|
||||
CAN_NOBPS,
|
||||
CAN_5KBPS,
|
||||
CAN_10KBPS,
|
||||
CAN_20KBPS,
|
||||
CAN_25KBPS,
|
||||
CAN_31K25BPS,
|
||||
CAN_33KBPS ,
|
||||
CAN_40KBPS ,
|
||||
CAN_50KBPS ,
|
||||
CAN_80KBPS ,
|
||||
CAN_83K3BPS ,
|
||||
CAN_95KBPS ,
|
||||
CAN_100KBPS ,
|
||||
CAN_125KBPS ,
|
||||
CAN_200KBPS ,
|
||||
CAN_250KBPS ,
|
||||
CAN_500KBPS ,
|
||||
CAN_666KBPS ,
|
||||
CAN_1000KBPS
|
||||
} MCP2515_BITTIME_SETUP;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define CAN_MAX_CHAR_IN_MESSAGE (8)
|
||||
|
||||
+18
-2
@@ -2317,6 +2317,22 @@ int8_t mcp2518fd::mcp2518fd_receiveMsg() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static MCP2518FD_BITTIME_SETUP bittime_compat_to_mcp2518fd(byte speedset) {
|
||||
MCP2518FD_BITTIME_SETUP r;
|
||||
switch (speedset) {
|
||||
case CAN_125KBPS:
|
||||
r = CAN_125K_500K; break;
|
||||
case CAN_250KBPS:
|
||||
r = CAN_250K_500K; break;
|
||||
case CAN_500KBPS:
|
||||
r = CAN_500K_1M; break;
|
||||
case CAN_1000KBPS:
|
||||
default:
|
||||
r = CAN_1000K_4M; break;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/*********************************************************************************************************
|
||||
** Function name: mcp2515_init
|
||||
** Descriptions: init the device
|
||||
@@ -2368,8 +2384,8 @@ uint8_t mcp2518fd::mcp2518fd_init(byte speedset, const byte clock) {
|
||||
mcp2518fd_FilterToFifoLink(CAN_FILTER0, APP_RX_FIFO, true);
|
||||
|
||||
// Setup Bit Time
|
||||
mcp2518fd_BitTimeConfigure((MCP2518FD_BITTIME_SETUP)speedset,
|
||||
CAN_SSP_MODE_AUTO, CAN_SYSCLK_40M);
|
||||
mcp2518fd_BitTimeConfigure(bittime_compat_to_mcp2518fd(speedset),
|
||||
CAN_SSP_MODE_AUTO, CAN_SYSCLK_SPEED(clock));
|
||||
|
||||
// Setup Transmit and Receive Interrupts
|
||||
mcp2518fd_GpioModeConfigure(GPIO_MODE_INT, GPIO_MODE_INT);
|
||||
|
||||
+5
-28
@@ -47,6 +47,7 @@ DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <inttypes.h>
|
||||
#include "mcp_can.h"
|
||||
|
||||
// DOM-IGNORE-BEGIN
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
@@ -130,8 +131,7 @@ extern "C" {
|
||||
#define cRAMADDR_START 0x400
|
||||
#define cRAMADDR_END (cRAMADDR_START + cRAM_SIZE)
|
||||
|
||||
/*spi cs set*/
|
||||
extern uint8_t SPICS;
|
||||
/* SPI Chip Select */
|
||||
#define MCP2518fd_SELECT() \
|
||||
pinMode(SPICS, OUTPUT); \
|
||||
digitalWrite(SPICS, LOW)
|
||||
@@ -942,9 +942,9 @@ typedef enum {
|
||||
//! System Clock Selection
|
||||
|
||||
typedef enum {
|
||||
CAN_SYSCLK_40M,
|
||||
CAN_SYSCLK_20M,
|
||||
CAN_SYSCLK_10M
|
||||
CAN_SYSCLK_40M = MCP2518FD_40MHz,
|
||||
CAN_SYSCLK_20M = MCP2518FD_20MHz,
|
||||
CAN_SYSCLK_10M = MCP2518FD_10MHz,
|
||||
} CAN_SYSCLK_SPEED;
|
||||
|
||||
//! CLKO Divide
|
||||
@@ -1610,29 +1610,6 @@ static const uint32_t mcp25xxfdControlResetValues[] = {
|
||||
|
||||
|
||||
|
||||
// compatible layer for MCP2515
|
||||
typedef enum {
|
||||
CAN_NOBPS,
|
||||
CAN_5KBPS,
|
||||
CAN_10KBPS,
|
||||
CAN_20KBPS,
|
||||
CAN_25KBPS,
|
||||
CAN_31K25BPS,
|
||||
CAN_33KBPS ,
|
||||
CAN_40KBPS ,
|
||||
CAN_50KBPS ,
|
||||
CAN_80KBPS ,
|
||||
CAN_83K3BPS ,
|
||||
CAN_95KBPS ,
|
||||
CAN_100KBPS ,
|
||||
CAN_125KBPS = CAN_125K_500K,
|
||||
CAN_200KBPS ,
|
||||
CAN_250KBPS = CAN_250K_500K,
|
||||
CAN_500KBPS = CAN_500K_1M,
|
||||
CAN_666KBPS ,
|
||||
CAN_1000KBPS = CAN_1000K_4M,
|
||||
} MCP2515_BITTIME_SETUP;
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -19,6 +19,40 @@
|
||||
#define CAN_SENDMSGTIMEOUT (7)
|
||||
#define CAN_FAIL (0xff)
|
||||
|
||||
// clock
|
||||
typedef enum {
|
||||
MCP_NO_MHz,
|
||||
/* apply to MCP2515 */
|
||||
MCP_16MHz,
|
||||
MCP_8MHz,
|
||||
/* apply to MCP2518FD */
|
||||
MCP2518FD_40MHz = MCP_16MHz /* To compatible MCP2515 shield */,
|
||||
MCP2518FD_20MHz,
|
||||
MCP2518FD_10MHz,
|
||||
} MCP_CLOCK_T;
|
||||
|
||||
typedef enum {
|
||||
CAN_NOBPS,
|
||||
CAN_5KBPS,
|
||||
CAN_10KBPS,
|
||||
CAN_20KBPS,
|
||||
CAN_25KBPS,
|
||||
CAN_31K25BPS,
|
||||
CAN_33KBPS ,
|
||||
CAN_40KBPS ,
|
||||
CAN_50KBPS ,
|
||||
CAN_80KBPS ,
|
||||
CAN_83K3BPS ,
|
||||
CAN_95KBPS ,
|
||||
CAN_100KBPS ,
|
||||
CAN_125KBPS ,
|
||||
CAN_200KBPS ,
|
||||
CAN_250KBPS ,
|
||||
CAN_500KBPS ,
|
||||
CAN_666KBPS ,
|
||||
CAN_1000KBPS
|
||||
} MCP_BITTIME_SETUP;
|
||||
|
||||
|
||||
class MCP_CAN
|
||||
{
|
||||
@@ -26,6 +60,10 @@ public:
|
||||
virtual void enableTxInterrupt(bool enable = true) = 0; // enable transmit interrupt
|
||||
virtual void reserveTxBuffers(byte nTxBuf = 0) = 0;
|
||||
virtual byte getLastTxBuffer() = 0;
|
||||
/*
|
||||
* speedset be in MCP_BITTIME_SETUP
|
||||
* clockset be in MCP_CLOCK_T
|
||||
*/
|
||||
virtual byte begin(byte speedset, const byte clockset) = 0; // init can
|
||||
virtual byte init_Mask(byte num, byte ext, unsigned long ulData) = 0; // init Masks
|
||||
virtual byte init_Filt(byte num, byte ext, unsigned long ulData) = 0; // init filters
|
||||
|
||||
Reference in New Issue
Block a user