From 3cd8d8ea9baa0b40ff74ac11980306b126498767 Mon Sep 17 00:00:00 2001 From: Rikkert01 Date: Thu, 30 Jan 2025 14:37:29 +0100 Subject: [PATCH 1/7] werkt nu --- devices/Mcp25xxx/Mcp25xxx.cs | 21 +++++++++++++++ devices/Mcp25xxx/Mcp25xxx.nfproj | 3 +++ .../Mcp25xxx/Register/Interrupt/CanIntF.cs | 4 +-- .../Mcp25xxx/samples/Mcp25xxx.Samples.nfproj | 6 +++++ devices/Mcp25xxx/samples/Program.cs | 26 ++++++++++++------- devices/Mcp25xxx/samples/packages.config | 1 + devices/Mcp25xxx/samples/packages.lock.json | 6 +++++ 7 files changed, 55 insertions(+), 12 deletions(-) diff --git a/devices/Mcp25xxx/Mcp25xxx.cs b/devices/Mcp25xxx/Mcp25xxx.cs index 67582851d0..add38d9ccf 100644 --- a/devices/Mcp25xxx/Mcp25xxx.cs +++ b/devices/Mcp25xxx/Mcp25xxx.cs @@ -451,5 +451,26 @@ public void Dispose() _spiDevice?.Dispose(); _spiDevice = null!; } + + public byte[] ReadRegister(Address register, byte length = 1) + { + SpanByte writeBuffer = new byte[2 + length]; + writeBuffer[0] = (byte)InstructionFormat.Read; + writeBuffer[1] = (byte)register; + + SpanByte readBuffer = new byte[2 + length]; + _spiDevice.TransferFullDuplex(writeBuffer, readBuffer); + return readBuffer.Slice(2).ToArray(); + + //Span tx = stackalloc byte[2 + length]; + //Span rx = stackalloc byte[2 + length]; + + //tx[0] = (byte)Command.Read; + //tx[1] = (byte)register; + + //SpiBus.Exchange(ChipSelect, tx, rx); + + //return rx.Slice(2).ToArray(); + } } } diff --git a/devices/Mcp25xxx/Mcp25xxx.nfproj b/devices/Mcp25xxx/Mcp25xxx.nfproj index dafbece8ef..98b2221313 100644 --- a/devices/Mcp25xxx/Mcp25xxx.nfproj +++ b/devices/Mcp25xxx/Mcp25xxx.nfproj @@ -60,6 +60,9 @@ + + + diff --git a/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs b/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs index 2700c4ec84..d129cc3944 100644 --- a/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs +++ b/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs @@ -92,14 +92,14 @@ public CanIntF(byte value) /// True = Interrupt pending (must be cleared by MCU to reset interrupt condition). /// False = No interrupt pending. /// - public bool ReceiveBuffer0FullInterruptFlag { get; } + public bool ReceiveBuffer0FullInterruptFlag { get; set; } /// /// RX1IF: Receive Buffer 1 Full Interrupt Flag bit. /// True = Interrupt pending (must be cleared by MCU to reset interrupt condition). /// False = No interrupt pending. /// - public bool ReceiveBuffer1FullInterruptFlag { get; } + public bool ReceiveBuffer1FullInterruptFlag { get; set; } /// /// TX0IF: Transmit Buffer 0 Empty Interrupt Flag bit. diff --git a/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj b/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj index b25fd6cfed..6680826147 100644 --- a/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj +++ b/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj @@ -23,6 +23,9 @@ ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + + ..\packages\nanoFramework.Hardware.Esp32.1.6.23\lib\nanoFramework.Hardware.Esp32.dll + ..\packages\nanoFramework.Runtime.Events.1.11.18\lib\nanoFramework.Runtime.Events.dll @@ -45,6 +48,9 @@ + + + diff --git a/devices/Mcp25xxx/samples/Program.cs b/devices/Mcp25xxx/samples/Program.cs index ef30d2bbb4..885cf5d138 100644 --- a/devices/Mcp25xxx/samples/Program.cs +++ b/devices/Mcp25xxx/samples/Program.cs @@ -14,6 +14,7 @@ using Iot.Device.Mcp25xxx.Register.MessageReceive; using Iot.Device.Mcp25xxx.Register.MessageTransmit; using System.Diagnostics; +using nanoFramework.Hardware.Esp32; Debug.WriteLine("Hello Mcp25xxx Sample!"); @@ -21,9 +22,9 @@ Reset(mcp25xxx); // ReadAllRegisters(mcp25xxx); -ReadAllRegistersWithDetails(mcp25xxx); + ReadAllRegistersWithDetails(mcp25xxx); // ReadRxBuffer(mcp25xxx); -// Write(mcp25xxx); +//Write(mcp25xxx); // LoadTxBuffer(mcp25xxx); // RequestToSend(mcp25xxx); // ReadStatus(mcp25xxx); @@ -38,13 +39,13 @@ Mcp25xxx GetMcp25xxxDevice() ////////////////////////////////////////////////////////////////////// // 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(22, DeviceFunction.SPI1_CLOCK); + Configuration.SetPinFunction(25, DeviceFunction.SPI1_MOSI); // GPIO25 = SI (MOSI) + Configuration.SetPinFunction(26, DeviceFunction.SPI1_MISO); // GPIO26 = SO (MISO) + Configuration.SetPinFunction(33, DeviceFunction.SPI1_CLOCK); // GPIO33 = SCK (Clock) // Make sure as well you are using the right chip select - SpiConnectionSettings spiConnectionSettings = new(1, 42); + SpiConnectionSettings spiConnectionSettings = new(1, 27); // GPIO27 = CS (Chip Select) SpiDevice spiDevice = SpiDevice.Create(spiConnectionSettings); - return new Mcp25625(spiDevice); + return new Mcp2515(spiDevice); } void Reset(Mcp25xxx mcp25xxx) @@ -73,13 +74,13 @@ void ReadAllRegistersWithDetails(Mcp25xxx mcp25xxx) Debug.WriteLine("Read All Registers"); Debug.WriteLine(""); - ReadAllMessageTransmitRegistersWithDetails(mcp25xxx); + // ReadAllMessageTransmitRegistersWithDetails(mcp25xxx); // ReadAllMessageReceiveRegistersWithDetails(mcp25xxx); - // ReadAllAcceptanceFilterRegistersWithDetails(mcp25xxx); + ReadAllAcceptanceFilterRegistersWithDetails(mcp25xxx); // ReadAllBitTimeConfigurationRegistersWithDetails(mcp25xxx); // ReadAllErrorDetectionRegistersWithDetails(mcp25xxx); // ReadAllInterruptRegistersWithDetails(mcp25xxx); - // ReadAllCanControlRegistersWithDetails(mcp25xxx); + ReadAllCanControlRegistersWithDetails(mcp25xxx); } byte ConsoleWriteRegisterAddressDetails(Mcp25xxx mcp25xxx, Address address) @@ -327,6 +328,11 @@ void ReadAllCanControlRegistersWithDetails(Mcp25xxx mcp25xxx) ConsoleWriteRegisterItemDetails(new CanCtrl(ConsoleWriteRegisterAddressDetails(mcp25xxx, Address.CanCtrl))); ConsoleWriteRegisterItemDetails(new CanStat(ConsoleWriteRegisterAddressDetails(mcp25xxx, Address.CanStat))); + + var canStat = new CanStat(mcp25xxx.Read(Address.CanStat)); + Debug.WriteLine($" OPMOD: {canStat.OperationMode}"); + Debug.WriteLine($" ICOD: {canStat.InterruptFlagCode}"); + } void ReadRxBuffer(Mcp25xxx mcp25xxx) diff --git a/devices/Mcp25xxx/samples/packages.config b/devices/Mcp25xxx/samples/packages.config index 4fbd05f8de..c5181100f9 100644 --- a/devices/Mcp25xxx/samples/packages.config +++ b/devices/Mcp25xxx/samples/packages.config @@ -1,6 +1,7 @@  + diff --git a/devices/Mcp25xxx/samples/packages.lock.json b/devices/Mcp25xxx/samples/packages.lock.json index 22094432d5..4d2900e458 100644 --- a/devices/Mcp25xxx/samples/packages.lock.json +++ b/devices/Mcp25xxx/samples/packages.lock.json @@ -8,6 +8,12 @@ "resolved": "1.15.5", "contentHash": "u2+GvAp1uxLrGdILACAZy+EVKOs28EQ52j8Lz7599egXZ3GBGejjnR2ofhjMQwzrJLlgtyrsx8nSLngDfJNsAg==" }, + "nanoFramework.Hardware.Esp32": { + "type": "Direct", + "requested": "[1.6.23, 1.6.23]", + "resolved": "1.6.23", + "contentHash": "rgNByDk4jttssYlXAhDpgt0IWYoUNbyDSQjy7xV7tG+z8dTt7IjA5ehe42028Umwoe6ksHm8mRDfFsITotbNiA==" + }, "nanoFramework.Runtime.Events": { "type": "Direct", "requested": "[1.11.18, 1.11.18]", From 554a573cd73c49ab677b6978713cb45521bb97ae Mon Sep 17 00:00:00 2001 From: Rikkert01 Date: Sat, 8 Feb 2025 14:52:55 +0100 Subject: [PATCH 2/7] Added a CanController --- devices/Mcp25xxx/Can/CanController.cs | 395 ++++++++++++++++++++ devices/Mcp25xxx/Can/CanEnums.cs | 35 ++ devices/Mcp25xxx/Can/CanMessage.cs | 73 ++++ devices/Mcp25xxx/Can/CanMessageFrameType.cs | 21 ++ devices/Mcp25xxx/Can/CanMessageIdType.cs | 21 ++ devices/Mcp25xxx/Can/ICanController.cs | 14 + devices/Mcp25xxx/Mcp25xxx.cs | 38 +- devices/Mcp25xxx/Mcp25xxx.nfproj | 6 + 8 files changed, 582 insertions(+), 21 deletions(-) create mode 100644 devices/Mcp25xxx/Can/CanController.cs create mode 100644 devices/Mcp25xxx/Can/CanEnums.cs create mode 100644 devices/Mcp25xxx/Can/CanMessage.cs create mode 100644 devices/Mcp25xxx/Can/CanMessageFrameType.cs create mode 100644 devices/Mcp25xxx/Can/CanMessageIdType.cs create mode 100644 devices/Mcp25xxx/Can/ICanController.cs diff --git a/devices/Mcp25xxx/Can/CanController.cs b/devices/Mcp25xxx/Can/CanController.cs new file mode 100644 index 0000000000..f3b3b2c213 --- /dev/null +++ b/devices/Mcp25xxx/Can/CanController.cs @@ -0,0 +1,395 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Iot.Device.Mcp25xxx.Register; +using Iot.Device.Mcp25xxx.Register.CanControl; +using Iot.Device.Mcp25xxx.Register.Interrupt; +using Iot.Device.Mcp25xxx.Tests.Register.CanControl; +using System; +using System.Diagnostics; +using System.Threading; + +namespace Iot.Device.Mcp25xxx.Can +{ + /// + /// Represents a CAN controller on the system. + /// + public class CanController : ICanController + { + byte MCP_SIDH = 0; + byte MCP_SIDL = 1; + byte MCP_EID8 = 2; + byte MCP_EID0 = 3; + byte MCP_DLC = 4; + byte DLC_MASK = 0x0F; + byte TXB_EXIDE_MASK = 0x08; + + private Mcp25xxx _mcp25xxx; + + /// + /// + /// + /// + public void Initialize(Mcp25xxx mcp25xxx) + { + _mcp25xxx = mcp25xxx; + } + + /// + /// Write message to CAN Bus. + /// + /// CAN mesage to write in CAN Bus. + public void WriteMessage(CanMessage message) + { + + } + + /// + /// Get next available in the _ internal buffer. + /// If there are no more messages available null will be returned. + /// + /// + /// A or null if there are no more messages available. + /// + public CanMessage GetMessage() + { + var status = _mcp25xxx.ReadStatus(); + + if (status.HasFlag(ReadStatusResponse.Rx0If)) + { // message in buffer 0 + return ReadDataMessage(0); + } + else if (status.HasFlag(ReadStatusResponse.Rx1If)) + { // message in buffer 1 + return ReadDataMessage(1); + } + else + { // no messages available + return null; + } + } + + /// + /// Clear all receive buffers. + /// + public void Reset() + { + Debug.WriteLine("Reset Instruction"); + _mcp25xxx.Reset(); + + Thread.Sleep(10); + + // Clear control buffers + byte[] data14 = new byte[14]; + _mcp25xxx.Write(Address.TxB0Ctrl, data14); + _mcp25xxx.Write(Address.TxB1Ctrl, data14); + _mcp25xxx.Write(Address.TxB2Ctrl, data14); + + _mcp25xxx.WriteByte(Address.RxB0Ctrl, 0); + _mcp25xxx.WriteByte(Address.RxB1Ctrl, 0); + + + _mcp25xxx.WriteByte(Address.CanIntE, (byte)(InterruptEnable.RXB0 | InterruptEnable.RXB1 | InterruptEnable.ERR | InterruptEnable.MSG_ERR)); + + // receives all valid messages using either Standard or Extended Identifiers that + // meet filter criteria. RXF0 is applied for RXB0, RXF1 is applied for RXB1 + _mcp25xxx.BitModify(Address.RxB0Ctrl, + 0x60 | 0x04 | 0x07, // moet die laatste niet 0x03 zijn? Geprobeerd maar doet niets.. + 0x00 | 0x04 | 0x00); + _mcp25xxx.BitModify(Address.RxB1Ctrl, + 0x60 | 0x07, + 0x00 | 0x01); + + // clear filters and masks + // do not filter any standard frames for RXF0 used by RXB0 + // do not filter any extended frames for RXF1 used by RXB1 + byte[] zeros12 = new byte[12]; + _mcp25xxx.Write(Address.RxF0Sidh, zeros12); + _mcp25xxx.Write(Address.RxF3Sidh, zeros12); + + byte[] zeros8 = new byte[8]; + _mcp25xxx.Write(Address.RxM0Sidh, zeros8); + } + + private CanMessage ReadDataMessage(int bufferNumber) + { + var sidh_reg = bufferNumber == 0 ? Address.RxB0Sidh : Address.RxB1Sidh; + var sidl_reg = bufferNumber == 0 ? Address.RxB0Sidl : Address.RxB1Sidl; + + var dlc_reg = bufferNumber == 0 ? Address.RxB0Dlc : Address.RxB1Dlc; + + + var ctrl_reg = bufferNumber == 0 ? Address.RxB0Ctrl : Address.RxB1Ctrl; + var data_reg = bufferNumber == 0 ? Address.RxB0D0 : Address.RxB1D0; //.RXB0DATA RXB1DATA + var int_flag = bufferNumber == 0 ? ReadStatusResponse.Rx0If : ReadStatusResponse.Rx1If; + + // read 5 bytes + var buffer = _mcp25xxx.Read(sidh_reg, 5); + + int id = (buffer[MCP_SIDH] << 3) + (buffer[MCP_SIDL] >> 5); + + bool isExtended = false; + + // check to see if it's an extended ID + if ((buffer[MCP_SIDL] & TXB_EXIDE_MASK) == TXB_EXIDE_MASK) + { + id = (id << 2) + (buffer[MCP_SIDL] & 0x03); + id = (id << 8) + buffer[MCP_EID8]; + id = (id << 8) + buffer[MCP_EID0]; + isExtended = true; + } + + byte dataLengthCode = (byte)(buffer[MCP_DLC] & DLC_MASK); + if (dataLengthCode > 8) throw new Exception($"DLC of {dataLengthCode} is > 8 bytes"); + + // see if it's a remote transmission request + //var isRemoteTransmitRequest = false; + //var ctrl = ReadRegister(ctrl_reg)[0]; + //if ((ctrl & RXBnCTRL_RTR) == RXBnCTRL_RTR) + //{ + // isRemoteTransmitRequest = true; + //} + + // create the CANMessag + CanMessage frame; + + if (isExtended) + { + //if (isRemoteTransmitRequest) + //{ + // frame = new ExtendedRtrFrame + // { + // ID = id, + // }; + //} + //else + //{ + frame = new CanMessage((uint)id, + CanMessageIdType.EID, + CanMessageFrameType.Data, + _mcp25xxx.Read(data_reg, dataLengthCode)); + + //} + } + else + { + //if (isRemoteTransmitRequest) + //{ + // frame = new StandardRtrFrame + // { + // ID = id, + // }; + //} + //else + //{ + frame = new CanMessage((uint)id, + CanMessageIdType.SID, + CanMessageFrameType.Data, + _mcp25xxx.Read(data_reg, dataLengthCode)); + + // read the frame data + //} + //} + + + } + // clear the interrupt flag + //if (InterruptPort != null) + //{ + //ClearInterrupt(int_flag); + ClearInterrupt(bufferNumber); // int_flag); + + return frame; + } + + private void ClearInterrupt(int bufferNumber) + { + var canIntf = new CanIntF(_mcp25xxx.Read(Address.CanIntF)); + if (bufferNumber == 0) + { + canIntf.ReceiveBuffer0FullInterruptFlag = false; + } + else + { + canIntf.ReceiveBuffer1FullInterruptFlag = false; + } + + // Write the modified value back to the CanCtrl register + _mcp25xxx.WriteByte(canIntf); + } + + class Config + { + public long ClockFrequency { get; set; } + public long BaudRate { get; set; } + public byte[] Cnf { get; set; } + } + + /// + /// + /// + /// CAN baudrate. For example 250.000 + /// mcp2515 clock frequency. For example 8.000.000 + public void SetBitRate(int baudRate, int clockFrequency) + { + var mode = GetOperationMode(); + if(mode != OperationMode.Configuration) + { + SetOperationMode(OperationMode.Configuration); + } + + var CNF_MAPPER = new Config[] + { + new() { ClockFrequency = 8_000_000L, BaudRate = 1_000_000L, Cnf = new byte[] { 0x00, 0x80, 0x00 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 666_666L, Cnf = new byte[] { 0xC0, 0xB8, 0x01 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 500_000L, Cnf = new byte[] { 0x00, 0x90, 0x02 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 250_000L, Cnf = new byte[] { 0x00, 0xB1, 0x05 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 200_000L, Cnf = new byte[] { 0x00, 0xB4, 0x06 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 125_000L, Cnf = new byte[] { 0x01, 0xB1, 0x05 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 100_000L, Cnf = new byte[] { 0x01, 0xB4, 0x06 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 80_000L, Cnf = new byte[] { 0x01, 0xBF, 0x07 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 50_000L, Cnf = new byte[] { 0x03, 0xB4, 0x06 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 40_000L, Cnf = new byte[] { 0x03, 0xBF, 0x07 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 20_000L, Cnf = new byte[] { 0x07, 0xBF, 0x07 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 10_000L, Cnf = new byte[] { 0x0F, 0xBF, 0x07 } }, + new() { ClockFrequency = 8_000_000L, BaudRate = 5_000L, Cnf = new byte[] { 0x1F, 0xBF, 0x07 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 1_000_000L, Cnf = new byte[] { 0x00, 0xD0, 0x82 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 666_666L, Cnf = new byte[] { 0xC0, 0xF8, 0x81 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 500_000L, Cnf = new byte[] { 0x00, 0xF0, 0x86 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 250_000L, Cnf = new byte[] { 0x41, 0xF1, 0x85 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 200_000L, Cnf = new byte[] { 0x01, 0xFA, 0x87 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 125_000L, Cnf = new byte[] { 0x03, 0xF0, 0x86 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 100_000L, Cnf = new byte[] { 0x03, 0xFA, 0x87 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 80_000L, Cnf = new byte[] { 0x03, 0xFF, 0x87 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 50_000L, Cnf = new byte[] { 0x07, 0xFA, 0x87 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 40_000L, Cnf = new byte[] { 0x07, 0xFF, 0x87 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 20_000L, Cnf = new byte[] { 0x0F, 0xFF, 0x87 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 10_000L, Cnf = new byte[] { 0x1F, 0xFF, 0x87 } }, + new() { ClockFrequency = 16_000_000L, BaudRate = 5_000L, Cnf = new byte[] { 0x3F, 0xFF, 0x87 } }, + }; + + byte[] cnf = null; + + foreach (var mapper in CNF_MAPPER) + { + if (mapper.ClockFrequency == clockFrequency && mapper.BaudRate == baudRate) + { + cnf = mapper.Cnf; + break; + } + } + + _mcp25xxx.WriteByte(Address.Cnf1, cnf[0]); + _mcp25xxx.WriteByte(Address.Cnf2, cnf[1]); + _mcp25xxx.WriteByte(Address.Cnf3, cnf[2]); + + SetFilterMask(MASK.MASK0, false, 0x7ff); + SetFilter(RXF.RXF0, false, 0x154); + SetFilterMask(MASK.MASK1, false, 0x7ff); + SetFilter(RXF.RXF0, false, 0x154); + + SetOperationMode(OperationMode.NormalOperation); + } + + public bool SetFilter(RXF num, bool ext, uint ulData) + { + var mode = GetOperationMode(); + SetOperationMode(OperationMode.Configuration); + + Address reg; + + switch (num) + { + case RXF.RXF0: reg = Address.RxF0Sidh; break; + case RXF.RXF1: reg = Address.RxF1Sidh; break; + case RXF.RXF2: reg = Address.RxF2Sidh; break; + case RXF.RXF3: reg = Address.RxF3Sidh; break; + case RXF.RXF4: reg = Address.RxF4Sidh; break; + case RXF.RXF5: reg = Address.RxF5Sidh; break; + default: + return false; + } + + SpanByte tbufdata = new byte[4]; + PrepareId(tbufdata, ext, ulData); + _mcp25xxx.Write(reg, tbufdata); + + SetOperationMode(mode); + + return true; + } + + void PrepareId(SpanByte buffer, bool ext, uint id) + { + ushort canid = (ushort)(id & 0x0FFFF); + + if (ext) + { + buffer[MCP_EID0] = (byte)(canid & 0xFF); + buffer[MCP_EID8] = (byte)(canid >> 8); + canid = (ushort)(id >> 16); + buffer[MCP_SIDL] = (byte)(canid & 0x03); + buffer[MCP_SIDL] += (byte)((canid & 0x1C) << 3); + buffer[MCP_SIDL] |= TXB_EXIDE_MASK; + buffer[MCP_SIDH] = (byte)(canid >> 5); + } + else + { + buffer[MCP_SIDH] = (byte)(canid >> 3); + buffer[MCP_SIDL] = (byte)((canid & 0x07) << 5); + buffer[MCP_EID0] = 0; + buffer[MCP_EID8] = 0; + } + } + + private bool SetFilterMask(MASK mask, bool ext, uint ulData) + { + var mode = GetOperationMode(); + SetOperationMode(OperationMode.Configuration); + + SpanByte tbufdata = new SpanByte(new byte[4]); + PrepareId(tbufdata, ext, ulData); + + Address reg; + switch (mask) + { + case MASK.MASK0: reg = Address.RxM0Sidh; break; + case MASK.MASK1: reg = Address.RxM1Sidh; break; + default: + return false; + } + + _mcp25xxx.Write(reg, tbufdata); + + SetOperationMode(mode); + return true; + } + private OperationMode GetOperationMode() + { + byte value = _mcp25xxx.Read(Address.CanStat); + var canStat = new CanStat(value); + return canStat.OperationMode; + } + + /// + /// Sets the operation mode of the MCP25xxx device. + /// + /// The MCP25xxx device instance. + /// The desired operation mode. + private void SetOperationMode(OperationMode mode) + { + // Read the current value of the CanCtrl register + var canCtrlValue = new CanCtrl(_mcp25xxx.Read(Address.CanCtrl)); + + var newCanCtrlValue = new CanCtrl( + canCtrlValue.ClkOutPinPrescaler, + canCtrlValue.ClkOutPinEnable, + canCtrlValue.OneShotMode, + canCtrlValue.AbortAllPendingTransmissions, + mode); + + // Write the modified value back to the CanCtrl register + _mcp25xxx.WriteByte(newCanCtrlValue); + } + } +} diff --git a/devices/Mcp25xxx/Can/CanEnums.cs b/devices/Mcp25xxx/Can/CanEnums.cs new file mode 100644 index 0000000000..91a143b372 --- /dev/null +++ b/devices/Mcp25xxx/Can/CanEnums.cs @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Iot.Device.Mcp25xxx.Can +{ + public enum MASK + { + MASK0, + MASK1 + }; + + public enum RXF + { + RXF0 = 0, + RXF1 = 1, + RXF2 = 2, + RXF3 = 3, + RXF4 = 4, + RXF5 = 5 + }; + + public enum InterruptEnable : byte + { + DisableAll = 0, + RXB0 = 0x01, + RXB1 = 0x02, + TXB0 = 0x04, + TXB1 = 0x08, + TXB2 = 0x10, + ERR = 0x20, + WAKE = 0x40, + MSG_ERR = 0x80 + } + +} diff --git a/devices/Mcp25xxx/Can/CanMessage.cs b/devices/Mcp25xxx/Can/CanMessage.cs new file mode 100644 index 0000000000..4673c7778d --- /dev/null +++ b/devices/Mcp25xxx/Can/CanMessage.cs @@ -0,0 +1,73 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +namespace Iot.Device.Mcp25xxx.Can +{ + /// + /// CAN message. + /// + public class CanMessage + { + private uint _id; + + private CanMessageIdType _identifierType; + + private CanMessageFrameType _frameType; + + private byte[] _message; + + /// + /// Message ID (SID or EID format, depending on ). + /// + public uint Id + { + get { return _id; } + set { _id = value; } + } + + /// + /// Message identifier type. + /// + public CanMessageIdType IdentifierType + { + get { return _identifierType; } + set { _identifierType = value; } + } + + /// + /// Message frame type. + /// + public CanMessageFrameType FrameType + { + get { return _frameType; } + set { _frameType = value; } + } + + /// + /// Message data. + /// + /// + /// Maximum lenght of data buffer is 8. + /// + /// If the message buffer exceeds the maximum allowed lenght. + public byte[] Message + { + get { return _message; } + set { _message = value; } + } + + /// + /// Creates a CAN message. + /// + public CanMessage(uint id, CanMessageIdType identifierType, CanMessageFrameType frameType, byte[] message) + { + _id = id; + _identifierType = identifierType; + _frameType = frameType; + _message = message; + } + } + +} diff --git a/devices/Mcp25xxx/Can/CanMessageFrameType.cs b/devices/Mcp25xxx/Can/CanMessageFrameType.cs new file mode 100644 index 0000000000..f2f9917a84 --- /dev/null +++ b/devices/Mcp25xxx/Can/CanMessageFrameType.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Iot.Device.Mcp25xxx.Can +{ + /// + /// CAN message frame type. + /// + public enum CanMessageFrameType + { + /// + /// Data frame. + /// + Data = 0, + + /// + /// Remote request frame. + /// + RemoteRequest + } +} diff --git a/devices/Mcp25xxx/Can/CanMessageIdType.cs b/devices/Mcp25xxx/Can/CanMessageIdType.cs new file mode 100644 index 0000000000..cdb493baf2 --- /dev/null +++ b/devices/Mcp25xxx/Can/CanMessageIdType.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Iot.Device.Mcp25xxx.Can +{ + /// + /// CAN message identifier type. + /// + public enum CanMessageIdType + { + /// + /// Standard Identifier. + /// + SID, + + /// + /// Extended Identifier. + /// + EID + } +} diff --git a/devices/Mcp25xxx/Can/ICanController.cs b/devices/Mcp25xxx/Can/ICanController.cs new file mode 100644 index 0000000000..262fa8da20 --- /dev/null +++ b/devices/Mcp25xxx/Can/ICanController.cs @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Iot.Device.Mcp25xxx.Can +{ + public interface ICanController + { + CanMessage GetMessage(); + void Initialize(Mcp25xxx mcp25xxx); + void Reset(); + void SetBitRate(int baudRate, int clockFrequency); + void WriteMessage(CanMessage message); + } +} \ No newline at end of file diff --git a/devices/Mcp25xxx/Mcp25xxx.cs b/devices/Mcp25xxx/Mcp25xxx.cs index add38d9ccf..79eae7d59e 100644 --- a/devices/Mcp25xxx/Mcp25xxx.cs +++ b/devices/Mcp25xxx/Mcp25xxx.cs @@ -260,6 +260,23 @@ public byte Read(Address address) return readBuffer[2]; } + /// + /// Reads data of a specified lenght from the register beginning at the selected address. + /// + /// The address to start reading. + /// Number of bytes to read. This must be one or more to read. + /// The value of address read. + public byte[] Read(Address address, byte length = 1) + { + SpanByte writeBuffer = new byte[2 + length]; + writeBuffer[0] = (byte)InstructionFormat.Read; + writeBuffer[1] = (byte)address; + + SpanByte readBuffer = new byte[2 + length]; + _spiDevice.TransferFullDuplex(writeBuffer, readBuffer); + return readBuffer.Slice(2).ToArray(); + } + /// /// When reading a receive buffer, reduces the overhead of a normal READ /// command by placing the Address Pointer at one of four locations for the receive buffer. @@ -451,26 +468,5 @@ public void Dispose() _spiDevice?.Dispose(); _spiDevice = null!; } - - public byte[] ReadRegister(Address register, byte length = 1) - { - SpanByte writeBuffer = new byte[2 + length]; - writeBuffer[0] = (byte)InstructionFormat.Read; - writeBuffer[1] = (byte)register; - - SpanByte readBuffer = new byte[2 + length]; - _spiDevice.TransferFullDuplex(writeBuffer, readBuffer); - return readBuffer.Slice(2).ToArray(); - - //Span tx = stackalloc byte[2 + length]; - //Span rx = stackalloc byte[2 + length]; - - //tx[0] = (byte)Command.Read; - //tx[1] = (byte)register; - - //SpiBus.Exchange(ChipSelect, tx, rx); - - //return rx.Slice(2).ToArray(); - } } } diff --git a/devices/Mcp25xxx/Mcp25xxx.nfproj b/devices/Mcp25xxx/Mcp25xxx.nfproj index 98b2221313..9df511ff7f 100644 --- a/devices/Mcp25xxx/Mcp25xxx.nfproj +++ b/devices/Mcp25xxx/Mcp25xxx.nfproj @@ -45,6 +45,12 @@ + + + + + + From d8c46e77cf72a61efdf5cae24b684fbf62915a74 Mon Sep 17 00:00:00 2001 From: Rikkert01 Date: Sat, 8 Feb 2025 15:19:40 +0100 Subject: [PATCH 3/7] removed unnecesary changes --- .../Mcp25xxx/Register/Interrupt/CanIntF.cs | 4 ++-- .../Mcp25xxx/samples/Mcp25xxx.Samples.nfproj | 3 --- devices/Mcp25xxx/samples/Program.cs | 24 +++++++------------ devices/Mcp25xxx/samples/packages.config | 1 - devices/Mcp25xxx/samples/packages.lock.json | 6 ----- 5 files changed, 11 insertions(+), 27 deletions(-) diff --git a/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs b/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs index d129cc3944..2700c4ec84 100644 --- a/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs +++ b/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs @@ -92,14 +92,14 @@ public CanIntF(byte value) /// True = Interrupt pending (must be cleared by MCU to reset interrupt condition). /// False = No interrupt pending. /// - public bool ReceiveBuffer0FullInterruptFlag { get; set; } + public bool ReceiveBuffer0FullInterruptFlag { get; } /// /// RX1IF: Receive Buffer 1 Full Interrupt Flag bit. /// True = Interrupt pending (must be cleared by MCU to reset interrupt condition). /// False = No interrupt pending. /// - public bool ReceiveBuffer1FullInterruptFlag { get; set; } + public bool ReceiveBuffer1FullInterruptFlag { get; } /// /// TX0IF: Transmit Buffer 0 Empty Interrupt Flag bit. diff --git a/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj b/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj index 6680826147..d1d8d8891d 100644 --- a/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj +++ b/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj @@ -23,9 +23,6 @@ ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll - - ..\packages\nanoFramework.Hardware.Esp32.1.6.23\lib\nanoFramework.Hardware.Esp32.dll - ..\packages\nanoFramework.Runtime.Events.1.11.18\lib\nanoFramework.Runtime.Events.dll diff --git a/devices/Mcp25xxx/samples/Program.cs b/devices/Mcp25xxx/samples/Program.cs index 885cf5d138..87f0cf1fa9 100644 --- a/devices/Mcp25xxx/samples/Program.cs +++ b/devices/Mcp25xxx/samples/Program.cs @@ -14,7 +14,6 @@ using Iot.Device.Mcp25xxx.Register.MessageReceive; using Iot.Device.Mcp25xxx.Register.MessageTransmit; using System.Diagnostics; -using nanoFramework.Hardware.Esp32; Debug.WriteLine("Hello Mcp25xxx Sample!"); @@ -22,9 +21,9 @@ Reset(mcp25xxx); // ReadAllRegisters(mcp25xxx); - ReadAllRegistersWithDetails(mcp25xxx); +ReadAllRegistersWithDetails(mcp25xxx); // ReadRxBuffer(mcp25xxx); -//Write(mcp25xxx); +// Write(mcp25xxx); // LoadTxBuffer(mcp25xxx); // RequestToSend(mcp25xxx); // ReadStatus(mcp25xxx); @@ -39,11 +38,11 @@ Mcp25xxx GetMcp25xxxDevice() ////////////////////////////////////////////////////////////////////// // when connecting to an ESP32 device, need to configure the SPI GPIOs // used for the bus - Configuration.SetPinFunction(25, DeviceFunction.SPI1_MOSI); // GPIO25 = SI (MOSI) - Configuration.SetPinFunction(26, DeviceFunction.SPI1_MISO); // GPIO26 = SO (MISO) - Configuration.SetPinFunction(33, DeviceFunction.SPI1_CLOCK); // GPIO33 = SCK (Clock) + //Configuration.SetPinFunction(25, DeviceFunction.SPI1_MOSI); + //Configuration.SetPinFunction(26, DeviceFunction.SPI1_MISO); + //Configuration.SetPinFunction(33, DeviceFunction.SPI1_CLOCK); // Make sure as well you are using the right chip select - SpiConnectionSettings spiConnectionSettings = new(1, 27); // GPIO27 = CS (Chip Select) + SpiConnectionSettings spiConnectionSettings = new(1, 27); SpiDevice spiDevice = SpiDevice.Create(spiConnectionSettings); return new Mcp2515(spiDevice); } @@ -74,13 +73,13 @@ void ReadAllRegistersWithDetails(Mcp25xxx mcp25xxx) Debug.WriteLine("Read All Registers"); Debug.WriteLine(""); - // ReadAllMessageTransmitRegistersWithDetails(mcp25xxx); + ReadAllMessageTransmitRegistersWithDetails(mcp25xxx); // ReadAllMessageReceiveRegistersWithDetails(mcp25xxx); - ReadAllAcceptanceFilterRegistersWithDetails(mcp25xxx); + // ReadAllAcceptanceFilterRegistersWithDetails(mcp25xxx); // ReadAllBitTimeConfigurationRegistersWithDetails(mcp25xxx); // ReadAllErrorDetectionRegistersWithDetails(mcp25xxx); // ReadAllInterruptRegistersWithDetails(mcp25xxx); - ReadAllCanControlRegistersWithDetails(mcp25xxx); + // ReadAllCanControlRegistersWithDetails(mcp25xxx); } byte ConsoleWriteRegisterAddressDetails(Mcp25xxx mcp25xxx, Address address) @@ -328,11 +327,6 @@ void ReadAllCanControlRegistersWithDetails(Mcp25xxx mcp25xxx) ConsoleWriteRegisterItemDetails(new CanCtrl(ConsoleWriteRegisterAddressDetails(mcp25xxx, Address.CanCtrl))); ConsoleWriteRegisterItemDetails(new CanStat(ConsoleWriteRegisterAddressDetails(mcp25xxx, Address.CanStat))); - - var canStat = new CanStat(mcp25xxx.Read(Address.CanStat)); - Debug.WriteLine($" OPMOD: {canStat.OperationMode}"); - Debug.WriteLine($" ICOD: {canStat.InterruptFlagCode}"); - } void ReadRxBuffer(Mcp25xxx mcp25xxx) diff --git a/devices/Mcp25xxx/samples/packages.config b/devices/Mcp25xxx/samples/packages.config index c5181100f9..4fbd05f8de 100644 --- a/devices/Mcp25xxx/samples/packages.config +++ b/devices/Mcp25xxx/samples/packages.config @@ -1,7 +1,6 @@  - diff --git a/devices/Mcp25xxx/samples/packages.lock.json b/devices/Mcp25xxx/samples/packages.lock.json index 4d2900e458..22094432d5 100644 --- a/devices/Mcp25xxx/samples/packages.lock.json +++ b/devices/Mcp25xxx/samples/packages.lock.json @@ -8,12 +8,6 @@ "resolved": "1.15.5", "contentHash": "u2+GvAp1uxLrGdILACAZy+EVKOs28EQ52j8Lz7599egXZ3GBGejjnR2ofhjMQwzrJLlgtyrsx8nSLngDfJNsAg==" }, - "nanoFramework.Hardware.Esp32": { - "type": "Direct", - "requested": "[1.6.23, 1.6.23]", - "resolved": "1.6.23", - "contentHash": "rgNByDk4jttssYlXAhDpgt0IWYoUNbyDSQjy7xV7tG+z8dTt7IjA5ehe42028Umwoe6ksHm8mRDfFsITotbNiA==" - }, "nanoFramework.Runtime.Events": { "type": "Direct", "requested": "[1.11.18, 1.11.18]", From 68c0a0e91c9948207d17eee516801cf8afe33bfa Mon Sep 17 00:00:00 2001 From: Rikkert01 Date: Sat, 8 Feb 2025 16:20:49 +0100 Subject: [PATCH 4/7] updated package references --- devices/Mcp25xxx/Mcp25xxx.nfproj | 17 +++++++------ devices/Mcp25xxx/Mcp25xxx.sln | 11 ++------- .../Mcp25xxx/Register/Interrupt/CanIntF.cs | 4 ++-- devices/Mcp25xxx/packages.config | 8 +++---- devices/Mcp25xxx/packages.lock.json | 24 +++++++++---------- .../Mcp25xxx/samples/Mcp25xxx.Samples.nfproj | 21 +++++++--------- devices/Mcp25xxx/samples/packages.config | 8 +++---- devices/Mcp25xxx/samples/packages.lock.json | 24 +++++++++---------- 8 files changed, 55 insertions(+), 62 deletions(-) diff --git a/devices/Mcp25xxx/Mcp25xxx.nfproj b/devices/Mcp25xxx/Mcp25xxx.nfproj index 9df511ff7f..764623b54c 100644 --- a/devices/Mcp25xxx/Mcp25xxx.nfproj +++ b/devices/Mcp25xxx/Mcp25xxx.nfproj @@ -30,21 +30,23 @@ + + packages\nanoFramework.CoreLibrary.1.16.11\lib\mscorlib.dll + packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll - - packages\nanoFramework.Runtime.Events.1.11.18\lib\nanoFramework.Runtime.Events.dll + + packages\nanoFramework.Runtime.Events.1.11.29\lib\nanoFramework.Runtime.Events.dll - - packages\nanoFramework.System.Device.Gpio.1.1.41\lib\System.Device.Gpio.dll + + packages\nanoFramework.System.Device.Gpio.1.1.53\lib\System.Device.Gpio.dll - - packages\nanoFramework.System.Device.Spi.1.3.52\lib\System.Device.Spi.dll + + packages\nanoFramework.System.Device.Spi.1.3.73\lib\System.Device.Spi.dll - @@ -60,6 +62,7 @@ + diff --git a/devices/Mcp25xxx/Mcp25xxx.sln b/devices/Mcp25xxx/Mcp25xxx.sln index 8212ab1bb3..ee91da7f9b 100644 --- a/devices/Mcp25xxx/Mcp25xxx.sln +++ b/devices/Mcp25xxx/Mcp25xxx.sln @@ -1,7 +1,6 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30413.136 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35527.113 d17.12 MinimumVisualStudioVersion = 15.0.26124.0 Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Mcp25xxx", "Mcp25xxx.nfproj", "{36CCC2BB-F206-44FD-A852-D9219E39C391}" EndProject @@ -25,12 +24,6 @@ Global {4BFDD29A-0A47-4798-B5A7-C05E39667013}.Release|Any CPU.ActiveCfg = Release|Any CPU {4BFDD29A-0A47-4798-B5A7-C05E39667013}.Release|Any CPU.Build.0 = Release|Any CPU {4BFDD29A-0A47-4798-B5A7-C05E39667013}.Release|Any CPU.Deploy.0 = Release|Any CPU - {EDF668AE-0CC6-47AF-AEB7-3B23EDA0EA1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EDF668AE-0CC6-47AF-AEB7-3B23EDA0EA1C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EDF668AE-0CC6-47AF-AEB7-3B23EDA0EA1C}.Debug|Any CPU.Deploy.0 = Debug|Any CPU - {EDF668AE-0CC6-47AF-AEB7-3B23EDA0EA1C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EDF668AE-0CC6-47AF-AEB7-3B23EDA0EA1C}.Release|Any CPU.Build.0 = Release|Any CPU - {EDF668AE-0CC6-47AF-AEB7-3B23EDA0EA1C}.Release|Any CPU.Deploy.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs b/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs index 2700c4ec84..d129cc3944 100644 --- a/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs +++ b/devices/Mcp25xxx/Register/Interrupt/CanIntF.cs @@ -92,14 +92,14 @@ public CanIntF(byte value) /// True = Interrupt pending (must be cleared by MCU to reset interrupt condition). /// False = No interrupt pending. /// - public bool ReceiveBuffer0FullInterruptFlag { get; } + public bool ReceiveBuffer0FullInterruptFlag { get; set; } /// /// RX1IF: Receive Buffer 1 Full Interrupt Flag bit. /// True = Interrupt pending (must be cleared by MCU to reset interrupt condition). /// False = No interrupt pending. /// - public bool ReceiveBuffer1FullInterruptFlag { get; } + public bool ReceiveBuffer1FullInterruptFlag { get; set; } /// /// TX0IF: Transmit Buffer 0 Empty Interrupt Flag bit. diff --git a/devices/Mcp25xxx/packages.config b/devices/Mcp25xxx/packages.config index 115c650cd4..d13a0b8705 100644 --- a/devices/Mcp25xxx/packages.config +++ b/devices/Mcp25xxx/packages.config @@ -1,8 +1,8 @@  - - - - + + + + \ No newline at end of file diff --git a/devices/Mcp25xxx/packages.lock.json b/devices/Mcp25xxx/packages.lock.json index 403df704ef..30139681f6 100644 --- a/devices/Mcp25xxx/packages.lock.json +++ b/devices/Mcp25xxx/packages.lock.json @@ -4,27 +4,27 @@ ".NETnanoFramework,Version=v1.0": { "nanoFramework.CoreLibrary": { "type": "Direct", - "requested": "[1.15.5, 1.15.5]", - "resolved": "1.15.5", - "contentHash": "u2+GvAp1uxLrGdILACAZy+EVKOs28EQ52j8Lz7599egXZ3GBGejjnR2ofhjMQwzrJLlgtyrsx8nSLngDfJNsAg==" + "requested": "[1.16.11, 1.16.11]", + "resolved": "1.16.11", + "contentHash": "2XW+Zn0lQ+lOcxDbB1l2ga2rNoj9Jv2IeJwXE4ka1r+swmxn5N/otlMJVEXJgK8trUeD/E8T7+J7dXjU8UReHw==" }, "nanoFramework.Runtime.Events": { "type": "Direct", - "requested": "[1.11.18, 1.11.18]", - "resolved": "1.11.18", - "contentHash": "t0XpUkdyBBBv/0S4oGx3yUJG1iPYWc38odvZW8mVoioSxZOJrRkRHpNfwYxTxtP4LIEyyesOPEH42d05FHfHzA==" + "requested": "[1.11.29, 1.11.29]", + "resolved": "1.11.29", + "contentHash": "y3Y0SNfr1afMor4xrsiB1ETldjKvmnzBTcEH5gizFFXw3RNBB/N8npWqkCJn4HZS0TEENlH2vVrib3bWYMx5+Q==" }, "nanoFramework.System.Device.Gpio": { "type": "Direct", - "requested": "[1.1.41, 1.1.41]", - "resolved": "1.1.41", - "contentHash": "5QnpdfvjxOvka2S5IHSdKudWmkH+CDQ3TFFuXOGuNlgZJFsAx0/k5zuwgJYkxIyGbL8kdcjBWLyDNdihjA1pUg==" + "requested": "[1.1.53, 1.1.53]", + "resolved": "1.1.53", + "contentHash": "7Pd5iAeWPGdtKUB+OJ0vPjL+d9tQAK0s0JxV1dfjh6PZcU38wykdK64oMqNmCbDFA0aiZl0UyFmz3zXchn39nQ==" }, "nanoFramework.System.Device.Spi": { "type": "Direct", - "requested": "[1.3.52, 1.3.52]", - "resolved": "1.3.52", - "contentHash": "chtkrJp424LMitA6Fw/QzzhIrYL9PdEaln+A7o5QR99VijDoOILdMvgeeVBnIpkicUH7aY9Vj+3F2TlIGQH/+g==" + "requested": "[1.3.73, 1.3.73]", + "resolved": "1.3.73", + "contentHash": "bHh4MYqJcOfWnWjWBzYWZ+BiZdnUWXdJQKn7saGAaJTdQNVmYOF4QLL0P0bzetgAsEgeQ/ULs69ITBK64/jbyw==" }, "Nerdbank.GitVersioning": { "type": "Direct", diff --git a/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj b/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj index d1d8d8891d..7fdf3baf32 100644 --- a/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj +++ b/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj @@ -20,27 +20,24 @@ - - ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + + ..\packages\nanoFramework.CoreLibrary.1.16.11\lib\mscorlib.dll - - ..\packages\nanoFramework.Runtime.Events.1.11.18\lib\nanoFramework.Runtime.Events.dll + + ..\packages\nanoFramework.Runtime.Events.1.11.29\lib\nanoFramework.Runtime.Events.dll - - ..\packages\nanoFramework.System.Device.Gpio.1.1.41\lib\System.Device.Gpio.dll + + ..\packages\nanoFramework.System.Device.Gpio.1.1.53\lib\System.Device.Gpio.dll - - ..\packages\nanoFramework.System.Device.Spi.1.3.52\lib\System.Device.Spi.dll + + ..\packages\nanoFramework.System.Device.Spi.1.3.73\lib\System.Device.Spi.dll - - - - + diff --git a/devices/Mcp25xxx/samples/packages.config b/devices/Mcp25xxx/samples/packages.config index 4fbd05f8de..d5809c7dd0 100644 --- a/devices/Mcp25xxx/samples/packages.config +++ b/devices/Mcp25xxx/samples/packages.config @@ -1,7 +1,7 @@  - - - - + + + + \ No newline at end of file diff --git a/devices/Mcp25xxx/samples/packages.lock.json b/devices/Mcp25xxx/samples/packages.lock.json index 22094432d5..6004e9f425 100644 --- a/devices/Mcp25xxx/samples/packages.lock.json +++ b/devices/Mcp25xxx/samples/packages.lock.json @@ -4,27 +4,27 @@ ".NETnanoFramework,Version=v1.0": { "nanoFramework.CoreLibrary": { "type": "Direct", - "requested": "[1.15.5, 1.15.5]", - "resolved": "1.15.5", - "contentHash": "u2+GvAp1uxLrGdILACAZy+EVKOs28EQ52j8Lz7599egXZ3GBGejjnR2ofhjMQwzrJLlgtyrsx8nSLngDfJNsAg==" + "requested": "[1.16.11, 1.16.11]", + "resolved": "1.16.11", + "contentHash": "2XW+Zn0lQ+lOcxDbB1l2ga2rNoj9Jv2IeJwXE4ka1r+swmxn5N/otlMJVEXJgK8trUeD/E8T7+J7dXjU8UReHw==" }, "nanoFramework.Runtime.Events": { "type": "Direct", - "requested": "[1.11.18, 1.11.18]", - "resolved": "1.11.18", - "contentHash": "t0XpUkdyBBBv/0S4oGx3yUJG1iPYWc38odvZW8mVoioSxZOJrRkRHpNfwYxTxtP4LIEyyesOPEH42d05FHfHzA==" + "requested": "[1.11.29, 1.11.29]", + "resolved": "1.11.29", + "contentHash": "y3Y0SNfr1afMor4xrsiB1ETldjKvmnzBTcEH5gizFFXw3RNBB/N8npWqkCJn4HZS0TEENlH2vVrib3bWYMx5+Q==" }, "nanoFramework.System.Device.Gpio": { "type": "Direct", - "requested": "[1.1.41, 1.1.41]", - "resolved": "1.1.41", - "contentHash": "5QnpdfvjxOvka2S5IHSdKudWmkH+CDQ3TFFuXOGuNlgZJFsAx0/k5zuwgJYkxIyGbL8kdcjBWLyDNdihjA1pUg==" + "requested": "[1.1.53, 1.1.53]", + "resolved": "1.1.53", + "contentHash": "7Pd5iAeWPGdtKUB+OJ0vPjL+d9tQAK0s0JxV1dfjh6PZcU38wykdK64oMqNmCbDFA0aiZl0UyFmz3zXchn39nQ==" }, "nanoFramework.System.Device.Spi": { "type": "Direct", - "requested": "[1.3.52, 1.3.52]", - "resolved": "1.3.52", - "contentHash": "chtkrJp424LMitA6Fw/QzzhIrYL9PdEaln+A7o5QR99VijDoOILdMvgeeVBnIpkicUH7aY9Vj+3F2TlIGQH/+g==" + "requested": "[1.3.73, 1.3.73]", + "resolved": "1.3.73", + "contentHash": "bHh4MYqJcOfWnWjWBzYWZ+BiZdnUWXdJQKn7saGAaJTdQNVmYOF4QLL0P0bzetgAsEgeQ/ULs69ITBK64/jbyw==" } } } From 12baedd75283e6a6f0efa3bb8d1f421e3cdaa836 Mon Sep 17 00:00:00 2001 From: Rikkert01 Date: Sat, 8 Feb 2025 16:28:13 +0100 Subject: [PATCH 5/7] removed unused references --- devices/Mcp25xxx/Mcp25xxx.nfproj | 8 +------- devices/Mcp25xxx/samples/Program.cs | 10 +++++----- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/devices/Mcp25xxx/Mcp25xxx.nfproj b/devices/Mcp25xxx/Mcp25xxx.nfproj index 764623b54c..699f6f92ef 100644 --- a/devices/Mcp25xxx/Mcp25xxx.nfproj +++ b/devices/Mcp25xxx/Mcp25xxx.nfproj @@ -33,9 +33,6 @@ packages\nanoFramework.CoreLibrary.1.16.11\lib\mscorlib.dll - - packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll - packages\nanoFramework.Runtime.Events.1.11.29\lib\nanoFramework.Runtime.Events.dll @@ -47,6 +44,7 @@ + @@ -62,16 +60,12 @@ - - - - diff --git a/devices/Mcp25xxx/samples/Program.cs b/devices/Mcp25xxx/samples/Program.cs index 87f0cf1fa9..ccf226c6c6 100644 --- a/devices/Mcp25xxx/samples/Program.cs +++ b/devices/Mcp25xxx/samples/Program.cs @@ -38,13 +38,13 @@ Mcp25xxx GetMcp25xxxDevice() ////////////////////////////////////////////////////////////////////// // when connecting to an ESP32 device, need to configure the SPI GPIOs // used for the bus - //Configuration.SetPinFunction(25, DeviceFunction.SPI1_MOSI); - //Configuration.SetPinFunction(26, DeviceFunction.SPI1_MISO); - //Configuration.SetPinFunction(33, DeviceFunction.SPI1_CLOCK); + //Configuration.SetPinFunction(21, DeviceFunction.SPI1_MOSI); + //Configuration.SetPinFunction(22, DeviceFunction.SPI1_MISO); + //Configuration.SetPinFunction(32, DeviceFunction.SPI1_CLOCK); // Make sure as well you are using the right chip select - SpiConnectionSettings spiConnectionSettings = new(1, 27); + SpiConnectionSettings spiConnectionSettings = new(1, 42); SpiDevice spiDevice = SpiDevice.Create(spiConnectionSettings); - return new Mcp2515(spiDevice); + return new Mcp25625(spiDevice); } void Reset(Mcp25xxx mcp25xxx) From cfa1a2f41b74f3671c762011b38043dd25f797a6 Mon Sep 17 00:00:00 2001 From: Rikkert01 Date: Sat, 8 Feb 2025 16:33:53 +0100 Subject: [PATCH 6/7] removed unnecessary changes --- devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj b/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj index 7fdf3baf32..b60a00af3b 100644 --- a/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj +++ b/devices/Mcp25xxx/samples/Mcp25xxx.Samples.nfproj @@ -33,18 +33,18 @@ ..\packages\nanoFramework.System.Device.Spi.1.3.73\lib\System.Device.Spi.dll + + + + - - - - From 77599d55f23d9e04e78f37ab65dd8917ca93e293 Mon Sep 17 00:00:00 2001 From: Rikkert01 Date: Sat, 8 Feb 2025 16:34:34 +0100 Subject: [PATCH 7/7] typo --- devices/Mcp25xxx/samples/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devices/Mcp25xxx/samples/Program.cs b/devices/Mcp25xxx/samples/Program.cs index ccf226c6c6..ef30d2bbb4 100644 --- a/devices/Mcp25xxx/samples/Program.cs +++ b/devices/Mcp25xxx/samples/Program.cs @@ -40,7 +40,7 @@ Mcp25xxx GetMcp25xxxDevice() // used for the bus //Configuration.SetPinFunction(21, DeviceFunction.SPI1_MOSI); //Configuration.SetPinFunction(22, DeviceFunction.SPI1_MISO); - //Configuration.SetPinFunction(32, DeviceFunction.SPI1_CLOCK); + //Configuration.SetPinFunction(22, DeviceFunction.SPI1_CLOCK); // Make sure as well you are using the right chip select SpiConnectionSettings spiConnectionSettings = new(1, 42); SpiDevice spiDevice = SpiDevice.Create(spiConnectionSettings);