UWP 上通过 GPIO 的 SPI

SPI over GPIO on UWP

我尝试在 Raspberry Pi 3.
上将 max7219 与 UWP 应用程序 运行ning 集成 max7219 连接到以下引脚:

原生SPI端口:19、21、23、24、26忙于触摸板
我没有找到如何配置 .NET Windows.Devices.SerialCommunication.SerialDevice 以使用 GPIO 端口,所以我从 Arduino 移植 shiftOut 如下:

    private void shiftOut(BitOrder aBitOrder, byte val)
    {
        if (aBitOrder == BitOrder.LSBFIRST) {
            for (byte i = 0; i < 8; i++)
            {
                GpioPinValue __val = (val & (1 << i)) == 0x0 ? 
                    GpioPinValue.Low : 
                    GpioPinValue.High;

                _data_pin.Write(__val);
            }
        } else {
            for (byte i = 0; i < 8; i++)
            {
                GpioPinValue __val = (val & (1 << (7 - i))) == 0x0 ? 
                    GpioPinValue.Low : 
                    GpioPinValue.High;

                _data_pin.Write(__val);
            }
        }

        _clock_pin.Write(GpioPinValue.High);
        _clock_pin.Write(GpioPinValue.Low);
    }

过去该项目在 Arduino Avr 上 运行ning 并通过 shiftOut 函数使用 GPIO 端口。

现在,我运行项目结束Raspberry Pi 3.我向芯片提供以下数据:

{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x1, 0x01, 0x01 },
{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x1, 0x01, 0x01 }

但是表盘上的 LED(由 max7219 管理)以混乱的方式闪烁
根据芯片的数据 sheet 我认为,问题是 - Raspberry 处理器的频率。

Arduino 运行s 的频率约为 50 MHz,而 Rasbpery Pi 3 运行s 的频率为 1.4 GHz。 Tcl,Tch等值在Arduino上是可以接受的,可能是微秒左右,但在Raspberry上可能是1或2纳秒。

下一个问题是 - 我无法在写入之间插入足够短的停顿,最短停顿可能是一毫秒,我觉得这对 SPI 标准来说太多了:

_clock_pin.Write(GpioPinValue.High);
Task.Delay(-1).Wait(1);  
_clock_pin.Write(GpioPinValue.Low);

另一个问题,我 运行 项目是 Visual Studio 2015,所以我不能像 RaspberrySharp 和其他的那样使用 Nuget 库。
有什么办法可以解决?

Raspberry Pi3上有两个原生SPI,可以使用SPI1:

使用SPI1的代码示例:

// Use chip select line CS0
var settings = new SpiConnectionSettings(0);
// Set clock to 10MHz 
settings.ClockFrequency = 10000000;

// Get a selector string that will return our wanted SPI controller
string aqs = SpiDevice.GetDeviceSelector("SPI1");

// Find the SPI bus controller devices with our selector string
var dis = await DeviceInformation.FindAllAsync(aqs);

// Create an SpiDevice with our selected bus controller and Spi settings
using (SpiDevice device = await SpiDevice.FromIdAsync(dis[0].Id, settings))
{
    byte[] writeBuf = { 0x01, 0x02, 0x03, 0x04 };
    device.Write(writeBuf);
}