0

I follow the document from Microsoft as below: https://learn.microsoft.com/en-us/windows/iot-core/learn-about-hardware/pinmappings/pinmappingsrpi Here is the code:

using Windows.Devices.Enumeration;
using Windows.Devices.Spi;

public async void SPI()
{
    // 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("SPI0");

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

This code can build successful. But it does not work in Raspbian with Mono. Looking around, I follow this: https://github.com/dotnet/iot/issues/1089

The way to migrate is to remove all references to winmds and System.Runtime.WindowsRuntime and System.Runtime.InteropServices.WindowsRuntime and instead just reference the Microsoft.Windows.SDK.NET package.

But it fail to build because of below error:

The type 'IAsyncAction' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'

I read below link, but it could not help. IAsyncOperation await in Windows Service: "Type is defined in an assembly that is not referenced..."

VnPower
  • 1
  • 1
  • The serial port has to be configured in the startup configuration. When starting the Raspberry for debugging you should be connecting first to the console port so you can monitor any errors when starting. The console port should be automatically configured. The console should automatically be configured. Use Putty from a working PC to connection to the console port. I'm not sure if you are trying to connect to the console or to a different serial port. See : https://pinout.xyz/pinout/spi. The console port info should tell you what devices are being configured. – jdweng Jun 27 '21 at 13:14
  • of course the SPI is enabled. I using wiringPi library and code with C language, the SPI0 working fine. Then I try to using wiringPi library in C#, it's not working as I expected, sometimes the data is missing Then I try to use Windows.Devices.Spi and I got this problem – VnPower Jun 27 '21 at 14:57
  • I have Pi 3A as a SPI master (SPI0 CS0), and ESP32 as a slave. The code using wiringPi (work fine) – VnPower Jun 27 '21 at 15:27
  • Is the device already opened? Did you check the baud rate and settings? I would think if the device is already opened you would get an error. So it is more likely the settings are wrong (baud, no parity, one stop) Or the wiring is wrong. How are you checking that code is not sending? What do you mean the sometimes data is missing? Let try to figure out the intermittent problem first. – jdweng Jun 27 '21 at 17:52
  • The namespaces `Windows.*` are UWP only (aka Windows only), https://learn.microsoft.com/en-us/uwp/api/windows.devices.enumeration?view=winrt-20348 So it is impossible to use them on Mono. – Lex Li Jul 03 '21 at 04:53

0 Answers0