4

I am trying to troubleshoot an I2C device connected to my Raspberry PI Model B.

The device is giving me the following error:

System.IO.FileNotFoundException: The system cannot find the file specified. Slave address was not acknowledged.

Googling around it seems that it is a generic error message and means that the device is not working. I'd like to troubleshoot this and a Windows version of i2cdetect would be useful.

Further, should an I2C device, once connected correctly, show up in the devices in the Win10 IOT web interface?

Thanks

1 Answer 1

3

Microsoft have a short walkthrough on achieving this using their premade i2cTestTool.

I took a look over the documentation for the WinIoT device manager. I think that i2c devices should show up there, but I can't yet pin down a sentence that definitively says it will.

UPDATE

Per your comment, running the i2cTestTool with the -list parameter will not enumerate devices attached to the controller. I think that using the -info parameter will do that. Alternately, you could run multiple passes of the tool to eliminate non-working addresses.

As a second option, this thread on the raspberrypi.org forum includes a C# method, written by user vidalsasoon at 27/09/15 1:46pm, which attempts to write data to each address and returns success or fail on each attempt. This should enumerate all the devices attached to a controller:

public async Task<bool> FindI2CAddressesAsync(Func<Message, Task> onMessageReceived)
{
    string aqs = I2cDevice.GetDeviceSelector("I2C1");

    var i2CDevices = await DeviceInformation.FindAllAsync(aqs).AsTask().ConfigureAwait(false);
    if (i2CDevices.Count == 0)
    {
        await onMessageReceived(new Message("bus not found")).ConfigureAwait(false);
        return false;
    }

    for (byte slaveAddress = 0x00; slaveAddress <= 0x7F; slaveAddress++)
    {
        var settings = new I2cConnectionSettings(slaveAddress)
        {
            BusSpeed = I2cBusSpeed.FastMode,
            SharingMode = I2cSharingMode.Shared
        };

        foreach (var i2CDevice in i2CDevices)
        {
            var i2CDeviceDetails = await I2cDevice.FromIdAsync(i2CDevice.Id, settings).AsTask().ConfigureAwait(false);

            try
            {
                var testCommand = new byte[] { 0x00, 0x0 };
                      i2CDeviceDetails.Read(testCommand);

                await onMessageReceived(new Message($"SlaveAddress: {settings.SlaveAddress:X} SUCCESS \n"));
            }
            catch(Exception)
            {
                await onMessageReceived(new Message($"SlaveAddress: {settings.SlaveAddress:X} FAILED \n"));
            }
        }
    }

    return false;
}
3
  • Thanks - do you know if the -list option will show devices attached to the controller, or just tell me that my Pi has an I2C controller - which I already know :) Jun 8, 2016 at 9:34
  • Perhaps a stupid question about your answer, but I have ran the code and did find a device, however the loop did not respond to any slaveAddress. So could you explain the 0x7F value of the end of the loop parameter? Aug 15, 2018 at 8:31
  • 0x7f is 127. So it loops from 0 to 127 because there can be up to 128 devices to I2c. If anyone wondered like me ;) still have no clue why I can't find a slaveaddress. Aug 15, 2018 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.