nanoFramework.Iot.Device.Mcp25xxx 1.2.907

Prefix Reserved
dotnet add package nanoFramework.Iot.Device.Mcp25xxx --version 1.2.907
                    
NuGet\Install-Package nanoFramework.Iot.Device.Mcp25xxx -Version 1.2.907
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nanoFramework.Iot.Device.Mcp25xxx" Version="1.2.907" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.Iot.Device.Mcp25xxx" Version="1.2.907" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.Iot.Device.Mcp25xxx" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add nanoFramework.Iot.Device.Mcp25xxx --version 1.2.907
                    
#r "nuget: nanoFramework.Iot.Device.Mcp25xxx, 1.2.907"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package nanoFramework.Iot.Device.Mcp25xxx@1.2.907
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=nanoFramework.Iot.Device.Mcp25xxx&version=1.2.907
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.Mcp25xxx&version=1.2.907
                    
Install as a Cake Tool

Mcp25xxx/MCP2515/MCP2565 device family - CAN bus

This binding is currently not finished. Please consider contributing to help us finish it.

The MCP25XXX is a stand-alone CAN controller and includes features like faster throughput, databyte filtering, and support for time-triggered protocols.

Documentation

MCP25XXX devices contain different markings to distinguish features like interfacing, packaging, and temperature ratings. For example, MCP25625 contains a CAN transceiver. Please review specific datasheet for more information.

Usage

Important: make sure you properly setup the SPI pins especially for ESP32 before creating the SpiDevice, make sure you install the nanoFramework.Hardware.ESP32 nuget:

//////////////////////////////////////////////////////////////////////
// when connecting to an ESP32 device, need to configure the SPI GPIOs
// used for the bus
Configuration.SetPinFunction(21, DeviceFunction.SPI1_MOSI);
Configuration.SetPinFunction(22, DeviceFunction.SPI1_MISO);
Configuration.SetPinFunction(23, DeviceFunction.SPI1_CLOCK);
// Make sure as well you are using the right chip select

For other devices like STM32, please make sure you're using the preset pins for the SPI bus you want to use. The chip select can as well be pre setup.

You can create a Mcp25625 device like this:

SpiConnectionSettings spiConnectionSettings = new(1, 42);
SpiDevice spiDevice = SpiDevice.Create(spiConnectionSettings);
Mcp25625 mcp25xxx = new Mcp25625(spiDevice);

Read all the registers

You can read all the registers like this:

Debug.WriteLine("Read Instruction for All Registers");
Array addresses = Enum.GetValues(typeof(Address));

foreach (Address address in addresses)
{
    byte addressData = mcp25xxx.Read(address);
    Debug.WriteLine($"0x{(byte)address:X2} - {address,-10}: 0x{addressData:X2}");
}

to read a single register, just use the Address enum.

RX Status

The RX status is available like this:

Debug.WriteLine("Rx Status Instruction");
RxStatusResponse rxStatusResponse = mcp25xxx.RxStatus();
Debug.WriteLine($"Value: 0x{rxStatusResponse.ToByte():X2}");
Debug.WriteLine($"Filter Match: {rxStatusResponse.FilterMatch}");
Debug.WriteLine($"Message Type Received: {rxStatusResponse.MessageTypeReceived}");
Debug.WriteLine($"Received Message: {rxStatusResponse.ReceivedMessage}");

Read Status

The Read status is available like this:

Debug.WriteLine("Read Status Instruction");
ReadStatusResponse readStatusResponse = mcp25xxx.ReadStatus();
Debug.WriteLine($"Value: 0x{readStatusResponse:X2}");
Debug.WriteLine($"Rx0If: {readStatusResponse.HasFlag(ReadStatusResponse.Rx0If)}");
Debug.WriteLine($"Rx1If: {readStatusResponse.HasFlag(ReadStatusResponse.Rx1If)}");
Debug.WriteLine($"Tx0Req: {readStatusResponse.HasFlag(ReadStatusResponse.Tx0Req)}");
Debug.WriteLine($"Tx0If: {readStatusResponse.HasFlag(ReadStatusResponse.Tx0If)}");
Debug.WriteLine($"Tx0Req: {readStatusResponse.HasFlag(ReadStatusResponse.Tx0Req)}");
Debug.WriteLine($"Tx1If: {readStatusResponse.HasFlag(ReadStatusResponse.Tx1If)}");
Debug.WriteLine($"Tx1Req: {readStatusResponse.HasFlag(ReadStatusResponse.Tx1Req)}");
Debug.WriteLine($"Tx2Req: {readStatusResponse.HasFlag(ReadStatusResponse.Tx2Req)}");
Debug.WriteLine($"Tx2If: {readStatusResponse.HasFlag(ReadStatusResponse.Tx2If)}");

