SPI MISO Monitoring

Hi:
I am building a module that uses SPI. My device needs to monitor MISO on the SPI module being used to determine when data is ready to sample. I would like to write generalized code that could be used on different platforms, and different SPI module assignments. Is there any way to know which pin to assign to a InputPort to enable monitoring before instantiating the SPI?
Thanks

You should use an S (SPI) socket:

Serial peripheral interface (SPI). Pin 7 is the master-out/slave-in (MOSI) line, pin 8 is the master-in/slave-out (MISO) line, and pin 9 is the clock (SCK) line. In addition, pins 3, 4 and 5 are general-purpose input/outputs, with pin 3 supporting interrupt capabilities.

Check out this page for details on all the different sockets and pinouts: http://gadgeteer.codeplex.com/wikipage?title=.NET%20Gadgeteer%20Socket%20Types

Thanks for the reply. I do understand the mapping is invariant in a Gadgeteer module, but I am interested in having the code work on other SoM targets.
The goal is to be able to code a class to interface to an external SPI device that requires monitoring the state of the MISO line when passed only SPI.Configuration?
This is needed as SPI2.MISO is PA21 on a G400-D SoM while it is IO38 on a EMX.

I don’t think that you can initialize an Input port and a SPI using the same pins (Resource conflict). But you might read the CPU register which holds the data.

To find out the GPIO pin you should look at the schematics.

O you could decompile the Gadgeteer code by pressing F12 in VS on socket and follow up types with ReSharper or Redgate Reflector installed until you find the code/const defining the pins.

You should also be aware thet on some boards some SPI pins are not available as GPIO’s (like G120 SPI2).

Hi Reinhard:
You are right that you get a resource conflict, but I first dispose the spi then take the pin reference to make it an input, then when data is ready, I turn it back into an SPI port. There does not seem to be much of a speed penalty.
I will look into the source to see if there are any hints there when I get further along and I will need to deal with the G120 issue you mentioned - it will probably be easier just to pass separate references to the MISO pin and deal with board differences in the calling class.
Thanks

I think I do not understand how you want do this.
The data (each bit) on the input pin is only available as long as the device keeps the high/low level.
If you read it when in GPIO mode there is no more data when you reinitialize SPI.
Looked at from the other side, as soon as SPI gets the hand on the data it will read as long as there is data.

Here is how it works:

    
Public Function ReadVolts() As Single()
        _spi.Dispose()
        Dim s(_SPI_config.Length - 1) As Single  ' SPI.cofigurations defined in class.new

        For i As Integer = 0 To _SPI_config.Length - 1 ' reads 1 or more ADC converters

            Dim cs As New OutputPort(_ChipSelectBarPin(i), False)
            Dim adcout As New InputPort(Pins.GPIO_PIN_D12, False, Port.ResistorMode.Disabled) ' read MISO for conversion complete
            While adcout.Read = True

            End While
            cs.Dispose()    ' dispose up to make available for spi
            adcout.Dispose()

            _spi = New SPI(_SPI_config(i)) ' remake SPI for the intended ADC
            Write7799Reg(&H58)          ' tell the ADC to provide data
            s(i) = ReadAD7799Volts(i)  ' SPI.writeread 3 bytes from SPI and computes the voltage
            _spi.Dispose()
        Next
        Return s

    End Function

This works for the AD7799 by Analog Devices (a 24Bit adc).

Now I understand,

out wait until ADC rings on MOSI.
I would imagine that this should work via the SPI class as well. At least it should.