From ab1141c3a6df1fd851215d93de310b7f0073089c Mon Sep 17 00:00:00 2001 From: Thomas Munz Date: Sun, 2 Apr 2023 19:31:39 +0200 Subject: [PATCH] added 12mhz and CANopen support (#84) * added 12 mhz options * fixed ordering * fixed wrong index sorting (double added) * added CANopen support * fixed typo * reversed existing CNF flags to org values. Only new values will be added --- src/ArduinoMCP2515.cpp | 27 +++++++++++++++++++- src/ArduinoMCP2515.h | 49 +++++++++++++++++++++++++++--------- src/MCP2515/MCP2515_Config.h | 29 +++++++++++++++++++-- 3 files changed, 90 insertions(+), 15 deletions(-) diff --git a/src/ArduinoMCP2515.cpp b/src/ArduinoMCP2515.cpp index cc490fa..cf54efb 100644 --- a/src/ArduinoMCP2515.cpp +++ b/src/ArduinoMCP2515.cpp @@ -25,18 +25,43 @@ using namespace MCP2515; static CanBitRateConfig const BIT_RATE_CONFIG_ARRAY[] = { + BitRate_10kBPS_16MHz, + BitRate_20kBPS_16MHz, + BitRate_50kBPS_16MHz, + BitRate_100kBPS_16MHz, BitRate_125kBPS_16MHz, BitRate_250kBPS_16MHz, BitRate_500kBPS_16MHz, + BitRate_800kBPS_16MHz, BitRate_1000kBPS_16MHz, + + BitRate_10kBPS_8MHz, + BitRate_20kBPS_8MHz, + BitRate_50kBPS_8MHz, + BitRate_100kBPS_8MHz, BitRate_125kBPS_8MHz, BitRate_250kBPS_8MHz, BitRate_500kBPS_8MHz, + BitRate_800kBPS_8MHz, BitRate_1000kBPS_8MHz, + + BitRate_10kBPS_10MHz, + BitRate_20kBPS_10MHz, + BitRate_50kBPS_10MHz, + BitRate_1000kBPS_10MHz, BitRate_125kBPS_10MHz, BitRate_250kBPS_10MHz, BitRate_500kBPS_10MHz, - BitRate_1000kBPS_10MHz + BitRate_1000kBPS_10MHz, + + BitRate_10kBPS_12MHz, + BitRate_20kBPS_12MHz, + BitRate_50kBPS_12MHz, + BitRate_100kBPS_12MHz, + BitRate_125kBPS_12MHz, + BitRate_250kBPS_12MHz, + BitRate_500kBPS_12MHz, + BitRate_1000kBPS_12MHz }; /************************************************************************************** diff --git a/src/ArduinoMCP2515.h b/src/ArduinoMCP2515.h index 23c5523..f8925d3 100644 --- a/src/ArduinoMCP2515.h +++ b/src/ArduinoMCP2515.h @@ -43,18 +43,43 @@ enum class CanBitRate : size_t { - BR_125kBPS_16MHZ = 0, - BR_250kBPS_16MHZ = 1, - BR_500kBPS_16MHZ = 2, - BR_1000kBPS_16MHZ = 3, - BR_125kBPS_8MHZ = 4, - BR_250kBPS_8MHZ = 5, - BR_500kBPS_8MHZ = 6, - BR_1000kBPS_8MHZ = 7, - BR_125kBPS_10MHZ = 8, - BR_250kBPS_10MHZ = 9, - BR_500kBPS_10MHZ = 10, - BR_1000kBPS_10MHZ = 11 + BR_10kBPS_16MHZ = 0, + BR_20kBPS_16MHZ, + BR_50kBPS_16MHZ, + BR_100kBPS_16MHZ, + BR_125kBPS_16MHZ, + BR_250kBPS_16MHZ, + BR_500kBPS_16MHZ, + BR_800kBPS_16MHZ, + BR_1000kBPS_16MHZ, + + BR_10kBPS_8MHZ, + BR_20kBPS_8MHZ, + BR_50kBPS_8MHZ, + BR_100kBPS_8MHZ, + BR_125kBPS_8MHZ, + BR_250kBPS_8MHZ, + BR_500kBPS_8MHZ, + BR_800kBPS_8MHZ, + BR_1000kBPS_8MHZ, + + BR_10kBPS_10MHZ, + BR_20kBPS_10MHZ, + BR_50kBPS_10MHZ, + BR_100kBPS_10MHZ, + BR_125kBPS_10MHZ, + BR_250kBPS_10MHZ, + BR_500kBPS_10MHZ, + BR_1000kBPS_10MHZ, + + BR_10kBPS_12MHZ, + BR_20kBPS_12MHZ, + BR_50kBPS_12MHZ, + BR_100kBPS_12MHZ, + BR_125kBPS_12MHZ, + BR_250kBPS_12MHZ, + BR_500kBPS_12MHZ, + BR_1000kBPS_12MHZ }; typedef std::function MicroSecondFunc; diff --git a/src/MCP2515/MCP2515_Config.h b/src/MCP2515/MCP2515_Config.h index c3f83b7..ee39b76 100644 --- a/src/MCP2515/MCP2515_Config.h +++ b/src/MCP2515/MCP2515_Config.h @@ -45,21 +45,46 @@ typedef struct * GLOBAL CONSTANTS **************************************************************************************/ +static CanBitRateConfig constexpr BitRate_10kBPS_16MHz = {0x31, 0xb5, 0x01}; +static CanBitRateConfig constexpr BitRate_20kBPS_16MHz = {0x18, 0xb5, 0x01}; +static CanBitRateConfig constexpr BitRate_50kBPS_16MHz = {0x09, 0xb5, 0x01}; +static CanBitRateConfig constexpr BitRate_100kBPS_16MHz = {0x04, 0xb5, 0x01}; static CanBitRateConfig constexpr BitRate_125kBPS_16MHz = {0x03, 0xF0, 0x86}; static CanBitRateConfig constexpr BitRate_250kBPS_16MHz = {0x41, 0xF1, 0x85}; static CanBitRateConfig constexpr BitRate_500kBPS_16MHz = {0x00, 0xF0, 0x86}; +static CanBitRateConfig constexpr BitRate_800kBPS_16MHz = {0x00, 0x9a, 0x01}; static CanBitRateConfig constexpr BitRate_1000kBPS_16MHz = {0x00, 0xD0, 0x82}; +static CanBitRateConfig constexpr BitRate_10kBPS_8MHz = {0x18, 0xb5, 0x01}; +static CanBitRateConfig constexpr BitRate_20kBPS_8MHz = {0x09, 0xbf, 0x02}; +static CanBitRateConfig constexpr BitRate_50kBPS_8MHz = {0x04, 0xb5, 0x01}; +static CanBitRateConfig constexpr BitRate_100kBPS_8MHz = {0x01, 0xbf, 0x02}; +static CanBitRateConfig constexpr BitRate_125kBPS_8MHz = {0x01, 0xb1, 0x05}; static CanBitRateConfig constexpr BitRate_250kBPS_8MHz = {0x00, 0xb1, 0x05}; static CanBitRateConfig constexpr BitRate_500kBPS_8MHz = {0x00, 0x90, 0x02}; -static CanBitRateConfig constexpr BitRate_125kBPS_8MHz = {0x01, 0xb1, 0x05}; +static CanBitRateConfig constexpr BitRate_800kBPS_8MHz = {0x00, 0x80, 0x01}; static CanBitRateConfig constexpr BitRate_1000kBPS_8MHz = {0x00, 0x80, 0x00}; +static CanBitRateConfig constexpr BitRate_10kBPS_10MHz = {0x18, 0xbf, 0x02}; +static CanBitRateConfig constexpr BitRate_20kBPS_10MHz = {0x18, 0x9a, 0x01}; +static CanBitRateConfig constexpr BitRate_50kBPS_10MHz = {0x04, 0xbf, 0x02}; +static CanBitRateConfig constexpr BitRate_100kBPS_10MHz = {0x04, 0x9a, 0x01}; +static CanBitRateConfig constexpr BitRate_125kBPS_10MHz = {0x01, 0xB6, 0x04}; static CanBitRateConfig constexpr BitRate_250kBPS_10MHz = {0x00, 0xB6, 0x04}; static CanBitRateConfig constexpr BitRate_500kBPS_10MHz = {0x00, 0x9A, 0x01}; -static CanBitRateConfig constexpr BitRate_125kBPS_10MHz = {0x01, 0xB6, 0x04}; +//static CanBitRateConfig constexpr BitRate_800kBPS_10MHz = {0x00, 0x00, 0x00}; // 10 mhz is to slow for this speed - not possible static CanBitRateConfig constexpr BitRate_1000kBPS_10MHz = {0x00, 0x80, 0x01}; +static CanBitRateConfig constexpr BitRate_10kBPS_12MHz = {0x27, 0xad, 0x01}; +static CanBitRateConfig constexpr BitRate_20kBPS_12MHz = {0x13, 0xad, 0x01}; +static CanBitRateConfig constexpr BitRate_50kBPS_12MHz = {0x07, 0xad, 0x01}; +static CanBitRateConfig constexpr BitRate_100kBPS_12MHz = {0x03, 0xad, 0x01}; +static CanBitRateConfig constexpr BitRate_125kBPS_12MHz = {0x02, 0xb5, 0x01}; +static CanBitRateConfig constexpr BitRate_250kBPS_12MHz = {0x01, 0xa3, 0x01}; +static CanBitRateConfig constexpr BitRate_500kBPS_12MHz = {0x00, 0xa3, 0x01}; +//static CanBitRateConfig constexpr BitRate_800kBPS_12MHz = {0x00, 0x00, 0x00}; // 12 mhz is to slow for this speed - not possible +static CanBitRateConfig constexpr BitRate_1000kBPS_12MHz = {0x00, 0x88, 0x01}; + /************************************************************************************** * CTOR/DTOR **************************************************************************************/