Transmit a message

You can transmit a message like this:

Debug.WriteLine("Transmit Message");

mcp25xxx.WriteByte(
    new CanCtrl(CanCtrl.PinPrescaler.ClockDivideBy8,
        false,
        false,
        false,
        OperationMode.NormalOperation));

byte[] data = new byte[] { 0b0000_0001, 0b0010_0011, 0b0100_0101, 0b0110_0111, 0b1000_1001 };

mcp25xxx.Write(
    Address.TxB0Sidh,
    new byte[]
    {
        new TxBxSidh(0, 0b0000_1001).ToByte(), new TxBxSidl(0, 0b001, false, 0b00).ToByte(),
        new TxBxEid8(0, 0b0000_0000).ToByte(), new TxBxEid0(0, 0b0000_0000).ToByte(),
        new TxBxDlc(0, data.Length, false).ToByte()
    });

mcp25xxx.Write(Address.TxB0D0, data);

// Send with TxB0 buffer.
mcp25xxx.RequestToSend(true, false, false);
cp25xxx.RequestToSend(false, false, true);

Note: You will find detailed way of using this binding in the sample file

Binding Notes

More details will be added in future PR once core CAN classes/interfaces are determined.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.907 174 10/2/2025
1.2.864 264 4/2/2025
1.2.852 251 3/11/2025
1.2.822 189 2/26/2025
1.2.775 197 2/4/2025
1.2.772 202 2/4/2025
1.2.755 208 1/31/2025
1.2.737 145 1/13/2025
1.2.696 190 12/16/2024
1.2.673 210 10/23/2024
1.2.631 194 8/28/2024
1.2.570 212 6/14/2024
1.2.560 199 5/29/2024
1.2.548 200 5/15/2024
1.2.436 309 11/10/2023
1.2.329 272 5/26/2023
1.2.316 256 5/16/2023
1.2.313 257 5/12/2023
1.2.297 273 5/3/2023
1.2.203 431 12/28/2022
1.2.141 522 10/25/2022
1.2.122 529 10/12/2022
1.2.114 495 10/8/2022
1.2.95 520 9/22/2022
1.2.87 589 9/15/2022
1.2.73 528 9/8/2022
1.2.5 569 7/13/2022
1.1.141.41205 543 7/6/2022
1.1.113.2032 558 6/23/2022
1.1.27 577 4/26/2022
1.1.20 562 4/21/2022
1.1.1 555 4/14/2022
1.0.300 563 3/31/2022
1.0.277-preview.125 210 3/25/2022
1.0.277-preview.110 210 3/18/2022
1.0.277-preview.105 220 3/15/2022
1.0.277-preview.98 214 3/8/2022
1.0.277-preview.85 221 2/25/2022
1.0.277-preview.77 209 2/18/2022
1.0.277-preview.60 234 2/4/2022
1.0.277-preview.41 233 1/28/2022
1.0.277-preview.32 229 1/27/2022
1.0.277-preview.17 225 1/24/2022
1.0.277-preview.13 231 1/21/2022
1.0.277-preview.1 229 1/11/2022
1.0.259 445 12/9/2021
1.0.221 271 10/19/2021
1.0.219 277 10/19/2021
1.0.218 301 10/18/2021
1.0.207 292 10/11/2021
1.0.155 279 8/31/2021
1.0.136 351 7/17/2021
1.0.135 274 7/16/2021
1.0.134 278 7/15/2021
1.0.133 301 7/14/2021
1.0.129 269 7/6/2021
1.0.125 311 7/5/2021
1.0.121 305 6/29/2021
1.0.119 342 6/28/2021
1.0.105 280 5/29/2021
1.0.46 306 5/24/2021