I am trying to write a driver for the MikroE Proximity 11 Click and ran into a bit of a roadblock initializing the RPR-0521RS IC on the Proximity 11 Click.
Using a SC20260 based board (FezPortal and SC20260 Dev Board) I cannot get the RPR-0521RS IC to respond to I2c commands on the I2cBus.I2c1 and returns all zeros on either board.
However, it works just fine on the other I2c busses (I2c2 and I2c3).
I accidentally stumbled across a solution by adding in an extra zero in the I2cConnectionSettings by setting the bus speed to 4_000_000 and that worked and I was able to read a few known registers and verify the register contents. Running the same code at 400_000 does not work.
I tried the code on the SC20100 Dev board an it initializes at 400_000 just fine.
So I am stumped at this point and can only conclude the differences between I2c1 and I2c2 and three is that I2c1 has pull up resistors whereas I2c2 and I2c3 do not. I have not checked the schematic for the SC20100 DEV board to determine if it has the pull-up resistors or not.
I am running the latest firmware and using a Revision 3 SC20260 Dev Board.
Here is the code I am using to demonstrate the problem I am encountering.
internal class Program
{
private static void Main()
{
// This initialization works with the I2cBus Speed set to 2_850_000.
//I2cDevice _sensor = I2cController.FromName(GHIElectronics.TinyCLR.Pins.SC20260.I2cBus.I2c1).GetDevice(new I2cConnectionSettings(0x38, 2_850_000));
// This does not work with the I2cBus Speed set to 400_000.
I2cDevice _sensor = I2cController.FromName(GHIElectronics.TinyCLR.Pins.SC20260.I2cBus.I2c1).GetDevice(new I2cConnectionSettings(0x38, 400_000));
Thread.Sleep(2); // Per Datasheet, need 2ms before accessing the RPR-0521RS.
Byte[] registerData = new Byte[1];
_sensor.WriteRead(new Byte[] {0x42}, registerData);
Debug.WriteLine($"Register 0x42 is 0x{registerData[0]:x2} and should be 0x02");
_sensor.WriteRead(new Byte[] {0x43}, registerData);
Debug.WriteLine($"Register 0x43 is 0x{registerData[0]:x2} and should be 0x01");
_sensor.WriteRead(new Byte[] {0x4b}, registerData);
Debug.WriteLine($"Register 0x4b is 0x{registerData[0]:x2} and should be 0xFF");
}