0

I try to communicate between a raspberry pi 3 running windows 10 IOT build 14376 insiders and a T-REX Manual here using I2C protocol. The thing is that it always crash, so after some debug process I've found that it looks like it doesn't retrieve anything from the DeviceInformation.FinAllAsync(..) and that cause after an ArgumentOutOfRangeException. It should have some thing I don't understand, maybe in the device capabilities or permissions, which Microsoft tutorial doesn't mention here

var settings = new I2cConnectionSettings(0x07);
settings.BusSpeed = I2cBusSpeed.StandardMode;
var aqs = I2cDevice.GetDeviceSelector("I2C1");
var dis = await DeviceInformation.FindAllAsync(aqs);
int a = dis.Count; //is always equal to 0

Then I have a using (I2cDevice device = await I2cDevice.FromIdAsync(dis[0].Id, settings)){...} which fails with the ArgumentOutOfRangeException mentionned before

A second way I tried was using this code:

I2CDevice device;
var settings = new I2cConnectionSettings(0x07);
settings.BusSpeed = I2cBusSpeed.StandardMode;

var controller = await Windows.Devices.I2c.I2cController.GetDefaultAsync();
device = controller.GetDevice(settings);

which produce a NullReferenceException with the last line

Sven Borden
  • 1,070
  • 1
  • 13
  • 29
  • It has nothing to do with the I2C device. Exception is thrown before talking to that slave. – Jackie Jul 17 '16 at 13:47

1 Answers1

2

You might be having the "Direct Memory Mapped Driver" enabled. You need to switch back to "Inbox Driver".

Your code should work just fine with the "Inbox Driver". However, with "Direct Memory Mapped Driver", you have to use the "Microsoft.IoT.Lightning" package to talk to your IoT device.

Follow this tutorial to use "Lightning" library, the way you setup your I2c controller looks like something below,

        if (LightningProvider.IsLightningEnabled)
        {
            LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
        }

        var i2cProvider = LightningI2cProvider.GetI2cProvider();
        var i2cControllers = await I2cController.GetControllersAsync(i2cProvider);
        var i2cController = i2cControllers[0];
        var i2cDevice = i2cController.GetDevice(new I2cConnectionSettings(0x07));

Note that you'll need to include

<iot:Capability Name="lowLevelDevices"/>
<DeviceCapability Name="109b86ad-f53d-4b76-aa5f-821e2ddf2141"/>

in your package manifest file, otherwise you don't have the access to all the serial peripherals.

Follow this tutorial to switch your device driver between "Inbox Driver" and "Direct Memory Mapped Driver".

Cameron Aavik
  • 812
  • 7
  • 21
Jackie
  • 2,032
  • 1
  • 12
  • 14