SPI Port Sharing

I have a strange situation. I use 2 different SPI configurations:


static SPI.Configuration config = new SPI.Configuration((Cpu.Pin) FEZCerbuino.Pin.Gadgeteer.Socket1.Pin6,
            false, // Chip Select, active-low
            1000, // 1000 (nanoseconds?) setup time
            1000, // 1000 (nanoseconds?) hold time
            true, // Clock low on idle
            true, // Data valid on falling edge
            625, // 625Khz Clock Rate
            SPI.SPI_module.SPI1);

which I will call A, and


    static SPI.Configuration config = new SPI.Configuration((Cpu.Pin)FEZCerbuino.Pin.Digital.D10, //fake chip select to trick bus
           false, // ChipSelect_ActiveState
           1000, // ChipSelect_SetupTime
           1000, // ChipSelect_HoldTime
           false, // Clock_IdleState
           true, // Clock_Edge
           3000, // Clock_Rate
           SPI.SPI_module.SPI1);

which I will call B.
The difference here is that in A the clock is low when idle and in B the clock is high on idle. When I switch from using A to using B, the first byte always has the MSB high.
e.g. 10001000
and when I switch from B to A all the bits are high except the last bit
e.g. 11111110

Does anyone know what could cause this behavior?

Edited from all bits high to last bit high

What first byte?

By the way your setup and hold times don’t look right. These are milliseconds.

The first byte of any communication. So if the value was supposed to be 0x7E I would get 0xBF; ugh.

@ Arch, I “fixed” this problem just now by switching to a configuration using spi2 then back to spi1. What’s wrong with my setup and hold times? I thought those were nanoseconds.

Scratch that, it’s not fixed.

Also when I initialize a SPI port with module 2 I get an exception (on Cerbuino Bee).

What kind of exception?

The message is:

A first chance exception of type ‘System.ArgumentException’ occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type ‘System.ArgumentException’ occurred in Microsoft.SPOT.Hardware.dll

(the code basically looks like this)


SPI.Configuration spiConfig = new SPI.Configuration((Cpu.Pin)FEZCerbuino.Pin.Digital.D6,
           false, // ChipSelect_ActiveState
           1000, // ChipSelect_SetupTime
           1000, // ChipSelect_HoldTime
           false, // Clock_IdleState
           true, // Clock_Edge
           300, // Clock_Rate
           SPI.SPI_module.SPI2);
SPI spiPort = new SPI(spiConfig);

Do you have a data sheet for your device?

Setup and hold time in your case are 1s each. That is very unusual.

Cerb firmware only supports a single SPI port

Well that explains that. Why just one SPI port when the Cerb40 has so many ports broken out?

Dunno, you will have to ask GHI that…
The Mountaineer firmware has 3 (one is used by flash)

@ Arch, The devices are

[url]http://www.st.com/web/catalog/sense_power/FM142/CL851/SC1794/SS1498/LN1723/PF248592[/url]

and

[url]OEM Wi-Fi Module with Fully Integrated Support for Digi Remote Manager | Digi International

Looks like both devices are capable of higher clock speeds. I would use 5MHz for both. Setup/hold time is in ns range so I would use 0 or try 1 for both parameters. Try to make each device work on its own before using them both on the same bus.

@ Arch, hum… thanks I will.

Next up… find that memory leak.