I am migrating a driver for the TinyFileSystem from NETMF to TinyCLR OS, and have come up with a problem on SPI code using the WriteRead() in NETMF, where I can not seem to find an equivalent in TinyCLR, or at least is not working for me.
In the read method, the NETMF code is:
public void ReadData(int address, byte[] array, int index, int count)
{
if ((array.Length - index) < count) throw new ArgumentException("Invalid index + count");
if ((MaxAddress - count) < address) throw new ArgumentException("Invalid address + count");
while (WriteEnable() == false) Thread.Sleep(0);
data4[0] = CMD_READ;
data4[1] = (byte) (address >> 16);
data4[2] = (byte) (address >> 8);
data4[3] = (byte) (address >> 0);
_spi.WriteRead(data4, 0, 4, array, index, count, 4);
}
To clarify, that is this overload:
spi.WriteRead(writeBuffer, writeOffset, writeCount, readBuffer, readOffset, readCount, startReadOffset);
The best I can come up in TinyCLR is:
spi.TransferFullDuplex(data4, 0, array, index, count);
But this then throws an exception about writeBuffer, see below.
Not sure about the error, so any hints or pointers?