See the IO Pins page here for any extensions needed by Visual Studio and to enable the IO pins.

using System.Threading.Tasks;
using Windows.Devices.Enumeration;
using Windows.Devices.Spi;
	private const string SPI_PORT_NAME = "SPI0";
	private SpiDevice OurSpiPort;
	public bool InitialiseComplete = false;

	//********************************
	//********************************
	//********** INITIALISE **********
	//********************************
	//********************************
	//ChipSelectId: 0 or 1
	//NOTE - THIS IS AN ASYNC METHOD, IF YOU DON'T AWAIT IT WHEN CALLING THEN IT MAY NOT BE COMPELTE WHEN YOU FIRST TRY TO USE THE OTHER IO METHODS)
	public async void Initialise(int ChipSelectId)
	{

		try
		{
			// Create SPI initialization settings
			var settings = new SpiConnectionSettings(ChipSelectId);			//CS Select line
			settings.ClockFrequency = 10000;                    //<<<<<SET BUS SPEED (10000000 = 10MHz - 100nS per bit).  10000 = Is slowest possible ClockFrequency
			settings.Mode = SpiMode.Mode3;

			string spiAqs = SpiDevice.GetDeviceSelector(SPI_PORT_NAME);
			var devicesInfo = await DeviceInformation.FindAllAsync(spiAqs);
			OurSpiPort = await SpiDevice.FromIdAsync(devicesInfo[0].Id, settings);
		}
		catch (Exception e)
		{
			System.Diagnostics.Debug.WriteLine("SPI Initialisation Error", e.Message);
		}
		finally
		{
			InitialiseComplete = true;
		}

		return;
	}
		
	//**************************************
	//**************************************
	//********** READ/WRITE BYTES **********
	//**************************************
	//**************************************
	public void ReadWriteBytes(byte[] TxData, out byte[] RxData)
	{
		RxData = new byte[(TxData.Length)];
		int Count;
		for (Count = 0; Count < RxData.Length; Count++)
			RxData[Count] = 0;

		try
		{
			if (!InitialiseComplete)
				return;

			RxData = new byte[TxData.Length];
			OurSpiPort.TransferFullDuplex(TxData, RxData);
		}
		catch (Exception)
		{
			//System.Diagnostics.Debug.WriteLine("Exception: {0}", e.Message);
			return;
		}

		return;
	}
UK Electronic Designer
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.