Skip to main content

CAN MCP2515 Lib API

danger

this is a legacy library and thus not supported by Toradex anymore. We recommend that you use the new libraries for all Toradex modules. Please see the Toradex CE Libraries and Code Samples for up-to-date information.


Header for MCP2515 CAN controller library. More...

Data Structures

struct  tCanMessageExt 

Macros

#define STANDARD   0x00
 Use standard (11 bits ID) frame types. More...
 
#define EXTENDED   0x01
 Use extended (29 bits ID) frame types. More...
 
#define PXA_TYPE   (0)
 PXA type. More...
 
#define TEG_TYPE   (1)
 Tegra type. More...
 
#define UNKNOWN_TYPE   (2)
 Unknown type. More...
 
#define CAN_VER_MAJ   2
 Version info. More...
 
#define CAN_VER_MIN   0
 
#define CAN_VER_BUILD   0
 
#define MSG_DATA_LENGTH   (8)
 

Typedefs

typedef struct tCanMessageExt canMessageExt
 

Functions

BOOL CANLibMCP2515WriteDescriptor (DWORD device, DWORD description, DWORD mask)
 
INT32 CANLibMCP2515ReadDescriptor (DWORD device)
 
INT32 CANLibMCP2515ReadMask (DWORD device)
 
BOOL CANLibMCP2515Reset (DWORD device)
 
BOOL CANLibMCP2515SetBaudrate (DWORD device, DWORD baud)
 
BOOL CANLibMCP2515TransmitMessage (DWORD device, canMessageExt *message, DWORD timeout)
 
DWORD CANLibMCP2515ReceiveMessages (DWORD device, canMessageExt *message, DWORD numberOfMessages, DWORD timeout)
 
INT32 CANLibMCP2515Init (DWORD device, DWORD interruptGpio, DWORD waterMark, DWORD bufferSize, DWORD processorType)
 
void CANLibMCP2515DeInit (DWORD device)
 
INT32 CANLibMCP2515GetStatus (DWORD device)
 
void CANLibMCP2515PrintMessage (canMessageExt *message)
 
void CANLibMCP2515GetLibVersion (DWORD *verMaj, DWORD *verMin, DWORD *buildNumber)
 
void CANLibMCP2515ResetInterruptFlags (DWORD device)
 
void DumpMcp2515 (DWORD device)
 

Detailed Description

Header for MCP2515 CAN controller library.
Author
andy.kiser
Rev
2863
Date
2015-06-26 17:18:52 +0200 (Fr, 26 Jun 2015)
Target Platforms:
Colibri PXAxxx, T20

Macro Definition Documentation

#define CAN_VER_BUILD   0
#define CAN_VER_MAJ   2
Version info.
#define CAN_VER_MIN   0
#define EXTENDED   0x01
Use extended (29 bits ID) frame types.
#define MSG_DATA_LENGTH   (8)
#define PXA_TYPE   (0)
PXA type.
#define STANDARD   0x00
Use standard (11 bits ID) frame types.
#define TEG_TYPE   (1)
Tegra type.
#define UNKNOWN_TYPE   (2)
Unknown type.

Typedef Documentation

typedef struct tCanMessageExt canMessageExt
Structure for standard and extended frame types the size of this struct must be a multiple of 4!

Function Documentation

void CANLibMCP2515DeInit(DWORD device) 
Deinitializes MCP2515 controller and related functions
Parameters
[in]deviceInstance number (0..3)
void CANLibMCP2515GetLibVersion(DWORD * verMaj,
  DWORD * verMin,
  DWORD * buildNumber 
 )  
Request Library Revision
Parameters
[out]verMajMajor library version
[out]verMinMinor library version
[out]buildNumberLibrary Build number
INT32 CANLibMCP2515GetStatus(DWORD device) 
Returns CAN status for the particular instance.
The error status is sticky. Once an error has occured, this function returns the error value, until it is cleared by calling either CANLibMCP2515Init() or CANLibMCP2515Reset().
Parameters
[in]deviceInstance number (0..3)
Return values
0No Error CAN status information
0x20The MCP2515 triggered an error interrupt (MCP_ERRIF | MCP_WAKIF | MCP_MERRF)
INT32 CANLibMCP2515Init(DWORD device,
  DWORD interruptGpio,
  DWORD waterMark,
  DWORD bufferSize,
  DWORD processorType 
 )  
