test high speed I2C mode

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

Moderators: 99jonathan, roger, imaqine

test high speed I2C mode

Postby Aswin » Mon May 30, 2011 9:20 pm

Hi,

I want to test the high speed mode of an I2C sensor. What is the meaning of the third and fourth parameter of the constructor below? And what values should I supply for both parameters to test high speed mode?
Code: Select all
I2CSensor(I2CPort port, int address, int mode, int type)
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: test high speed I2C mode

Postby gloomyandy » Mon May 30, 2011 10:04 pm

Hi,
See this tutorial topic for a little more information:
http://lejos.sourceforge.net/nxt/nxj/tu ... rdware.htm
The type of the sensor is basically the overall use of the sensor port. For i2c devices this should be one of TYPE_LOWSPEED (for 5v sensors) or TYPE_LOWSPEED_9V (for 9V sensors). These names come from the Lego firmware.

The mode field specifies the i2c operating mode and should be one of LEGO_MODE, STANDARD_MODE, HIGH_SPEED, these values can also be combined with the value NO_RELEASE and ALWAYS_ACTIVE, but it is unlikely you will need either of these modifiers. They are defined here:
http://lejos.sourceforge.net/nxt/nxj/ap ... CPort.html

So in your case you probably want TYPE_LOWSPEED, for the type and HIGH_SPEED for the mode (yes that is a little confusing!).

However given that you can have multiple sensors attached to the same i2c port and the above attributes are really port based not sensor based, it arguably does not make sense to use the sensor constructor to set them. Basically the first active sensor for a port will set the operating mode by calling the i2cEnable method, this mode will stay in force until all of the sensors have released the port... So I tend to set things up so the actual sensor class uses LEGO_MODE (as this is compatible with all other Lego i2c sensors), then if I want to use a particular port in high speed mode I set the port mode explicitly by making a call to SensorPort.S1.i2cEnable(HIGH_SPEED) before creating the actual sensor classes attached to port 1. This will force all sensors attached to port 1 to use high speed mode. Note that if you connect multiple sensors to the same port they should all use the same voltage, and if you use high speed mode they must all be capable of operating in this mode (the Lego Ultrasonic sensor is not)...

Hope the above makes some sort of sense...

Andy

PS If your sensor does not work with the 0.9.0 release in high speed mode, it may be that it requires pulse stretching, I've just updated the firmware (after 0.9.0) to support this operating mode, you can grab a copy of the latest firmware file from here:
http://lejos.svn.sourceforge.net/viewvc ... n?view=log
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3997
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: test high speed I2C mode

Postby Aswin » Mon May 30, 2011 11:29 pm

Thanks for the fast reply.

High speed works fine for the mindsensors accelerometer.
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: test high speed I2C mode

Postby Aswin » Wed Jun 08, 2011 10:16 am

Hi,

I'm implementing another custom sensor. This time it's a BlinkM full color LED. I know that this device supports I2C fast mode and standard mode. I personally tested it with robotC fast I2C (+- 30Kb) and with a bus pirate in fast mode. But in Lejos I cannot get it to work in HIGH_SPEED mode. sendData then returns an error value of -3. It works fine when using LEGO_MODE.

I tried ALWAYS_ACTIVE and NO_RELEASE (I assume you have to logical AND these with HIGH_SPEED) but this didn't make a difference. I did not try pulse stretching as I do not know how to invoke this (I installed the binary that suppports this though).

How do I invoke pulse stretching?
What other things can I try to test HIGH_SPEED mode on sensors?

ps. The sensor not only houses the BlinkM, but also a gyro and accelerometer on the same cable and port. See here.
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: test high speed I2C mode

Postby gloomyandy » Wed Jun 08, 2011 3:12 pm

To get pulse stretching you need to use the updated firmware from the latest developers snapshot (I gave a pointer to it above), this version works with all of the i2c devices I have access to.... Note that leJOS fast mode is approx 100K which may explain why it works fine with RobotC. The Wii MotionPlus device (3 gyros) required the use of pulse stretching...

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

Re: test high speed I2C mode

Postby gloomyandy » Wed Jun 08, 2011 3:27 pm

Sorry I probably did not explain that very well. You need to download this file:
http://lejos.svn.sourceforge.net/viewvc ... n?view=log
Then locate the same file in your leJOS install and rename that to something else (as a backup) and replace it with the above version, then reflash your NXT using nxjflash... Pulse stretching is only enabled when you use HIGH_SPEED mode and it will be used if required, so no changes in your code.

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

Re: test high speed I2C mode

Postby Aswin » Wed Jun 08, 2011 3:42 pm

That is what I did. I conclude that pulse stretching doesn't help in my case.

