Thank you for your help.
I have a Panda II and all seems well except when I try to use SPI, I get the same result in the input array all the time. I have an old ‘scope’ and I can see the clock lines as well as data lines. But, I always get the same two bytes of data. I grounded the input data line, expecting data to go to 0x00, 0x00 but it did not change.
I must be doing something wrong.
My simple test code is below:
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.Threading;
using GHIElectronics.NETMF.FEZ;
namespace MFConsoleApplication1
{
public class Program
{
static OutputPort MyLED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);
static OutputPort CS_N = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di9, true);
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.Di10,
false,
20,
20,
false,
true,
200,
SPI.SPI_module.SPI1); // 200k bits n
// Create SPI object here
SPI MySPI = new SPI(MyConfig);
string errormsg = string.Empty;
byte[] StartConversion = { 0x24, 0x00 };
byte[] ReadPresMSB = { 0x80 , 0x00 };
byte[] ReadPresLSB = { 0x82 , 0x00 };
byte[] DummyBytes = new byte[2]; // receive the two bytes of SPI
bool LEDstate = true;
byte[] PresMSB = new byte[2];
byte[] PresLSB = new byte[2];
int pResult = 0;
int MSB = 0;
int LSB = 0;
for (int x = 0; x < 300000; x++) // run a long time, but not forever
{
// MySPI.Write(StartConversion);
MySPI.WriteRead(StartConversion, DummyBytes); // Send and receive SPI data
Thread.Sleep(200); // wait 200 ms for conversion
LEDstate = !LEDstate; // visual confirmation of running
MyLED.Write(LEDstate);
MySPI.WriteRead(ReadPresMSB, PresMSB);
MySPI.WriteRead(ReadPresLSB, PresLSB);
CS_N.Write(true);
MSB = ReadPresMSB[0];
LSB = ReadPresLSB[0];
pResult = (Int16)(((MSB << 2)) & 0x03fc) + (Int16)((LSB << 2) & 0x0003);
Debug.Print(pResult.ToString());
}
}
}
}