Complete SPI Example for FEZ Domino Board

Here’s a modified example from the Beginners Guide that I used for the FEZ Domino Board.
I connected Di11 (SPI out) and Di12 (SPI in) together. And note that in this case, the clock and chip select are ignored because we are configured as an SPI master. Once the application is up and running you can singled step through the code and also verify the two received bytes of data in rx_data as {0xAA, 0xAA} = 1010101010101010 binary.


using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;

namespace SPI_Beginners_Guide
{
    public class Program
    {
        public static void Main()
        {
            // Configure an instance and then create an SPI Object - Di11, Di12 & Di13. Di2 is chip select
            SPI.Configuration MyConfig = new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.Di2 , false, 0, 0, false, true, 200, SPI.SPI_module.SPI1); // 200k bits
            // Create SPI object here
            SPI MySPI = new SPI(MyConfig);
            byte[] tx_data = {0xAA, 0xAA}; // SPI looks like this: 1010101010101010
            byte[] rx_data = new byte[2];  // receive the two bytes of SPI via loopback jumper
            MySPI.WriteRead(tx_data, rx_data); // Send and receive SPI data

            while (true)
            {
                MySPI.WriteRead(tx_data, rx_data); // Send and receive SPI data once a second
                // zzzzzzzzzzzzzzzzz
                Thread.Sleep(1000); // Sleep for 1 second
            }
        }
    }
}

Thanks John, I modified your post to add the code tags so the code is readable.