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 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?
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.
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.