Main Site Documentation

Is the SPI1 on UEXT?


Can some one confirm that the UEXT on Panda has SPI1 ?


While I can’t 100% confirm by plugging in a SPI device on UEXT, I can 99% be sure that the UEXT header would have been kept as compatible with all the other UEXT headers on all other platforms, so it should be “standard”.


Panda and domino have the exact same pins on UEXT :wink: How is that for freakin’ easy?!


I have a related question (kinda ;)). Would an Eagle layout be available that has just the header positions? I want to make a custom shield for the bottom of my Panda and that would save me, well, about a hundred hours since I know sweet nothing about Eagle :-[ :whistle: Puhleaseeeee?


The design files will be online just like all other FEZes but we can’t put them online before we have the final production version so you have to wait few day


The Domino schematics show the SPI pins on UEXT as MOSI1, MISO1, SSEL1.

I assumed that this means that teh SPI port on UEXT is SPI1. Now SPI1 in NETMF is the chip SPI0. I think that the schematics have to be updated to show SPI2.

I was pulling my hair out until I saw the photograph of the Domino showing the bottom silk screen where it says SPI2.

My Panda has no marking - but now I know.

My post asks the question “Is the SPI1 on UEXT?” and the answer is no. The Domino, Panda and Cobra have SPI2 on UEXT.

HTH Someone.


A comment on the side, Do not take SSEL1 (on the schematic) into consideration when using SPI since the CS signal can be assigned to any InterruptPort.


Actually to any pin. Interrupt is not needed


i’m trying to connect a MCP3208 to a Fez Mini. in the example in beginners guide CS is fez_pin 2x what is that? UEXT CS on mini or some other pin. ? I assume MOSI ect is UEXT.


Connect CLK to SPI SCK (UEXT9)
Connect Din to SPI MOSI (UEXT8)
Connect Dout to SPI MISO (UEXT7)
Connect CS/SHDN to any Digital IO like UEXT10

In your code use SPI1 and put UEXT10 in the ChipSelect field.
Of course you have to make sure how the timing is done with this chip and set the other settings in the SPI code.


Great Info. The MCP3208 is a12 bit Muxed ADC. The library for SPI accepts 8 bit and 16 bit data.
any ideas on how to get 12 bits?

I’m porting some arduino code. since the methods are only writeread() was is written to read the serial buffer? does this cycle the clock?


Take a look at this section in the datasheet
6.1 Using the MCP3204/3208 with Microcontroller (MCU) SPI Ports

It will tell you how to use an 8-bit SPI with this chip.


I’m interfacing an MCP3208 with my Panda and am having some issues with somewhat nonsensical data from the ADC. I have readbuffer[] and writebuffer[] variables I’m using to read and write to the MCP3208, but I’m receiving some unexpected results, so I have a few questions:

The MCP3208 needs to have it’s CS pin cycled before a valid sample can take place. The documentation states: “If the device was powered up with the CS pin low, it must be brought high and back low to initiate communication.” - How can I do this on the Panda? declaring the pin as an output pin and then initiating a new SPI configuration using that previously-declared output pin throws an exception on my Panda.

Do I need to add pullup resistors to MISO/MOSI, or will the panda automatically use it’s internal resistors when I declare the SPI port? The implementation details of the SPI class don’t spell this out, and the beginner guide doesn’t, either.

What are the minimum and maximum SPI speeds that the Panda supports? If I set my panda’s clockrate in the SPI.Config that I’m using to 100Khz, The Panda throws an exception. Alternately, what’s the maximum clock rate that I can use?

Is the data stored in the read byte array stored in the order it’s received? To clarify, is readbuffer[0] filled first, followed by readbuffer[1]? And, within any single byte in the array, are they filled MSB first or LSB first? For example, if I receive a byte from an SPI slave like this: 10101010 Is the data in the Panda’s readbuffer[0] going to be 10101010 or 01010101 ?

is the read byte array filled while the write array is being written to the SPI bus? I’m asking this because my readbuffer[0] is always 0x00 regardless of the input voltage on the ADC inputs. According to the MCP3208’s documentation, the first byte out from the ADC should contain the first 7 out of 12 total bytes sent back from the ADC, along with a preceeding null bit. The Panda always sees readbuffer[0] as 0x00, but readbuffer[1] and readbuffer[2] always have data in them, although I’m still trying to bitshift and bitmask the results into something that resembles the data I’m expecting.


Just issue any transaction on SPI and dump the data. This will take care of cycling CS. Or you can control CS manually using outputPort.

I think max is 18Mhz

Yes, this is how SPI works, it swaps data between teh sides so when you TX you always RX


This is kind of what I’m doing right now - when I setup my SPI port, I do a single read and disgegard the data…

How can you control the CS port manually without lying to the SPI object when you instantiate it? If I use the same pin for my outputPort as I do in my SPI configuration, the Panda throws an exception and exits all running code. I don’t know that exception off the top of my head, but I’m sure I can get it tonight.

Okay; I’m not sure I was clear enough about the question. does the RX byte array get filled while the TX byte array is being sent? I’m not asking about within the same writeRead() in a sequential fashion, I’m asking about the exact same time. As I’m shifting each bit out via my write byte array, is data being shifted into my read byte array?


Set your SPI config to use GPIO_NONE for CS then use the pin anyway you like



Brochure says that SPI1 is on Di11->Di13 and SPI2 on UEXT


Okay, I’m up and running with the MCP3208, but I’m not happy with the lack of speed from the Panda. Regardless of how fast I set my SPI transfer mode, I am only able to sample just over 2.2KHz with the Panda - is this a limitation of the hardware itself or is something else going on?

I’m simply getting data from the MCP3208 via SPI, figuring out what the value is (bitshifting and bitmasking the data from the SPI receive byte array) and then incrementing another integer variable. I’m not outputting anything to the debug window until after 10000 iterations, and then I stop altogether. This takes around 4400Ms to complete, giving me my 2200 samples per second.

Unfortunately, the idea behind me upgrading to the USBizi based hardware was to get better performance than the bit-banging I was doing with an Arduino for my project. The Arduino can log at 2.5KHz with the Atmel chip while sending that data via 56K Serial to a computer. Without any serial transfer, I can log well over 3KHz with the Arduino. And yes, the Arduino is also doing all the same bitwise math as the Panda is doing. What gives?


If you post your code I’m sure someone could give you some pointers. Without seeing exactly how you are doing things it is impossible to make suggestions.


Here you go:

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Time;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.IO;

namespace MCP3208_Reading
    public class Program
        static bool ledState = false;
        static OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);
        static Cpu.Pin SSELPin = (Cpu.Pin)FEZ_Pin.Digital.Di10;
        static SPI spi = new SPI(new SPI.Configuration(SSELPin, false, 0, 0, false, true, 10000, SPI.SPI_module.SPI1));
        static byte[] writeData = new byte[1];
        static byte[] readData = new byte[4];
        static short ADCVal = 0;
        static long sampleCount = 0;
        public static void Main()
            // Init the ADC by doing one measurement, and doing nothing with it (this sample is invalid.)
            spi.Write(new byte[1]);
            // Thread.Sleep(100);

            int startTick = Environment.TickCount;

            while (sampleCount <= 10000)
                writeData[0] = 0x1F; // What are we writing? 0x18 says A0, 0x1F is A7
                spi.WriteRead(writeData, readData, 1); // Skip the first byte

                ADCVal = (short)((readData[0] << 6) + (readData[1] >> 2));
                ADCVal &= 0xfff; // We only want the rightmost 12 bits
                if (sampleCount %1000 == 1)
                    // Debug.Print("0: " + readData[0] + " 1: " + readData[1] + " 2: " + readData[2] + " 3: " + readData[3] + " ADCVal: " + (short)ADCVal);
                    ledState = !ledState;

            int endTick = Environment.TickCount;

            Debug.Print("Time Taken: " + (int)(endTick - startTick));


Removing the modulus operator gets me just over 2600 samples per second, still far short of what I think I should be able to get out of a Panda via SPI. The intention is to log this (and other data) to a SD card; I’m sure that will slow my sample rate down, too.