运行Windows 10 IoT的rasberry pi 2上的多个(4x)SPI设备 [英] Multiple (4x) SPI device on rasberry pi 2 running windows 10 iot

查看:141
本文介绍了运行Windows 10 IoT的rasberry pi 2上的多个(4x)SPI设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功通信了单个SPI设备(MCP3008).可以在具有Windows 10 IoT的rapiberry pi 2上运行多个(4x)SPI设备吗?

I had successfully communicate single SPI device (MCP3008). Is that possible running multiple (4x) SPI device on raspberry pi 2 with windows 10 iot?

  1. 我正在考虑手动连接CS(片选)线并在调用spi函数之前将其激活,并在完成spi函数后使其不活动. 可以在Windows 10物联网上工作吗?
  2. 如何配置spi芯片选择引脚?在SPI初始化期间更改引脚号?有可能吗?
  3. 在Windows 10物联网上使用多个(4 x MCP3008)SPI设备的更聪明的方法吗?
  1. I'm thinking to manually connect the CS(chip select) line and activate it before calling spi function and in-active it after done the spi function. Can it be work on windows 10 iot?
  2. How about configure the spi chip select pin? Change the pin number during the SPI initialization? Is that possible?
  3. Any smarter way to use multiple (4 x MCP3008 ) SPI device on windows 10 iot?

(我打算监视32个模拟信号,这些信号将输入到运行Windows 10 IoT的raspberry pi 2中)

(I'm planning to monitor 32 Analogue signal which will be input to my raspberry pi 2 running windows 10 iot)

非常感谢!

推荐答案

当然,您可以根据需要使用任意数量(可以使用尽可能多的GPIO引脚). 您只需要指明要呼叫的设备即可.

Of course you can use as many as you want (as many GPIO pins). You just have to indicate the device to which you are calling.

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

First, set the configuration of the SPI for example, using chip select line 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类配置输出端口,该类将用于指示设备.

You can not use this pin in further actions! So now you should configure the output ports using GpioPin class, which you will use to indicate the device.

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);

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

Always before transfer indicate device: (example method)

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;
}

这篇关于运行Windows 10 IoT的rasberry pi 2上的多个(4x)SPI设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