Use 2 SPI busses simultaneous

Hello,

My FEZ Panda II has 2 SPI busses. I would like to read 2 separate ADC chips (AD7680) at the same time. The important thing is that I want both ADC’s to share the Chip Select signal, since this triggers the AD conversion. If I read the sample code from the sample section, it somehow seems impossible:

(code modified by a suggestion of Brett)


public static void Main()
    {
        SPI.Configuration ConfigDeviceA =
             new SPI.Configuration(Cpu.Pin.GPIO_Pin1,
             false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);
        SPI.Configuration ConfigDeviceB =
             new SPI.Configuration(Cpu.Pin.GPIO_Pin1,
             false, 0, 0, false, true, 1000, SPI.SPI_module.SPI2);
        SPI MySPI = new SPI(ConfigDeviceA);
 
        byte[] tx_data = new byte[10];
        byte[] rx_data = new byte[10];
        // accessing device A
        MySPI.Config = ConfigDeviceA;
        MySPI.WriteRead(tx_data, rx_data);
 
        // accessing device B
        MySPI.Config = ConfigDeviceB;
        MySPI.WriteRead(tx_data, rx_data);
 
    }



Can somebody tell me if it is possible to have both SPI busses work in 2 different threads and read the data as good a simultane?

Thanks,

Erik

you are using SPI1 in both cases. You need to have unique SPI busses.

You may still run into problems though, because the SPI setup may require the CS line to be dedicated, and your setup would not allow it to be unique.

What’s your requirement to be “simultaneous”? how far apart is too far apart?

Hi Brett,

Thanks for your fast reply. I know I need two busses (just copied and paste some code, my error…).

I need to measure simultaneously 2 voltages. Requirement is 200 readings per second. The AD7680 is absolutely fast enough. The AD conversion is started at the CS line going low and then in 24 CLKs the data can be read. Since I have 5 ms for these 24 CLKs, I might do this with software SPI bit banging (5/24 = 200us, should be possible). However I thought since there are 2 seperate SPI ports on the FEZ Panda II, can I not use these?

Hope I explained my problem?

Thanks,

Erik

@ Erik4,

It’s not possible to have two readings simultaneously, unless your uC has 2 cores. Something close might be possible if you use a DMA, but I am new to C# NETMF so somebody else will need to help doing that.

Without any check, I would try to do has follow :

  • Define the 2 SPI buses with each a different CS pin which would not be connected
  • Use a 3rd pin to drive both CS of ADC, and manually toggle them to start conversion
  • Read both ADC in sequence, no need for threads as you are reading back a conversion already done.

Alternatively, use ADC which do not rely on SPI CS to start conversion.

@ Erik4,

There is another method which I have not tried.

Using SPI1 as master and SPI2 as slave.
Connect all SS pins together.
Connect all MOSI pins together but leave the slave SPI2 MOSI disconnected.
Connect MISO on master SPI1 to a ADC chip.
Connect MISO on slave SPI2 to the other ADC chip.

This may work if the incoming data on the slave gets saved to its own cache.

I have no idea if it will work, but it may. It maybe safer to set the slave SPI2 as no SS.
What should happen is SPI1 should initiate both ADC chips for a read.
I really dont know if it would work!
It’s a novel idea and really not the way to use SPI.

Hi everybody,

Thanks for all the input. I will try some things and update this when I find out how to get everything worked.

Erik

Maybe a daisy chain ?

I do not know, but maybe you have to write your own SPI driver for a daisy chain

Lutz