Skip to content

Commit

Permalink
added 12mhz and CANopen support (#84)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
munzili authored Apr 2, 2023
1 parent 631d2e7 commit ab1141c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 15 deletions.
27 changes: 26 additions & 1 deletion src/ArduinoMCP2515.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**************************************************************************************
Expand Down
49 changes: 37 additions & 12 deletions src/ArduinoMCP2515.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned long()> MicroSecondFunc;
Expand Down
29 changes: 27 additions & 2 deletions src/MCP2515/MCP2515_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
**************************************************************************************/
Expand Down

0 comments on commit ab1141c

Please sign in to comment.