.NET MF_HW I2C_CerbuinoBee NXShield-Dx


I need to help with code and adress explanation for communication:
FEZ Cerbuino Bee/NXShield-Dx(with sensor attached to BAS1 connector);

NXShield developer guide:

I have this information:
[ul]On Cerbuino I want to use HW I2C with NXShield BAS1, so: SDA - PIN A4; SCL - PIN A5[/ul][ul]NXShield BankA has adress 0x06[/ul][ul]Each bank appears as set of registers: 0x00-0x07 FW ver.; 0x08-0x0f Vendor ID; 0x10-0x17 Device ID;[/ul][/quote]

So Iam using generated Gadgeteer project which works correctly with gadgeteer CharDisplay. Now I want to communicate and at first at least read Device ID of attached sensor at BankA-BAS1. I tried to use first example from: https://www.ghielectronics.com/docs/12/i2c with

 and debug output:
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll
when at 
```cs]I2CDevice MyI2C = new I2CDevice(con);[/code

I dont know how to adress sensors, for example, LSB, which has adress 0x8C, attached to BankA(0x06) BAS1


@ DejvikCZ - Have you tried setting the bus speed to 100 or 400? I’ve never seen a speed of 168000 before and I don’t think our devices support it.

Hello John,

I thought it is core speed which will be computed to baud rate :\ Iam using second parameter as 400 from now on.
But I still dont know and need little explanation on how to choose first parameter, if I want to communicate with I2C via A4 and A5 PINs.


@ DejvikCZ - You’ll want to find the 7-bit address specified in the datasheet of your device and use that for the first parameter. It looks like it might be 0x06 based on the snippet you posted.

Okay, thank you. I will report my mistake when I found it :slight_smile:


my problem has changed a little…
I still need to get working I2C throught Arduino header via analog A4 PIN and analog A5 PIN.
But I am using new MF version and analog PINs are there accesed as channels, not pins.
Code, which i need to get working is below:

public  Cpu.AnalogChannel BAS1_Clock = (Cpu.AnalogChannel)5;
        public  Cpu.AnalogChannel BAS1_Data = (Cpu.AnalogChannel)4;

public II2c GetI2c(MotorPlug plug)
            if (_i2cs[0] == null)
                _i2cs[0] = new SoftwareI2c(PinMap.BAS1_Clock, PinMap.BAS1_Data, 0);
            return _i2cs[0];

public SoftwareI2c(Cpu.AnalogChannel scl, Cpu.AnalogChannel sda, int clock)
            Start = false;
            TimeOutTicks = (long)TimeOut * TimeSpan.TicksPerMillisecond;
            SCL = new TristatePort(scl, false, false, Port.ResistorMode.PullUp);
            SDA = new TristatePort(sda, false, false, Port.ResistorMode.PullUp);
            // scl and sda default to input, the next 2 lines make this explicit.
            I2CSpeed = 30;

So SCL and SDA in this I2C are managed to be treated as pullup PINs, but I cant acess them as PINs (can I?). So is there any MF way to get I2C working with AnalogChannel? Or can I read and write on analog arduino header PINs as PINs, not channels?

Have a nice day

the “analog” pins are just pins, they happen to have multiple uses, including analog, but they’re just digital pins. If you use them as analog pins then you can’t use them as digital pins, so instead of defining them as Cpu.AnalogChannel you just define them as Cpu.Pin.