I will try the other sensors on this port to see how they behave under high speed. I sure hope they work. A higher i2c speed was the main reason to switch to lejos.
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: test high speed I2C mode

Postby gloomyandy » Wed Jun 08, 2011 4:12 pm

One problem may be that at high speeds the signals start to get rather ragged and with multiple devices on the same port and the way that the NXT ends up driving the bus along with the various different voltages of the sensors things may get rather marginal. It is often possible to sort these problems out if you can hook up a scope and see what is going on, but without the devices it is difficult to fix them. I could possibly build you a version of the firmware that operates at a slow bus speed (say 50K) to see if that helps, the only problem is that my current build has a bunch of other changes that have not been checked in yet. Also I'm currently in Germany (rather than the UK), so I can't do anything for a few days...

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

Re: test high speed I2C mode

Postby Aswin » Thu Jun 09, 2011 11:05 pm

Andy,

Thanks for the offer but there is no need to hurry. First I'll build drivers for both the gyro and accelerometer of my sensor. When they both work on high speed I will be happy. The BlinkM I can do without.
First results show that the accelerometer works on high speed, even with the BlinkM around. But the gyro is more sensitive to disturbances. We'll see.

Ps Be careful at the salad bar!
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: test high speed I2C mode

Postby Aswin » Wed Jun 22, 2011 6:41 am

Hi,

Here's an update. I wrote classes for both an accelerometer, an ADXL345, and a gyro, ITX-3200. The accelerometer works fine using HIGH-SPEED. The gyro doesn't. The strange thing is that is does work when I use HIGH-SPEED & ALWAYS_ACTIVE. But when I measure the performance of the sensor under these condition I get a max frequency of about 100Hz (6 bytes per read). Under LEGO_MODE the performance is the same.
To make a long story short. If possible I would like to further test the sensor with different I2C speeds. Andy, does your offer, to get some fit ware with slower high-speed mode still stand? Or is it possible for me to get hold of THE source code for the firmware to experiment myself? If so, I probably need some help to get me started as it has been 20 years since I did some serious programming in C and assembly.
At the same time I'll try to get hold of a oscilloscope.
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: test high speed I2C mode

Postby gloomyandy » Wed Jun 22, 2011 8:56 am

Hi,
Interesting. If you are getting the same speed for HIGH_SPEED|ALWAYS_ACTIVE and LEGO_MODE then I suspect that there may be a bug and that you are not actually getting high speed mode (I've never tested that combination)! I'll take a look and see what is going on... The source code for all of leJOS is available from our sourceforge project, but note that you need a Linux arm toolchain to build it...

I will try and take a look at the i2c code and build a version that provides more control over the transfer speed, but this will probably take a few days...

All the best

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

Re: test high speed I2C mode

Postby gloomyandy » Sat Jun 25, 2011 3:11 pm

Hi Aswin,
OK I've built a new version of the firmware that runs the i2c at approx 64K rather than 125K you can download it from here:
http://www.gloomy-place.com/lejos/lejos ... _i2c64.bin
Let me know how you get on. Oh and I can confirm that it probably makes no sense to use the combination HIGH_SPEED|ALWAYS_ACTIVE, to be honest there is probably no good reason to ever use ALWAYS_ACTIVE unless you are debugging the leJOS i2c code...

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

Re: test high speed I2C mode

Postby Aswin » Sat Jun 25, 2011 4:29 pm

Wow, Thanks.

I'll try tuis out later tonight or tomorrow. I, for my part, ordered a digital oscilloscope.

aswin
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: test high speed I2C mode

Postby gloomyandy » Sat Jun 25, 2011 5:25 pm

Hi Aswin,
cool! which one did you order? I've got a Tektronix TDS 210, which is rather old these days, but still does a good job:
http://www2.tek.com/cmswpt/psdetails.lo ... 4408&lc=EN
I have wondered about replacing it with one of the PC based scopes. I'll be interested to see how you get on...

I've also been taking a look at the power usage of leJOS and I think I can drop the idle usage (in the menu, or a program sleeping, or waiting for a button press) from around 150mA to around 50mA. I'm still working on that though, but thanks for mentioning our power usage in comparison to the other firmware...

All the best

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

Re: test high speed I2C mode

Postby Aswin » Sat Jun 25, 2011 9:59 pm

Hi Andy,

The decreased bandwidth didn't help Both the gyro and the BlinkM refuse to work with 64K HIGH_SPEED.
The scope I ordered is a second hand DSO Quad. I hope it will be suitable for the tests I have to perform. I know nothing about scopes (just a bit of theory) so it will be another learning experience.

Aswin
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Next

Return to NXJ Software

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

more stuff