What is the overall specified range for setting the SPI clock rate on the Raptor? I have need for a low rate (~200kHz), but anything lower than about 525 kHz seems to break the interface.
Here’s the code I’m using to test:
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.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using Gadgeteer.Interfaces;
using GTI = Gadgeteer.Interfaces;
namespace SPITest
{
public partial class Program
{
private GT.Socket SPI_socket;
private GT.Socket IO_socket;
private GTI.SPI mySPI; // Syncport Module A
// Define the SPI Configuration object
private static SPI.Configuration spi_configuration = new SPI.Configuration(
false, //Chip Select Active State
0, //Chip Select Setup Time
0, //Chip Select Hold Time
false, //Clock Idle State
true, //Clock Edge
525); //Clock Rate (kHz)
// Define Module BUS Read Signal
private static DigitalOutput Trigger;
public static byte[] spidata;
const int bufferLength = 32;
// 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();
*******************************************************************************************/
// Define the SPI Interface
SPI_socket = GT.Socket.GetSocket(1, true, null, null);
mySPI = new SPI(SPI_socket, spi_configuration, SPI.Sharing.Shared, SPI_socket, GT.Socket.Pin.Six, null);
// create and fill the SPI data buffer
spidata = new byte[bufferLength];
for (int i = 0; i < spidata.Length; i++)
spidata[i] = (byte)i;
// Define Module BUS Read Signal
Trigger = new DigitalOutput(SPI_socket, GT.Socket.Pin.Five, false, null);
GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
timer.Tick += timer_Tick;
timer.Start();
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
}
void timer_Tick(GT.Timer timer)
{
Trigger.Write(true); // Fire Trigger pulse
mySPI.Write(spidata); // send the SPI buffer
Trigger.Write(false); // Reset trigger
}
}
}