Main Site Documentation

Using SPI and Extender Board


#1

I have a GHI Spider main board, using VC# 2010 I connected:


usbClient = new GTM.GHIElectronics.UsbClientDP(1);
extender = new GTM.GHIElectronics.Extender(6);
display = new GTM.GHIElectronics.Display_T35(14, 13, 12, 10);
button = new GTM.GHIElectronics.Button(11);

SPI 2 is on socket 6, as mosi, miso, and sck.
Also, IO18, IO20, IO22, and IO10 are on socket 6.
In the SPI initialization, I specify Cpu.Pin.GPIO_Pin10. I assume this is IO10?
Typing Cpu.Pin. allows me to see the completions fo GPIO_Pin0 through GPIO_Pin15.
How do I access any of the other pins?


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

// for SPI
//using GHIElectronics.NETMF.Hardware;
using Microsoft.SPOT.Hardware;


namespace mySPI
{
    public partial class Program
    {
        SPI.Configuration MyConfig = new SPI.Configuration(Cpu.Pin.GPIO_Pin1,
             false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/
            SPI MySPI = new SPI(MyConfig);
            byte[] tx_data = new byte[10];
            byte[] rx_data = new byte[10];

            MySPI.WriteRead(tx_data, rx_data);

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
        }
    }
}



#2

Take a look at the music module drivers. It uses SPI.


#3

I have SPI2 working with the extender board.

The GHI spider has 76 I/O pins.

I can see 16 pins using Cpu.Pin.GPIO_Pinxx where xx is 0 thru 15

Suppose I want to use 4 SPI devices, all connected to SPI2, socket 6. To do this, I
need to have IO18, IO20, IO22, and IO10 as CS pins.

How do I specify IO20 or IO22?


#4

If you are using spider then you would get the pins through gadgeteer core. Many examples are in code.

If not using gadgeteer then see EMX DLL with pins


#5

In case anyone is watching this

I am using sopcket 6 for SPI.

I have multiple devices connected.

I have 4 chip selects available. These are socket 6, pins 3, 4, 5, and, 6,
IO18, IO20, IO22, and IO10.

EMX.Pin.IO18, EMX.Pin.IO20, EMX.Pin.IO22, EMX.Pin.IO10, respectively.

You can use Cpu.Pin.GPIO_Pin10 for the last one.


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHIElectronics.NETMF.Hardware;

// for SPI
//using GHIElectronics.NETMF.Hardware;
using Microsoft.SPOT.Hardware;


namespace mySPI
{
    public partial class Program
    {

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/
            button.ButtonPressed += new GTM.GHIElectronics.Button.ButtonEventHandler(button_ButtonPressed);
            SPI.Configuration MyConfig = new SPI.Configuration(EMX.Pin.IO18,//Cpu.Pin.GPIO_Pin10,     // CS pin
                                                                false,                 // CS active state
                                                                0,                     // CS setup time
                                                                0,                     // CS hold time
                                                                false,                 // SCK idle state
                                                                true,                  // SCK edge
                                                                4000,                  // clock rate. KHz
                                                                SPI.SPI_module.SPI2);  // which spi module to use
            
            SPI MySPI = new SPI(MyConfig);
 
            byte[] tx_data = new byte[10];
            byte[] rx_data = new byte[10];

            for (byte idx=0; idx<10; idx++) tx_data[idx] = idx;

            while (true)
            {
                MySPI.WriteRead(tx_data, rx_data);
                Thread.Sleep(10);
            }

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            //Debug.Print("Program Started");
        }

        void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
        {
            button.ToggleLED();
        }
    }
}