1

我已成功通信单个 SPI 设备(MCP3008)。是否可以在带有 Windows 10 iot 的树莓派 2 上运行多个 (4x) SPI 设备?

  1. 我正在考虑手动连接 CS(片选)线并在调用 spi 函数之前将其激活,并在完成 spi 函数后将其停用。它可以在 Windows 10 iot 上运行吗?
  2. 怎么配置spi片选管脚?在 SPI 初始化期间更改引脚号?那可能吗?
  3. 在 windows 10 iot 上使用多个 (4 x MCP3008) SPI 设备的任何更智能的方法?

(我打算监控 32 个模拟信号,这些信号将输入到运行 windows 10 iot 的树莓派 2 中)

非常感谢!

4

2 回答 2

0

当然,您可以根据需要使用任意数量的 GPIO 引脚。您只需指明您呼叫的设备。

首先,设置SPI的配置例如,使用片选线0

settings = new SpiConnectionSettings(0); //chip select line 0
settings.ClockFrequency = 1000000;
settings.Mode = SpiMode.Mode0;

String spiDeviceSelector = SpiDevice.GetDeviceSelector();
devices = await DeviceInformation.FindAllAsync(spiDeviceSelector);
_spi1 = await SpiDevice.FromIdAsync(devices[0].Id, settings);

您不能在进一步的操作中使用此引脚!因此,现在您应该使用 GpioPin 类配置输出端口,您将使用它来指示设备。

GpioPin_19 = IoController.OpenPin(19);
GpioPin_19.Write(GpioPinValue.High);
GpioPin_19.SetDriveMode(GpioPinDriveMode.Output);

GpioPin_26 = IoController.OpenPin(26);
GpioPin_26.Write(GpioPinValue.High);
GpioPin_26.SetDriveMode(GpioPinDriveMode.Output);

GpioPin_13 = IoController.OpenPin(13);
GpioPin_13.Write(GpioPinValue.High);
GpioPin_13.SetDriveMode(GpioPinDriveMode.Output);

始终在传输前指示设备:(示例方法)

private byte[] TransferSpi(byte[] writeBuffer, byte ChipNo)
{
    var readBuffer = new byte[writeBuffer.Length];

    if (ChipNo == 1) GpioPin_19.Write(GpioPinValue.Low);
    if (ChipNo == 2) GpioPin_26.Write(GpioPinValue.Low);
    if (ChipNo == 3) GpioPin_13.Write(GpioPinValue.Low);

    _spi1.TransferFullDuplex(writeBuffer, readBuffer);

    if (ChipNo == 1) GpioPin_19.Write(GpioPinValue.High);
    if (ChipNo == 2) GpioPin_26.Write(GpioPinValue.High);
    if (ChipNo == 3) GpioPin_13.Write(GpioPinValue.High);

    return readBuffer;
}
于 2017-02-28T00:05:22.447 回答
-1

来自:https ://projects.drogon.net/understanding-spi-on-the-raspberry-pi/

树莓派此时只实现主模式,有2个片选引脚,所以可以控制2个SPI设备。(尽管有些设备有自己的子寻址方案,因此您可以将更多设备放在同一总线上)

我已经在J​​ared Bienz的IoT 设备 GitHub存储库中的DeviceTester 项目和Breathalyzer项目中成功使用了 2 个 SPI 设备。

请注意,在每个项目中,SPI 接口描述符在这两个项目中使用的 ADC 和 Display 的 ControllerName 属性中显式声明。可以在我的博客上找到有关 Breathalyzer 项目的详细信息。

    // ADC
    // Create the manager
    adcManager = new AdcProviderManager();

    adcManager.Providers.Add(
        new MCP3208()
        {
            ChipSelectLine = 0,
            ControllerName = "SPI1",
        });

    // Get the well-known controller collection back
    adcControllers = await adcManager.GetControllersAsync(); 

    // Create the display
    var disp = new ST7735()
    {
        ChipSelectLine = 0,
        ClockFrequency = 40000000, // Attempt to run at 40 MHz
        ControllerName = "SPI0",
        DataCommandPin = gpioController.OpenPin(12),
        DisplayType = ST7735DisplayType.RRed,
        ResetPin = gpioController.OpenPin(16),

        Orientation = DisplayOrientations.Portrait,
        Width = 128,
        Height = 160,
    };
于 2016-02-26T18:38:19.590 回答