Article updated
at 28 Oct 2017
Attention: 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...
struct tCanMessageExt
|
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) |
|
Header for MCP2515 CAN controller library.
- Copyright
- Copyright (c) 2012 Toradex AG
- Author
- andy.kiser
- Rev
- 2863
- Date
- 2015-06-26 17:18:52 +0200 (Fr, 26 Jun 2015)
- Target Platforms:
- Colibri PXAxxx, T20
Use extended (29 bits ID) frame types.
#define MSG_DATA_LENGTH (8) |
Use standard (11 bits ID) frame types.
Structure for standard and extended frame types the size of this struct must be a multiple of 4!
void CANLibMCP2515DeInit |
( |
DWORD |
device |
) |
|
Deinitializes MCP2515 controller and related functions
- Parameters
-
[in] |
device |
Instance number (0..3) |
void CANLibMCP2515GetLibVersion |
( |
DWORD * |
verMaj, |
|
|
DWORD * |
verMin, |
|
|
DWORD * |
buildNumber |
|
) |
|
|
Request Library Revision
- Parameters
-
[out] |
verMaj |
Major library version |
[out] |
verMin |
Minor library version |
[out] |
buildNumber |
Library 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] |
device |
Instance number (0..3) |
- Return values
-
0 |
No Error CAN status information |
0x20 |
The 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] |
device |
Instance 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] |
interruptGpio |
GPIO where the MCP2515's nINT signal is connected to. |
[in] |
waterMark |
This parameter is not used anymore, the value ignored. |
[in] |
bufferSize |
Number of CAN Messages the Receive Buffer can hold |
[in] |
processorType |
This parameter is not used anymore, the value ignored. |
- Return values
-
0 |
Success |
!=0 |
error. the value represents internal error codes |
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] |
device |
Instance number (0..3) |
- Return values
-
INT32 CANLibMCP2515ReadMask |
( |
DWORD |
device |
) |
|
Reads the mask value from the local shadow variable (no SPI communication)
- Parameters
-
[in] |
device |
Instance number (0..3) |
- Return values
-
DWORD CANLibMCP2515ReceiveMessages |
( |
DWORD |
device, |
|
|
canMessageExt * |
message, |
|
|
DWORD |
numberOfMessages, |
|
|
DWORD |
timeout |
|
) |
|
|
Receives CAN messages
- Parameters
-
[in] |
device |
Instance number (0..3) |
[out] |
message |
Aray of received CAN messages. See description of canMessageExt in canlib-MCP2515.h for details. |
[in] |
numberOfMessages |
Number of messages to receive |
[in] |
timeout |
Maximum 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
-
Number |
of Received Messages |
BOOL CANLibMCP2515Reset |
( |
DWORD |
device |
) |
|
Clear local read and write message buffers and reset the MCP2515.
- Parameters
-
[in] |
device |
Instance number (0..3) |
- Return values
-
void CANLibMCP2515ResetInterruptFlags |
( |
DWORD |
device |
) |
|
BOOL CANLibMCP2515SetBaudrate |
( |
DWORD |
device, |
|
|
DWORD |
baud |
|
) |
|
|
Set the CAN Baudrate and configure the MCP2515 mode to "Normal Operation"
- Parameters
-
[in] |
device |
Instance number (0..3) |
[in] |
baud |
New Baud Rate [kbps] Accepted values are: 1000, 800, 500, 250, 125, 100, 50, 20, 10 |
- Return values
-
TRUE |
Mode change successful |
FALSE |
Failure |
BOOL CANLibMCP2515TransmitMessage |
( |
DWORD |
device, |
|
|
canMessageExt * |
message, |
|
|
DWORD |
timeout |
|
) |
|
|
Sends a CAN message
- Parameters
-
[in] |
device |
Instance number (0..3) |
[in] |
message |
CAN message to transmit. See description of canMessageExt in canlib-MCP2515.h for details. |
- Return values
-
TRUE |
Success |
FALSE |
Failure |
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] |
device |
Instance number (0..3) |
[in] |
description |
New 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] |
mask |
New acceptance mask(32bits) |
- Return values
-
TRUE |
Success |
FALSE |
Failed cases |
void DumpMcp2515 |
( |
DWORD |
device |
) |
|
Outputs the regsister values
- Parameters
-
[in] |
device |
Instance number |