i've got some problems concerning a I2C connection to a proprietary hardware.
The hardware is a differential amplifier connected to an AD-Converter with an I2C Interface. The AD-Converter is an MCP 3426.
When i try to read from the Converter i always get the return value -5, wich is an error code for "the bus is busy" (or no device found). Im sure about using the correct address, since its mentioned in the datasheet (0xD1), but in the datasheet you can not find anything about an register address for an output register so i just assumed it might just start with the address 0x00 (wich might already be the mistake).
I already tried to read data from the AD-Converter using a C-Code with an ARM7 (not with NXT Brick) without using an defined registeraddress. It worked quite well and i've got the data from the device.
I would be glad if anybody would have an idea. Beside i post you guys the code i actually use.
- Code: Select all
public class SensorTest extends I2CSensor{
;
byte[] buf = new byte[1];
public SensorTest(I2CPort port){
super(port, 0xD1, I2CPort.LEGO_MODE, TYPE_LOWSPEED_9V);
}
public int getI2CData(){
int register = 0x00;
Delay.msDelay(50);
int ret = super.getData(register, buf, 1);
if(ret != 0){
LCD.drawString("Error: " + ret, 0, 1);
} else {
LCD.drawString("", 0, 1);
}
return (0xFF & buf[0]);
}
public static void main(String[]args){
SensorTest sensor = new SensorTest(SensorPort.S1);
while(true){
int value = sensor.getI2CData();
LCD.drawString(""+ Integer.toHexString(value), 0, 0);
}