Initializes CAN Controller
Parameters
[in]deviceInstance number (0..3)
The instance number defines the SPI channel used to communicate with the CAN controller:
On Colibri PXA: 0->SPI1 1->SPI3 2->SPI2 3->SPI4
On Colibri T20: 0->SPI4 1->SPI3 2->SPI2 3->SPI4
On Colibri T30: 0->SPI1 1->SPI3 2->SPI2 3->SPI4
On Apalis T30: 0->SPI2 1->SPI4
[in]interruptGpioGPIO where the MCP2515's nINT signal is connected to.
[in]waterMarkThis parameter is not used anymore, the value ignored.
[in]bufferSizeNumber of CAN Messages the Receive Buffer can hold
[in]processorTypeThis parameter is not used anymore, the value ignored.
Return values
0Success
!=0error. the value represents internal error codes
void CANLibMCP2515PrintMessage(canMessageExt * message) 
INT32 CANLibMCP2515ReadDescriptor(DWORD device) 
Reads acceptance code from the local shadow variable (no SPI communication).
This function was copied from the CAN SJA1000 implementation, but the feature is not available for the MCP2515.
Parameters
[in]deviceInstance number (0..3)
Return values
Acceptancecode
INT32 CANLibMCP2515ReadMask(DWORD device) 
Reads the mask value from the local shadow variable (no SPI communication)
Parameters
[in]deviceInstance number (0..3)
Return values
AcceptanceMask
DWORD CANLibMCP2515ReceiveMessages(DWORD device,
  canMessageExt * message,
  DWORD numberOfMessages,
  DWORD timeout 
 )  
Receives CAN messages
Parameters
[in]deviceInstance number (0..3)
[out]messageAray of received CAN messages. See description of canMessageExt in canlib-MCP2515.h for details.
[in]numberOfMessagesNumber of messages to receive
[in]timeoutMaximum time to wait for a Receive interrupt [ms]
The time-out value needs to be a positive number between zero and 0x7FFFFFFF, or the infinite time-out value 0xFFFFFFFF
Return values
Numberof Received Messages
BOOL CANLibMCP2515Reset(DWORD device) 
Clear local read and write message buffers and reset the MCP2515.
Parameters
[in]deviceInstance number (0..3)
Return values
TRUESuccess
void CANLibMCP2515ResetInterruptFlags(DWORD device) 
BOOL CANLibMCP2515SetBaudrate(DWORD device,
  DWORD baud 
 )  
Set the CAN Baudrate and configure the MCP2515 mode to "Normal Operation"
Parameters
[in]deviceInstance number (0..3)
[in]baudNew Baud Rate [kbps]
Accepted values are: 1000, 800, 500, 250, 125, 100, 50, 20, 10
Return values
TRUEMode change successful
FALSEFailure
BOOL CANLibMCP2515TransmitMessage(DWORD device,
  canMessageExt * message,
  DWORD timeout 
 )  
Sends a CAN message
Parameters
[in]deviceInstance number (0..3)
[in]messageCAN message to transmit. See description of canMessageExt in canlib-MCP2515.h for details.
Return values
TRUESuccess
FALSEFailure
BOOL CANLibMCP2515WriteDescriptor(DWORD device,
  DWORD description,
  DWORD mask 
 )  
Writes acceptance code and mask register. The mask register is also stored in a local shadow variable.
Parameters
[in]deviceInstance number (0..3)
[in]descriptionNew acceptance code(32bits).
This parameter was copied from the CAN SJA1000 implementation, but the feature is not available for the MCP2515.
It has no effect.
[in]maskNew acceptance mask(32bits)
Return values
TRUESuccess
FALSEFailed cases
void DumpMcp2515(DWORD device) 
Outputs the regsister values
Parameters
[in]deviceInstance number
Send Feedback!