SPI maxO communication

Hi,

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.

It is output only

Sorry, the maxO module is output only? (i.e. I cannot write to it)

Otherway around isn’t it???

output, you can write to it but you can’t read from it

Max O = Maximum Outputs.

ok, so how would I go about writing to the module? The following code only set the rightmost pin to high:


using Gadgeteer.Interface;

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);

byte[] tx_data = { 0xAA, 0xAA, 0xAA, 0xAA };
MySPI.Write(tx_data);


Just curious why are you using SPI directly instead of using Gadgeteer driver? Is there a problem?

No particular reason, more out of curiosity than anything. I guess proof of concept?

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.

Ah, ok - no real direct way of doing this I see. I will take a look.

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);

Ah i see. The Enable Pin was what really got me. Thanks for the response.

You are welcome!