Datasheet microchip mcp2515
Содержание:
- Модельный ряд
- Send Data
- MCP2515 CAN Controller Library for Arduino
- Модельный ряд
- 4. Receive Data
- Receive Data
- 6. Examples
- Datasheets
- 1. Initialization
- Set Receive Mask and Filter
- Модельный ряд
- 3. Send Data
- Модельный ряд
- Examples
- Экологический статус
- Datasheets
- Datasheets
- Корпус / Упаковка / Маркировка
- 1. Initialization
- Initialization
- Datasheets
- Datasheets
- 5. Set Receive Mask and Filter
Модельный ряд
Серия: MCP2515
MCP2515-E/ML MCP2515-E/MLVAO MCP2515-E/P MCP2515-E/PRB2 MCP2515-E/PRB4 MCP2515-E/SO MCP2515-E/SORB2 MCP2515-E/SORB4 MCP2515-E/SOVAO MCP2515-E/ST MCP2515-E/STRB2 MCP2515-E/STRB4 MCP2515-E/STVAO MCP2515-I/ML MCP2515-I/P MCP2515-I/PRB2 MCP2515-I/PRB4 MCP2515-I/SO MCP2515-I/SOGRB2 MCP2515-I/SORB2 MCP2515-I/SORB4 MCP2515-I/SOVAO MCP2515-I/ST MCP2515-I/STRB2 MCP2515-I/STRB4 MCP2515-I/STVAO MCP2515T-E/ML MCP2515T-E/MLVAO MCP2515T-E/SO MCP2515T-E/SORB2 MCP2515T-E/SORB4 MCP2515T-E/SOVAO MCP2515T-E/ST MCP2515T-E/STRB2 MCP2515T-E/STRB4 MCP2515T-E/STVAO MCP2515T-I/ML MCP2515T-I/SO MCP2515T-I/SORB2 MCP2515T-I/SORB4 MCP2515T-I/SOVAO MCP2515T-I/ST MCP2515T-I/STG MCP2515T-I/STRB2 MCP2515T-I/STRB4
(45)
Send Data
MCP2515::ERROR sendMessage(const MCP2515::TXBn txbn, const struct can_frame *frame); MCP2515::ERROR sendMessage(const struct can_frame *frame);
This is a function to send data onto the bus.
For example, In the ‘send’ example, we have:
struct can_frame frame; frame.can_id = 0x000; frame.can_dlc = 4; frame.data[] = 0xFF; frame.data = 0xFF; frame.data = 0xFF; frame.data = 0xFF; /* send out the message to the bus and tell other devices this is a standard frame from 0x00. */ mcp2515.sendMessage(&frame);
struct can_frame frame; frame.can_id = 0x12345678 | CAN_EFF_FLAG; frame.can_dlc = 2; frame.data[] = 0xFF; frame.data = 0xFF; /* send out the message to the bus using second TX buffer and tell other devices this is a extended frame from 0x12345678. */ mcp2515.sendMessage(MCP2515::TXB1, &frame);
MCP2515 CAN Controller Library for Arduino
Compatibility with the ACAN library
This library is fully compatible with the Teensy 3.x ACAN library https://github.com/pierremolinaro/acan, it uses a very similar API and the same class for handling messages.
ACAN2515 library description
ACAN2515 is a driver for the MCP2515 CAN Controller. It runs on any Arduino compatible board.
You can choose any frequency for your MCP2515, the actual frequency is a parameter of the library.
The driver supports many bit rates: for a 16 MHz quartz, the CAN bit timing calculator finds settings for standard 62.5 kbit/s, 125 kbit/s, 250 kbit/s, 500 kbit/s, 1 Mbit/s, but also for an exotic bit rate as 727 kbit/s. If the desired bit rate cannot be achieved, the method does not configure the hardware and returns an error code.
Demo Sketch
Configuration is a four-step operation.
- Instanciation of the object : the constructor has one parameter: the wished CAN bit rate. The is fully initialized.
- You can override default settings. Here, we set the property to true, enabling to run demo code without any additional hardware (no CAN transceiver needed). We can also for example change the receive buffer size by setting the property.
- Calling the method configures the driver and starts CAN bus participation. Any message can be sent, any frame on the bus is received. No default filter to provide.
- You check the value to detect configuration error(s).
static const byte MCP2515_CS = 20 ; // CS input of MCP2515, adapt to your design static const byte MCP2515_INT = 37 ; // INT output of MCP2515, adapt to your design ACAN2515 can (MCP2515_CS, SPI, MCP2515_INT) ; // You can use SPI2, SPI3, if provided by your microcontroller const uint32_t QUARTZ_FREQUENCY = 16 * 1000 * 1000 ; // 16 MHz void setup () { Serial.begin (9600) ; while (!Serial) {} Serial.println ("Hello") ; ACAN2515Settings settings (QUARTZ_FREQUENCY, 125 * 1000) ; // 125 kbit/s settings.mRequestedMode = ACAN2515RequestedMode::LoopBackMode ; // Select loopback mode const uint16_t errorCode = can.begin (settings, [] { can.isr () ; }) ; if ( == errorCode) { Serial.println ("Can ok") ; }else{ Serial.print ("Error Can: 0x") ; Serial.println (errorCode, HEX) ; } }
Now, an example of the function. As we have selected loop back mode, every sent frame is received.
static uint32_t gSendDate = ; static uint32_t gSentCount = ; static uint32_t gReceivedCount = ; void loop () { CANMessage message ; if (gSendDate < millis ()) { message.id = 0x542 ; const bool ok = can.tryToSend (message) ; if (ok) { gSendDate += 2000 ; gSentCount += 1 ; Serial.print ("Sent: ") ; Serial.println (gSentCount) ; } } if (can.receive (message)) { gReceivedCount += 1 ; Serial.print ("Received: ") ; Serial.println (gReceivedCount) ; } }
is the class that defines a CAN message. The object is fully initialized by the default constructor. Here, we set the to for sending a standard data frame, without data, with this identifier.
The tries to send the message. It returns if the message has been sucessfully added to the driver transmit buffer.
The variable handles sending a CAN message every 2000 ms.
returns if a message has been received, and assigned to the argument.
Use of Optional Reception Filtering
The MCP2515 CAN Controller implements two acceptance masks and six acceptance filters. The driver API enables you to fully manage these registers.
For example ( sketch):
ACAN2515Settings settings (QUARTZ_FREQUENCY, 125 * 1000) ; settings.mRequestedMode = ACAN2515RequestedMode::LoopBackMode ; // Select loopback mode const ACAN2515Mask rxm0 = extended2515Mask (0x1FFFFFFF) ; // For filter #0 and #1 const ACAN2515Mask rxm1 = standard2515Mask (0x7F0, 0xFF, ) ; // For filter #2 to #5 const ACAN2515AcceptanceFilter filters [] = { {extended2515Filter (0x12345678), receive0}, {extended2515Filter (0x18765432), receive1}, {standard2515Filter (0x560, 0x55, ), receive2} } ; const uint16_t errorCode = can.begin (settings, [] { can.isr () ; }, rxm0, rxm1, filters, 3) ;
These settings enable the acceptance of extended frames whose identifier is 0x12345678 or 0x18765432, and data frames whose identifier is 0x560 and first data byte, if any, is 0x55.
The , , functions are call back functions, handled by the function:
void loop () { can.dispatchReceivedMessage () ; // Do not use can.receive any more ... }
Модельный ряд
Серия: MCP2515
MCP2515-E/ML MCP2515-E/MLVAO MCP2515-E/P MCP2515-E/PRB2 MCP2515-E/PRB4 MCP2515-E/SO MCP2515-E/SORB2 MCP2515-E/SORB4 MCP2515-E/SOVAO MCP2515-E/ST MCP2515-E/STRB2 MCP2515-E/STRB4 MCP2515-E/STVAO MCP2515-I/ML MCP2515-I/P MCP2515-I/PRB2 MCP2515-I/PRB4 MCP2515-I/SO MCP2515-I/SOGRB2 MCP2515-I/SORB2 MCP2515-I/SORB4 MCP2515-I/SOVAO MCP2515-I/ST MCP2515-I/STRB2 MCP2515-I/STRB4 MCP2515-I/STVAO MCP2515T-E/ML MCP2515T-E/MLVAO MCP2515T-E/SO MCP2515T-E/SORB2 MCP2515T-E/SORB4 MCP2515T-E/SOVAO MCP2515T-E/ST MCP2515T-E/STRB2 MCP2515T-E/STRB4 MCP2515T-E/STVAO MCP2515T-I/ML MCP2515T-I/SO MCP2515T-I/SORB2 MCP2515T-I/SORB4 MCP2515T-I/SOVAO MCP2515T-I/ST MCP2515T-I/STG MCP2515T-I/STRB2 MCP2515T-I/STRB4
(45)
4. Receive Data
The following function is used to receive data on the ‘receive’ node:
MCP2515::ERROR readMessage(const MCP2515::RXBn rxbn, struct can_frame *frame); MCP2515::ERROR readMessage(struct can_frame *frame);
In conditions that masks and filters have been set. This function can only get frames that meet the requirements of masks and filters.
You can choise one of two method to receive: interrupt-based and polling
Example of poll read
struct can_frame frame; void loop() { if (mcp2515.readMessage(&frame) == MCP2515::ERROR_OK) { // frame contains received message } }
Example of interrupt based read
bool interrupt = false; struct can_frame frame; void irqHandler() { interrupt = true; } void setup() { ... attachInterrupt(, irqHandler, FALLING); } void loop() { if (interrupt) { interrupt = false; uint8_t irq = mcp2515.getInterrupts(); if (irq & MCP2515::CANINTF_RX0IF) { if (mcp2515.readMessage(MCP2515::RXB0, &frame) == MCP2515::ERROR_OK) { // frame contains received from RXB0 message } } if (irq & MCP2515::CANINTF_RX1IF) { if (mcp2515.readMessage(MCP2515::RXB1, &frame) == MCP2515::ERROR_OK) { // frame contains received from RXB1 message } } } }
Receive Data
The following function is used to receive data on the ‘receive’ node:
MCP2515::ERROR readMessage(const MCP2515::RXBn rxbn, struct can_frame *frame); MCP2515::ERROR readMessage(struct can_frame *frame);
In conditions that masks and filters have been set. This function can only get frames that meet the requirements of masks and filters.
You can choise one of two method to receive: interrupt-based and polling
Example of poll read
struct can_frame frame; void loop() { if (mcp2515.readMessage(&frame) == MCP2515::ERROR_OK) { // frame contains received message } }
Example of interrupt based read
bool interrupt = false; struct can_frame frame; void irqHandler() { interrupt = true; } void setup() { ... attachInterrupt(, irqHandler, FALLING); } void loop() { if (interrupt) { interrupt = false; uint8_t irq = mcp2515.getInterrupts(); if (irq & MCP2515::CANINTF_RX0IF) { if (mcp2515.readMessage(MCP2515::RXB0, &frame) == MCP2515::ERROR_OK) { // frame contains received from RXB0 message } } if (irq & MCP2515::CANINTF_RX1IF) { if (mcp2515.readMessage(MCP2515::RXB1, &frame) == MCP2515::ERROR_OK) { // frame contains received from RXB1 message } } } }
6. Examples
Example implementation of CanHacker (lawicel) protocol based device: https://github.com/autowp/can-usb
Contributing to this software is warmly welcomed. You can do this basically byforking, committing modifications and then pulling requests (follow the links above
for operating guide). Adding change log and your contact into file header is encouraged.
Thanks for your contribution.
Seeed Studio is an open hardware facilitation company based in Shenzhen, China.
Benefiting from local manufacture power and convenient global logistic system,
we integrate resources to serve new era of innovation. Seeed also works with
global distributors and partners to push open hardware movement.
Datasheets
MCP2515Stand-Alone CAN Controller with SPI InterfaceFeatures Description Implements CAN V2.0B at 1 Mb/s:-0 to 8-byte length in the data field-Standard and extended data and remoteframes Receive Buffers, Masks and Filters:-Two receive buffers with prioritized messagestorage-Six 29-bit filters-Two 29-bit masks Data Byte Filtering on the First Two Data Bytes(applies to standard data frames) Three Transmit Buffers with Prioritization andAbort Features High-Speed SPI Interface (10 MHz):-SPI modes 0,0 and 1,1 One-Shot mode Ensures Message Transmissionis Attempted Only One Time Clock Out Pin with Programmable Prescaler:-Can be used as a clock source for otherdevice(s) Start-of-Frame (SOF) Signal is Available forMonitoring the SOF Signal:-Can be used for time slot-based protocolsand/or bus diagnostics to detect early busdegradation Interrupt Output Pin with Selectable Enables Buffer Full Output Pins Configurable as:-Interrupt output for each receive buffer-General purpose output Request-to-Send (RTS) Input Pins IndividuallyConfigurable as: …
1. Initialization
To create connection with MCP2515 provide pin number where SPI CS is connected (10 by default), baudrate and mode
The available modes are listed as follows:
mcp2515.setNormalMode(); mcp2515.setLoopbackMode(); mcp2515.setListenOnlyMode();
The available baudrates are listed as follows:
enum CAN_SPEED { CAN_5KBPS, CAN_10KBPS, CAN_20KBPS, 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_1000KBPS };
Example of initialization
MCP2515 mcp2515(10); mcp2515.reset(); mcp2515.setBitrate(CAN_125KBPS); mcp2515.setLoopbackMode();
mcp2515.setBitrate(CAN_125KBPS, MCP_8MHZ);
enum CAN_CLOCK { MCP_20MHZ, MCP_16MHZ, MCP_8MHZ };
Default value is MCP_16MHZ
Note: To transfer data on high speed of CAN interface via UART dont forget to update UART baudrate as necessary.
Set Receive Mask and Filter
There are 2 receive mask registers and 5 filter registers on the controller chip that guarantee you get data from the target device. They are useful especially in a large network consisting of numerous nodes.
We provide two functions for you to utilize these mask and filter registers. They are:
MCP2515::ERROR setFilterMask(const MASK mask, const bool ext, const uint32_t ulData) MCP2515::ERROR setFilter(const RXF num, const bool ext, const uint32_t ulData)
MASK mask represents one of two mask MCP2515::MASK0 or MCP2515::MASK1
RXF num represents one of six acceptance filters registers from MCP2515::RXF0 to MCP2515::RXF5
ext represents the status of the frame. false means it’s a mask or filter for a standard frame. true means it’s for a extended frame.
ulData represents the content of the mask of filter.
Модельный ряд
Серия: MCP2515
MCP2515-E/ML MCP2515-E/MLVAO MCP2515-E/P MCP2515-E/PRB2 MCP2515-E/PRB4 MCP2515-E/SO MCP2515-E/SORB2 MCP2515-E/SORB4 MCP2515-E/SOVAO MCP2515-E/ST MCP2515-E/STRB2 MCP2515-E/STRB4 MCP2515-E/STVAO MCP2515-I/ML MCP2515-I/P MCP2515-I/PRB2 MCP2515-I/PRB4 MCP2515-I/SO MCP2515-I/SOGRB2 MCP2515-I/SORB2 MCP2515-I/SORB4 MCP2515-I/SOVAO MCP2515-I/ST MCP2515-I/STRB2 MCP2515-I/STRB4 MCP2515-I/STVAO MCP2515T-E/ML MCP2515T-E/MLVAO MCP2515T-E/SO MCP2515T-E/SORB2 MCP2515T-E/SORB4 MCP2515T-E/SOVAO MCP2515T-E/ST MCP2515T-E/STRB2 MCP2515T-E/STRB4 MCP2515T-E/STVAO MCP2515T-I/ML MCP2515T-I/SO MCP2515T-I/SORB2 MCP2515T-I/SORB4 MCP2515T-I/SOVAO MCP2515T-I/ST MCP2515T-I/STG MCP2515T-I/STRB2 MCP2515T-I/STRB4
(45)
3. Send Data
MCP2515::ERROR sendMessage(const MCP2515::TXBn txbn, const struct can_frame *frame); MCP2515::ERROR sendMessage(const struct can_frame *frame);
This is a function to send data onto the bus.
For example, In the ‘send’ example, we have:
struct can_frame frame; frame.can_id = 0x000; frame.can_dlc = 4; frame.data[] = 0xFF; frame.data = 0xFF; frame.data = 0xFF; frame.data = 0xFF; /* send out the message to the bus and tell other devices this is a standard frame from 0x00. */ mcp2515.sendMessage(&frame);
struct can_frame frame; frame.can_id = 0x12345678 | CAN_EFF_MASK; frame.can_dlc = 2; frame.data[] = 0xFF; frame.data = 0xFF; /* send out the message to the bus using second TX buffer and tell other devices this is a extended frame from 0x12345678. */ mcp2515.sendMessage(MCP2515::TXB1, &frame);
Модельный ряд
Серия: MCP2515
MCP2515-E/ML MCP2515-E/MLVAO MCP2515-E/P MCP2515-E/PRB2 MCP2515-E/PRB4 MCP2515-E/SO MCP2515-E/SORB2 MCP2515-E/SORB4 MCP2515-E/SOVAO MCP2515-E/ST MCP2515-E/STRB2 MCP2515-E/STRB4 MCP2515-E/STVAO MCP2515-I/ML MCP2515-I/P MCP2515-I/PRB2 MCP2515-I/PRB4 MCP2515-I/SO MCP2515-I/SOGRB2 MCP2515-I/SORB2 MCP2515-I/SORB4 MCP2515-I/SOVAO MCP2515-I/ST MCP2515-I/STRB2 MCP2515-I/STRB4 MCP2515-I/STVAO MCP2515T-E/ML MCP2515T-E/MLVAO MCP2515T-E/SO MCP2515T-E/SORB2 MCP2515T-E/SORB4 MCP2515T-E/SOVAO MCP2515T-E/ST MCP2515T-E/STRB2 MCP2515T-E/STRB4 MCP2515T-E/STVAO MCP2515T-I/ML MCP2515T-I/SO MCP2515T-I/SORB2 MCP2515T-I/SORB4 MCP2515T-I/SOVAO MCP2515T-I/ST MCP2515T-I/STG MCP2515T-I/STRB2 MCP2515T-I/STRB4
(45)
Examples
Example implementation of CanHacker (lawicel) protocol based device: https://github.com/autowp/can-usb
Contributing to this software is warmly welcomed. You can do this basically byforking, committing modifications and then pulling requests (follow the links above
for operating guide). Adding change log and your contact into file header is encouraged.
Thanks for your contribution.
Seeed Studio is an open hardware facilitation company based in Shenzhen, China.
Benefiting from local manufacture power and convenient global logistic system,
we integrate resources to serve new era of innovation. Seeed also works with
global distributors and partners to push open hardware movement.
Экологический статус
MCP2515-E/ML | MCP2515-E/MLVAO | MCP2515-E/P | MCP2515-E/PRB2 | MCP2515-E/PRB4 | MCP2515-E/SO | MCP2515-E/SORB2 | MCP2515-E/SORB4 | MCP2515-E/SOVAO | MCP2515-E/ST | MCP2515-E/STRB2 | MCP2515-E/STRB4 | MCP2515-E/STVAO | MCP2515-I/ML | MCP2515-I/P | MCP2515-I/PRB2 | MCP2515-I/PRB4 | MCP2515-I/SO | MCP2515-I/SOGRB2 | MCP2515-I/SORB2 | MCP2515-I/SORB4 | MCP2515-I/SOVAO | MCP2515-I/ST | MCP2515-I/STRB2 | MCP2515-I/STRB4 | MCP2515-I/STVAO | MCP2515T-E/ML | MCP2515T-E/MLVAO | MCP2515T-E/SO | MCP2515T-E/SORB2 | MCP2515T-E/SORB4 | MCP2515T-E/SOVAO | MCP2515T-E/ST | MCP2515T-E/STRB2 | MCP2515T-E/STRB4 | MCP2515T-E/STVAO | MCP2515T-I/ML | MCP2515T-I/SO | MCP2515T-I/SORB2 | MCP2515T-I/SORB4 | MCP2515T-I/SOVAO | MCP2515T-I/ST | MCP2515T-I/STG | MCP2515T-I/STRB2 | MCP2515T-I/STRB4 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
RoHS | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим | Совместим |
Datasheets
MCP2515Stand-Alone CAN Controller with SPI InterfaceFeatures Description Implements CAN V2.0B at 1 Mb/s:-0 to 8-byte length in the data field-Standard and extended data and remoteframes Receive Buffers, Masks and Filters:-Two receive buffers with prioritized messagestorage-Six 29-bit filters-Two 29-bit masks Data Byte Filtering on the First Two Data Bytes(applies to standard data frames) Three Transmit Buffers with Prioritization andAbort Features High-Speed SPI Interface (10 MHz):-SPI modes 0,0 and 1,1 One-Shot mode Ensures Message Transmissionis Attempted Only One Time Clock Out Pin with Programmable Prescaler:-Can be used as a clock source for otherdevice(s) Start-of-Frame (SOF) Signal is Available forMonitoring the SOF Signal:-Can be used for time slot-based protocolsand/or bus diagnostics to detect early busdegradation Interrupt Output Pin with Selectable Enables Buffer Full Output Pins Configurable as:-Interrupt output for each receive buffer-General purpose output Request-to-Send (RTS) Input Pins IndividuallyConfigurable as: …
Datasheets
MCP2515Stand-Alone CAN Controller with SPI InterfaceFeatures Description Implements CAN V2.0B at 1 Mb/s:-0 to 8-byte length in the data field-Standard and extended data and remoteframes Receive Buffers, Masks and Filters:-Two receive buffers with prioritized messagestorage-Six 29-bit filters-Two 29-bit masks Data Byte Filtering on the First Two Data Bytes(applies to standard data frames) Three Transmit Buffers with Prioritization andAbort Features High-Speed SPI Interface (10 MHz):-SPI modes 0,0 and 1,1 One-Shot mode Ensures Message Transmissionis Attempted Only One Time Clock Out Pin with Programmable Prescaler:-Can be used as a clock source for otherdevice(s) Start-of-Frame (SOF) Signal is Available forMonitoring the SOF Signal:-Can be used for time slot-based protocolsand/or bus diagnostics to detect early busdegradation Interrupt Output Pin with Selectable Enables Buffer Full Output Pins Configurable as:-Interrupt output for each receive buffer-General purpose output Request-to-Send (RTS) Input Pins IndividuallyConfigurable as: …
Корпус / Упаковка / Маркировка
MCP2515-E/ML | MCP2515-E/MLVAO | MCP2515-E/P | MCP2515-E/PRB2 | MCP2515-E/PRB4 | MCP2515-E/SO | MCP2515-E/SORB2 | MCP2515-E/SORB4 | MCP2515-E/SOVAO | MCP2515-E/ST | MCP2515-E/STRB2 | MCP2515-E/STRB4 | MCP2515-E/STVAO | MCP2515-I/ML | MCP2515-I/P | MCP2515-I/PRB2 | MCP2515-I/PRB4 | MCP2515-I/SO | MCP2515-I/SOGRB2 | MCP2515-I/SORB2 | MCP2515-I/SORB4 | MCP2515-I/SOVAO | MCP2515-I/ST | MCP2515-I/STRB2 | MCP2515-I/STRB4 | MCP2515-I/STVAO | MCP2515T-E/ML | MCP2515T-E/MLVAO | MCP2515T-E/SO | MCP2515T-E/SORB2 | MCP2515T-E/SORB4 | MCP2515T-E/SOVAO | MCP2515T-E/ST | MCP2515T-E/STRB2 | MCP2515T-E/STRB4 | MCP2515T-E/STVAO | MCP2515T-I/ML | MCP2515T-I/SO | MCP2515T-I/SORB2 | MCP2515T-I/SORB4 | MCP2515T-I/SOVAO | MCP2515T-I/ST | MCP2515T-I/STG | MCP2515T-I/STRB2 | MCP2515T-I/STRB4 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Корпус | QFN | QFN | PDIP | PDIP | PDIP | SOIC | SOIC | SOIC | SOIC | TSSOP | TSSOP | TSSOP | TSSOP | QFN | PDIP | PDIP | PDIP | SOIC | SOIC | SOIC | SOIC | SOIC | TSSOP | TSSOP | TSSOP | TSSOP | QFN | QFN | SOIC | SOIC | SOIC | SOIC | TSSOP | TSSOP | TSSOP | TSSOP | QFN | SOIC | SOIC | SOIC | SOIC | TSSOP | TSSOP | TSSOP | TSSOP |
Количество выводов | 20 | 20 | 18 | 18 | 18 | 18 | 18 | 18 | 18 | 20 | 20 | 20 | 20 | 20 | 18 | 18 | 18 | 18 | 18 | 18 | 18 | 18 | 20 | 20 | 20 | 20 | 20 | 20 | 18 | 18 | 18 | 18 | 20 | 20 | 20 | 20 | 20 | 18 | 18 | 18 | 18 | 20 | 20 | 20 | 20 |
1. Initialization
To create connection with MCP2515 provide pin number where SPI CS is connected (10 by default), baudrate and mode
The available modes are listed as follows:
mcp2515.setNormalMode(); mcp2515.setLoopbackMode(); mcp2515.setListenOnlyMode();
The available baudrates are listed as follows:
enum CAN_SPEED { CAN_5KBPS, CAN_10KBPS, CAN_20KBPS, 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_1000KBPS };
Example of initialization
MCP2515 mcp2515(10); mcp2515.reset(); mcp2515.setBitrate(CAN_125KBPS); mcp2515.setLoopbackMode();
mcp2515.setBitrate(CAN_125KBPS, MCP_8MHZ);
enum CAN_CLOCK { MCP_20MHZ, MCP_16MHZ, MCP_8MHZ };
Default value is MCP_16MHZ
Note: To transfer data on high speed of CAN interface via UART dont forget to update UART baudrate as necessary.
Initialization
To create connection with MCP2515 provide pin number where SPI CS is connected (10 by default), baudrate and mode
The available modes are listed as follows:
mcp2515.setNormalMode(); mcp2515.setLoopbackMode(); mcp2515.setListenOnlyMode();
The available baudrates are listed as follows:
enum CAN_SPEED { CAN_5KBPS, CAN_10KBPS, CAN_20KBPS, 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_1000KBPS };
Example of initialization
MCP2515 mcp2515(10); mcp2515.reset(); mcp2515.setBitrate(CAN_125KBPS); mcp2515.setLoopbackMode();
mcp2515.setBitrate(CAN_125KBPS, MCP_8MHZ);
enum CAN_CLOCK { MCP_20MHZ, MCP_16MHZ, MCP_8MHZ };
Default value is MCP_16MHZ
Note: To transfer data on high speed of CAN interface via UART dont forget to update UART baudrate as necessary.
Datasheets
MCP2515Stand-Alone CAN Controller with SPI InterfaceFeatures Description Implements CAN V2.0B at 1 Mb/s:-0 to 8-byte length in the data field-Standard and extended data and remoteframes Receive Buffers, Masks and Filters:-Two receive buffers with prioritized messagestorage-Six 29-bit filters-Two 29-bit masks Data Byte Filtering on the First Two Data Bytes(applies to standard data frames) Three Transmit Buffers with Prioritization andAbort Features High-Speed SPI Interface (10 MHz):-SPI modes 0,0 and 1,1 One-Shot mode Ensures Message Transmissionis Attempted Only One Time Clock Out Pin with Programmable Prescaler:-Can be used as a clock source for otherdevice(s) Start-of-Frame (SOF) Signal is Available forMonitoring the SOF Signal:-Can be used for time slot-based protocolsand/or bus diagnostics to detect early busdegradation Interrupt Output Pin with Selectable Enables Buffer Full Output Pins Configurable as:-Interrupt output for each receive buffer-General purpose output Request-to-Send (RTS) Input Pins IndividuallyConfigurable as: …
Datasheets
MCP2515Stand-Alone CAN Controller with SPI InterfaceFeatures Description Implements CAN V2.0B at 1 Mb/s:-0 to 8-byte length in the data field-Standard and extended data and remoteframes Receive Buffers, Masks and Filters:-Two receive buffers with prioritized messagestorage-Six 29-bit filters-Two 29-bit masks Data Byte Filtering on the First Two Data Bytes(applies to standard data frames) Three Transmit Buffers with Prioritization andAbort Features High-Speed SPI Interface (10 MHz):-SPI modes 0,0 and 1,1 One-Shot mode Ensures Message Transmissionis Attempted Only One Time Clock Out Pin with Programmable Prescaler:-Can be used as a clock source for otherdevice(s) Start-of-Frame (SOF) Signal is Available forMonitoring the SOF Signal:-Can be used for time slot-based protocolsand/or bus diagnostics to detect early busdegradation Interrupt Output Pin with Selectable Enables Buffer Full Output Pins Configurable as:-Interrupt output for each receive buffer-General purpose output Request-to-Send (RTS) Input Pins IndividuallyConfigurable as: …
5. Set Receive Mask and Filter
There are 2 receive mask registers and 5 filter registers on the controller chip that guarantee you get data from the target device. They are useful especially in a large network consisting of numerous nodes.
We provide two functions for you to utilize these mask and filter registers. They are:
MCP2515::ERROR setFilterMask(const MASK mask, const bool ext, const uint32_t ulData) MCP2515::ERROR setFilter(const RXF num, const bool ext, const uint32_t ulData)
MASK mask represents one of two mask MCP2515::MASK0 or MCP2515::MASK1
RXF num represents one of six acceptance filters registers from MCP2515::RXF0 to MCP2515::RXF5
ext represents the status of the frame. false means it’s a mask or filter for a standard frame. true means it’s for a extended frame.
ulData represents the content of the mask of filter.