Why doesn't the NXT support high speed I2C?
Why doesn't the NXT support high speed I2C?
Why doesn't the NXT support high speed I2C? The onboard chips do support this according to the data sheet.
My blog: nxttime.wordpress.com
-
- Posts: 323
- Joined: 29 Sep 2010, 05:03
Re: Why doesn't the NXT support high speed I2C?
The nxt does support high speed i2c but it is used to talk to some of the internal devices (I seem to remember it is used to talk to the ATMega). There is only a single i2c hardware device on the Arm chip. I guess they could have used it as a bus device, but that is not really compatible with the sensor port design that they have used. So I guess that Lego decided to go with a software implementation. Given that the only Lego sensor to use i2c (the ultrasonic sensor), struggles to keep up with the 9600 baud software i2c I guess that they saw no reason to do any better...
You can make the software implementation run faster (as done by RobotC), but this can end up using a lot of cpu cycles. I measured the cpu usage for the leJOS firmware (which at the time used a similar implementation to that used in the Lego firmware), and just driving a single port used approx 25% of the cpu (Since then we've reduced that considerably)... This was mainly from the timer based interrupt handler which generates approx 20,000 interrupts a second to drive the i2c code...
You can make the software implementation run faster (as done by RobotC), but this can end up using a lot of cpu cycles. I measured the cpu usage for the leJOS firmware (which at the time used a similar implementation to that used in the Lego firmware), and just driving a single port used approx 25% of the cpu (Since then we've reduced that considerably)... This was mainly from the timer based interrupt handler which generates approx 20,000 interrupts a second to drive the i2c code...
Re: Why doesn't the NXT support high speed I2C?
Ok, I understand. Thanks
My blog: nxttime.wordpress.com
Re: Why doesn't the NXT support high speed I2C?
Another point to consider is hardware limitations: the NXT is very well protected by (relatively) high value resistors (4.7k) but coupled with cable capacitance, this severely reduces possible bit rate.
Philo
-
- Posts: 323
- Joined: 29 Sep 2010, 05:03
Re: Why doesn't the NXT support high speed I2C?
Hi,
So I've been tweaking the i2c code in the leJOS firmware. With that I can run reliably at 125KHz (as opposed to the standard 9.6KHz). This seems to work with all of the non Lego i2c devices I have (half a dozen or so in all). I can even combine most of them on a single bus (using a port splitter). Any faster than this though and things seem to fall apart...
Andy
So I've been tweaking the i2c code in the leJOS firmware. With that I can run reliably at 125KHz (as opposed to the standard 9.6KHz). This seems to work with all of the non Lego i2c devices I have (half a dozen or so in all). I can even combine most of them on a single bus (using a port splitter). Any faster than this though and things seem to fall apart...
Andy
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Why doesn't the NXT support high speed I2C?
Wow, perhaps john should think about adding higher speeds to the enhanced FW, as an option. I know that a lot of the higher speed stuff I do (for visual displays and such) would look a lot better if I had higher I2C speeds. Even "just" 10x would be really cool.gloomyandy wrote:Hi,
So I've been tweaking the i2c code in the leJOS firmware. With that I can run reliably at 125KHz (as opposed to the standard 9.6KHz). This seems to work with all of the non Lego i2c devices I have (half a dozen or so in all). I can even combine most of them on a single bus (using a port splitter). Any faster than this though and things seem to fall apart...
Andy
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Why doesn't the NXT support high speed I2C?
Well, I soldered over these resistors at one port.philoo wrote:Another point to consider is hardware limitations: the NXT is very well protected by (relatively) high value resistors (4.7k) but coupled with cable capacitance, this severely reduces possible bit rate.
I use robotC and this support baud rates of 30K but I could use some extra bandwidth as I have a 3-axis accelerometer and a 3-axis gyro on the same port. One read out of both sensors takes two requests of 1 bytes and two replies of 6 bytes (not counting I2C overhead).
My blog: nxttime.wordpress.com
Re: Why doesn't the NXT support high speed I2C?
Andy, could you point me to your tweaked code and/or send me a copy? I am definitely interested in adding faster I2C support to the enhanced NBC/NXC firmware.gloomyandy wrote: So I've been tweaking the i2c code in the leJOS firmware. With that I can run reliably at 125KHz (as opposed to the standard 9.6KHz). This seems to work with all of the non Lego i2c devices I have (half a dozen or so in all). I can even combine most of them on a single bus (using a port splitter). Any faster than this though and things seem to fall apart...
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 323
- Joined: 29 Sep 2010, 05:03
Re: Why doesn't the NXT support high speed I2C?
Hi John,
I've just checked the code in and you can see it here...
http://lejos.svn.sourceforge.net/viewvc ... iew=markup
It is a pretty small change, but it does depend very heavily on the existing leJOS i2c mechanism which is basically a state machine driven by a timer interrupt. For the high speed case I basically just call the state machine directly using a busy wait loop using one of the hardware timers to provide the short timing interval required. I'm not sure how will this would translate over to the standard firmware. You really don't get to run much code with a cycle time that is this short!
One other thing I found I had to add support for clock stretching when operating at this speed. It looks like the processor used in some of the mindsensors devices (and possibly others), need this.
Andy
I've just checked the code in and you can see it here...
http://lejos.svn.sourceforge.net/viewvc ... iew=markup
It is a pretty small change, but it does depend very heavily on the existing leJOS i2c mechanism which is basically a state machine driven by a timer interrupt. For the high speed case I basically just call the state machine directly using a busy wait loop using one of the hardware timers to provide the short timing interval required. I'm not sure how will this would translate over to the standard firmware. You really don't get to run much code with a cycle time that is this short!
One other thing I found I had to add support for clock stretching when operating at this speed. It looks like the processor used in some of the mindsensors devices (and possibly others), need this.
Andy
Re: Why doesn't the NXT support high speed I2C?
With Andy's help I have added support to the enhanced NBC/NXC firmware for a fast I2C mode. It is not yet nicely integrated into the NXC API functions but you can call it as shown in the i2c test code below:
You can do that, I should say, once I make the latest build of the enhanced NBC/NXC firmware available publicly. If you are eager to help me test the firmware changes with your I2C devices please send me an email using the address in the BricxCC about box.
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Who is online
Users browsing this forum: No registered users and 7 guests