I wrote a small test program and when running it on a Raspberry PI 3 with a PiFace Digital 2, I get the following exception:
Unhandled exception. System.ArgumentException: Parameters 'writeBuffer' and 'readBuffer' must have the same length.
at System.Device.Spi.UnixSpiDevice.TransferFullDuplex(ReadOnlySpan1 writeBuffer, Span1 readBuffer)
at Iot.Device.Mcp23xxx.Mcp23xxx.SpiAdapter.Read(Byte registerAddress, Span1 buffer) at Iot.Device.Mcp23xxx.Mcp23xxx.InternalRead(Register register, Span1 buffer, Port port)
at Iot.Device.Mcp23xxx.Mcp23xxx.InternalReadByte(Register register, Port port)
at Iot.Device.Mcp23xxx.Mcp23x1x.ReadByte(Register register, Port port)
at TestPiface.Program.Main(String[] args) in /home/vsts/work/1/s/Electronics/Implementations/TestPiface/Program.cs:line 31
The line causing the issue is:
byte currentValue = mcp23s17.ReadByte(Register.GPIO, Port.PortA);
Shouldn't it be possible to read the state of the output ports like this?
This is the complete program:
using System;
using System.Threading.Tasks;
using System.Threading;
using Iot.Device.Mcp23xxx;
using System.Device.Spi;
namespace TestPiface
{
class Program
{
private static readonly int s_deviceAddress = 0x20;
private static Mcp23s17 mcp23s17;
static void Main(string[] args)
{
var spiConnectionSettings = new SpiConnectionSettings(0, 0)
{
ClockFrequency = 1000000,
Mode = SpiMode.Mode0
};
var spiDevice = SpiDevice.Create(spiConnectionSettings);
mcp23s17 = new Mcp23s17(spiDevice, s_deviceAddress);
mcp23s17.WriteByte(Register.IODIR, 0b0000_0000, Port.PortA); // set port A as an output
mcp23s17.WriteByte(Register.IODIR, 0b1111_1111, Port.PortB); // set port B as an input
mcp23s17.WriteByte(Register.GPIO, 0b0000_0000, Port.PortA); // Clear all outputs
byte currentValue = mcp23s17.ReadByte(Register.GPIO, Port.PortA);
mcp23s17.WriteByte(Register.GPIO, 0b0000_0010, Port.PortA);
}
}
}
I wrote a small test program and when running it on a Raspberry PI 3 with a PiFace Digital 2, I get the following exception:
Unhandled exception. System.ArgumentException: Parameters 'writeBuffer' and 'readBuffer' must have the same length.
at System.Device.Spi.UnixSpiDevice.TransferFullDuplex(ReadOnlySpan
1 writeBuffer, Span1 readBuffer)at Iot.Device.Mcp23xxx.Mcp23xxx.SpiAdapter.Read(Byte registerAddress, Span
1 buffer) at Iot.Device.Mcp23xxx.Mcp23xxx.InternalRead(Register register, Span1 buffer, Port port)at Iot.Device.Mcp23xxx.Mcp23xxx.InternalReadByte(Register register, Port port)
at Iot.Device.Mcp23xxx.Mcp23x1x.ReadByte(Register register, Port port)
at TestPiface.Program.Main(String[] args) in /home/vsts/work/1/s/Electronics/Implementations/TestPiface/Program.cs:line 31
The line causing the issue is:
Shouldn't it be possible to read the state of the output ports like this?
This is the complete program:
using System;
using System.Threading.Tasks;
using System.Threading;
using Iot.Device.Mcp23xxx;
using System.Device.Spi;
namespace TestPiface
{
class Program
{
private static readonly int s_deviceAddress = 0x20;
}