I2C connection to proprietary Hardware

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

I2C connection to proprietary Hardware

Postby Schuerlars » Wed Dec 07, 2011 4:38 pm

Hey guys,

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);
   }



Schuerlars
New User
 
Posts: 4
Joined: Wed Dec 07, 2011 4:17 pm

Re: I2C connection to proprietary Hardware

Postby gloomyandy » Wed Dec 07, 2011 4:41 pm

First off does you hardware have the required pull up resistors installed? If not nothing will work. Note that standard I2C hardware will not have these installed. Secondly what vaoltages are you operating the device i2c bus at. If you are trying to use anything less than about 3v it may not be possible to make it work with the NXT...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3991
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: I2C connection to proprietary Hardware

Postby Schuerlars » Thu Dec 08, 2011 7:18 pm

I didn't use any Pull-Up Resistors so far, so i'll add them to the circuit and see if it works afterwards.

Thank you already for the help.
Schuerlars
New User
 
Posts: 4
Joined: Wed Dec 07, 2011 4:17 pm

Re: I2C connection to proprietary Hardware

Postby gloomyandy » Thu Dec 08, 2011 8:24 pm

Make sure you use the correct values. You need approx 50K-80K... Read the Lego documentation or search the web for more details...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3991
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: I2C connection to proprietary Hardware

Postby Schuerlars » Mon Dec 12, 2011 1:13 pm

I've added two 82k Pull-up-Resistors now and the return value changed from -5 (bus not ready) to -3 (some kind of error while reading?).
So it kind of seems like the hardware is working now, but theres something wrong with the code or maybe with the register i try to read data from?
Schuerlars
New User
 
Posts: 4
Joined: Wed Dec 07, 2011 4:17 pm

Re: I2C connection to proprietary Hardware

Postby gloomyandy » Mon Dec 12, 2011 2:26 pm

Looking at the data sheet it would seem that the address is 0xD0 (not 0xD1 the low order bit is used to set read or write mode). It also looks like the device does not have any internal register addressing so to read data from it you simply need to issue an i2c read request. This means that you can not use the getData method as this can only be used when talking to a device that uses register addressing. You will have to use the lower level i2cTransaction method...
http://lejos.sourceforge.net/nxt/nxj/ap ... action(int, byte[], int, int, byte[], int, int)

I think the device can return 3 bytes of data (2 data bytes followed by a control byte). So something like...
port.i2cTransaction(0xd0, null, 0, 0, inBuffer, 0, 3);
may do the trick... But without access to the device it is hard to tell. You may want to search the forum and the web to see if any other leJOS users have used this device.

Good luck

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3991
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: I2C connection to proprietary Hardware

Postby Schuerlars » Mon Dec 12, 2011 6:40 pm

Alright, i'll try with the lower level method, wich looks way better to me since there is no register to use.
Thanks for your help. =)
Schuerlars
New User
 
Posts: 4
Joined: Wed Dec 07, 2011 4:17 pm


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 3 guests

more stuff