How to use the SPI on the cerberus

Hello everybody,

I’d like to know how to use the SPI Liaison cerberus. I was inspired by an example of GHI tutorial but it does not work. I’d like your help to find out where that I have made a mistake in my code. I have two fez cerberus. One master and one slave. It has both the same code.

Thank you.

using System;
using System.Collections;
using System.Threading;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using System.IO.Ports;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using GTI = Gadgeteer.Interfaces;
namespace LiaisonSpiTest_Esclave_
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.   
        private static GTI.SPI _spi;
        private static GTI.SPI.Configuration _config;
        private static GT.Socket _socket;
        private static byte[] writeBuffer, readBuffer;
        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();
            *******************************************************************************************/
            Debug.Print("Program Started");
            _socket = GT.Socket.GetSocket(5, true, null, null);
            _config = new GTI.SPI.Configuration(false, 0, 0, false, true, 2000);
            _spi = new GTI.SPI(_socket, _config, GTI.SPI.Sharing.Exclusive, _socket, GT.Socket.Pin.Six, null);
            
            writeBuffer = new byte[5] { 83, 80, 73, 81, 75 };
            readBuffer = new byte[5] ;
            GT.Timer timer = new GT.Timer(100);
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            _spi.WriteRead(writeBuffer, readBuffer);                     
            
        }
        void timer_Tick(GT.Timer timer)
        {
            _spi.WriteRead(writeBuffer, readBuffer);
        }
    }
}

Usually a Gadgeteer device is the SPI master (generates the clock). SPI slaves are various modules (sensors, displays) that support SPI. I don’t think you can use two Cerberus in Master/Slave configuration as is.

Okay, but how do I test my program if I have no slave. I have only four cards: two cerberus and two cerb40? I have no module. Thank for your help.

You would not be able to accurately test this without a slave. If you only want to see if you are sending data, you can hook it up to a logic analyzer.

@ mous - Check the parts you have if any, maybe you have something like a shift register IC or any other bread board friendly SPI chips.