SpiConnectionSettings 클래스

정의

SpiDevice와의 연결에 대한 설정을 나타냅니다.

public ref class SpiConnectionSettings sealed
/// [Windows.Foundation.Metadata.Activatable(Windows.Devices.Spi.ISpiConnectionSettingsFactory, 65536, Windows.Devices.DevicesLowLevelContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Devices.DevicesLowLevelContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class SpiConnectionSettings final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Devices.DevicesLowLevelContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Activatable(Windows.Devices.Spi.ISpiConnectionSettingsFactory, 65536, "Windows.Devices.DevicesLowLevelContract")]
class SpiConnectionSettings final
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Devices.Spi.ISpiConnectionSettingsFactory), 65536, typeof(Windows.Devices.DevicesLowLevelContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Devices.DevicesLowLevelContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class SpiConnectionSettings
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Devices.DevicesLowLevelContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Devices.Spi.ISpiConnectionSettingsFactory), 65536, "Windows.Devices.DevicesLowLevelContract")]
public sealed class SpiConnectionSettings
function SpiConnectionSettings(chipSelectLine)
Public NotInheritable Class SpiConnectionSettings
상속
Object Platform::Object IInspectable SpiConnectionSettings
특성

Windows 요구 사항

디바이스 패밀리
Windows IoT Extension SDK (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Devices.DevicesLowLevelContract (v1.0에서 도입되었습니다.)

예제

다음 샘플에서는 기본 연결 설정을 사용하여 식별 이름으로 SPI 버스를 여는 방법을 보여 줌으로써 이 API 및 기타 SPI API의 기본 기능을 보여 줍니다.

// Arduino SPIDigialPot example: http://arduino.cc/en/Tutorial/SPIDigitalPot 
// using digital potentiometer AD5206 the 50kohm variance 
async void Digipot_AD5206() 
{ 
    // Get a device selector query that will select buses with SP10 
    // property set on them (we expect only 1 SP10 bus at the end) 
    var spi0Aqs = SpiDevice.GetDeviceSelector("SPI0"); 
    // Find all buses using the AQS query formed above 
    var devicesInfo = await DeviceInformation.FindAllAsync(spi0Aqs); 

    // Construct time settings beforehand which can't be changed 
    // once a SPI device is created 
    const Int32 DigipotChipSelectLine = 0; 
    var settings = new SpiConnectionSettings(DigipotChipSelectLine); 

    // Ask the SPI bus to open a device with the connection settings 
    // provided. Once we go out of scope, the device will be released 
    using (var spiDev = await SpiDevice.FromIdAsync(devicesInfo[0].Id, settings)) 
    { 

        // data[0] is the channel address 
        // data[1] is the resistance step (0 - 255) 
        // 0 is max digipot resistance, and 255 is no resistance 
        byte[] data = { 0x0, 0x0 }; 

        // Go over the 6 channels of the digipot 
        for (byte channel = 0; channel < 6; ++channel) 
        { 
            data[0] = channel; 

            // Step the resistance on this channel from max to min 
            for (byte r = 0; r <= 255; ++r) 
            { 
                data[1] = r; 
                spiDev.Write(data); 
                await Task.Delay(100); 
            } 

            // Step the resistance on this channel from min to max 
            for (byte r = 255; r >= 0; --r) 
            { 
                data[1] = r; 
                spiDev.Write(data); 
                await Task.Delay(100); 
            } 
        } 
    } 
} 

다음 샘플에서는 이 API 및 기타 SPI API를 사용하여 기본 연결 설정이 아닌 SPI 디바이스를 초기화하는 방법을 보여 줍니다. 8채널 10비트 ADC108S102 A/D 컨버터에 연결된 아날로그 포토셀에서 광강도를 읽어 이 작업을 수행합니다.

참고

이 샘플에는 위의 디바이스와 관련된 여러 설정이 포함되어 있습니다. 특정 디바이스를 고려하도록 이러한 설정을 변경해야 할 수 있습니다. instance 경우 Raspberry Pi 디바이스는 SPI에 대해 최대 8/9비트 길이를 지원합니다.

// Knowing that an SPI bus with 'spiBusId' exist, and has the ADC connected 
// on 'chipSelectLine', read a digital sample from some sensor wired to 'channel' 
async Task<int> AnalogRead_ADC108S102(string spiBusId, Int32 chipSelectLine, byte channel) 
{ 
    var settings = new SpiConnectionSettings(chipSelectLine); 

    // The defaults (4MHz, 8-bit, Mode0) will not work here according 
    // to the datasheet. 
    // e.g The datasheet specifies a clock freq range (8MHz - 16MHz) 
    settings.ClockFrequency = 8000000; 
    // CPOL=1, CPHA=1 
    settings.Mode = SpiMode.Mode3; 
    // Conversion happens on a 16-bit frame 
    settings.DataBitLength = 16; 
    // The ADC108S102 has 8 input analog channels, where each can be 
    // connected to a specific analog sensor and each sensor is 
    // used by a different application independently 
    // The IO requests to the SPI bus are implicitly synchronized 
    // by the driver model, plus that the ADC configuration is per 
    // 1 sampling read 
    settings.SharingMode = SpiSharingMode.Shared; 

    // Ask the SPI bus to open a shared device with the connection settings 
    // provided. 
    using (var spiDev = await SpiDevice.FromIdAsync(spiBusId, settings)) 
    { 
        if (spiDev == null) 
            return -1; 

        // Set up control register to get a conversion on a specific 
        // channel address 
        byte[] write16bitData = { (byte)(channel << 3), 0 }; 
        byte[] read16bitData = new byte[2]; 
        // The transfer is guaranteed to be atomic according to SpbCx model 
        spiDev.TransferFullDuplex(write16bitData, read16bitData); 

        ushort result = BitConverter.ToUInt16(read16bitData, 0); 
        // Get rid of the 2 LSB zeros and mask the 10-bit sampled value 
        return (int)((result >> 2) & 0x3ff); 
    } 
} 

생성자

SpiConnectionSettings(Int32)

SpiConnectionSettings의 새 instance 초기화합니다.

속성

ChipSelectLine

SPI 디바이스 연결에 대한 칩 선택 선을 가져오거나 설정합니다.

ClockFrequency

연결의 클록 빈도를 가져오거나 설정합니다.

DataBitLength

이 연결의 데이터에 대한 비트 길이를 가져오거나 설정합니다.

Mode

이 연결에 대한 SpiMode 를 가져오거나 설정합니다.

SharingMode

SPI 연결에 대한 공유 모드를 가져오거나 설정합니다.

적용 대상