Hi, I am sending (0x1A00) to the IMU in order to read the temperature value (which I expect it to be encoded as 207), but somehow I got sometimes 1 value, 2 values and sometimes nothing !!
Here is the output:
Here is the code:
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 GTI = Gadgeteer.Interfaces;
using Gadgeteer.Modules.GHIElectronics;
using System.IO;
using Microsoft.SPOT.IO;
using GHI.OSHW.Hardware;
using Microsoft.SPOT.Hardware;
namespace GadgeteerApp7
{
public partial class Program
{
//SPI
static GT.Socket _socket;
static GTI.SPI.Configuration _config;
static GTI.SPI _spi;
// This method is run when the mainboard is powered up or reset.
public void ProgramStarted()
{
// SPI Config
_socket = GT.Socket.GetSocket(1, true, null, null);
_config = new GTI.SPI.Configuration(true, 0, 0, true, true, 1000);
_spi = new GTI.SPI(_socket, _config, GTI.SPI.Sharing.Exclusive, _socket, GT.Socket.Pin.Five, null);
while (true)
{
// SPI Reading
byte[] BytesWrite = new byte[] { 0x1A , 0x00 };
byte[] SPIBuffer = new byte[2];
_spi.WriteRead(BytesWrite, SPIBuffer);
// SPI writing to SD
Debug.Print("IMU Message: ");
Debug.Print(SPIBuffer[0].ToString());
Debug.Print(SPIBuffer[1].ToString());
Thread.Sleep(1000);
}
}
}
}
Which board are you using? The Cerberus firmware had broken SPI for a long time. Not sure if they ever fixed it. I submitted a patch on the forum, but I’m not sure it ever made it into the firmware. The problem I was having was that the clock line would start running before the cs pin asserted. Simple fix in the firmware, but it obviously involves compiling the firmware from the porting kit: a daunting task for most people.
I think that there’s no point testing any further. Gus tells you there were many SPI fixes in the 4.2 series of framework updates. The one I point to is the newest. You aren’t using that. Unless you want to manually go through the release notes and see where it’s mentioned that there was a fix, but even then you’re still going to need to move forward, so go to the latest.