Just wondering how I can send data through SPI to the maxO module, and then read back which pins are set. I understand that there are methods which already do that but I was hoping to use SPI for this.
Here is my configuration that I wrote (which I also believe doesn’t work). Any help would be very beneficial.
using Gadgeteer.Interfaces;
GT.Socket _socket = GT.Socket.GetSocket(6, true, null, null);
ConfigSPI = new SPI.Configuration(false, 0, 0, false, true, 1000);
SPI MySPI = new SPI(_socket, ConfigSPI, SPI.Sharing.Shared, maxO);
I am using the Spider board and I connected the maxO module to socket 6.
Ok. That module uses some extra pins that you have to set to a certain state (enable pin for example) for the module to work properly. Just using SPI is not enough. Take a look at module’s source code on codeplex, if you want to rewrite it, or just use it as is.
No, you still will be using SPI. You just need to take care of other pins on that socket as well:
/// <summary>
/// Writes the full array of data to the registers.
/// </summary>
/// <param name="arr"></param>
public void WriteArray(byte[] arr)
{
if (!reSized)
{
throw new Exception("No boards have been initialized! Please indicate how many modules are chained before writing");
}
if (arr.Length != data.Length)
{
throw new Exception("Passed in array not the same size as the number of registers!");
}
Enable.Write(true);
{
byte[] reversedArr = new byte[arr.Length];
Array.Copy(arr, reversedArr, arr.Length);
for (int i = 0; i < reversedArr.Length; i++)
{
reversedArr[i] = arr[data.Length - i - 1];//(byte)(~reversedArr[i]);
}
spi.Write(reversedArr);
Array.Copy(arr, data, arr.Length);
}
Enable.Write(false);
}
Where Enable is:
Enable = new GTI.DigitalOutput(socket, Socket.Pin.Three, false, this);