The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
var device = new I2CDevice(new I2CDevice.Configuration(0xa6, 400));
var transaction = I2CDevice.CreateWriteTransaction(new byte[] { 0xfe, 0x04 });
var transactions = new I2CDevice.I2CTransaction[] { transaction };
var sent = device.Execute(transactions, 100);
Unfortunately I'm getting an ArgumentException on the Execute.
Do you have any suspicion on what's wrong?
Is it possible to get more information on the exception? InnerException is null...
Unfortunately I'm getting an ArgumentException on the Execute
The slave address 0xA6 is out of range, the current implementation of I2C supports only 7-bit addressing and the address does not include read/write indicator bit. Try passing 0x52 instead.
The slave address 0xA6 is out of range, the current implementation of I2C supports only 7-bit addressing and the address does not include read/write indicator bit. Try passing 0x52 instead.
I'm trying to understand your suggestion.
0xA6 = 1010 0110
0x52 = 0101 0010
Setting just the left most bit of 0xA6 to zero:
0x26 = 0010 0110
Shouldn't it be 0x26?
I've been developing on C# since Beta 1 of .NET 1.0 but I'm new to .NET MF and I'm still learning what are the limitations. Are MF exceptions supposed to give so little information?
No - you'd need to use only the left-most 7 bits for the slave address, it means removing 0. bit: 0xA6 >> 1 = 0x53 (101 0011). According to the article, Wii Motion Plus starts in 'repeater state' at that address, so 0x53 should be the correct value (0x52 should be used instead of 0xA4 in the 'motion sensing state', sorry).
So, if I understand it correctly the code should be:
// Initial address is 0x53
var device = new I2CDevice(new I2CDevice.Configuration(0x53, 400));
var transaction = I2CDevice.CreateWriteTransaction(new byte[] { 0xFE, 0x04 });
var transactions = new I2CDevice.I2CTransaction[] { transaction };
var sent = device.Execute(transactions, 100);
// Now the address is 0x52
device.Config = new I2CDevice.Configuration(0x52, 400);
//...
Edit: Removed Dispose() call, replaced with .Config assignment.
Hi CW2,
I found a better source of information and you were right. He uses the values you suggested.
http://www.arduino.c...?num=1245723011
Unfortunately now I'm only receiving zeros...
Thanks for taking the time to help me.
aalmada
EDIT: The picture shows the pull-up resistors connected to 5V but since then I changed to 3V3 and it works fine. I read somewhere that this is the way it should be, as the analog pins are 3.3V on the Netduino. Unlike on the Arduino, where they are 5V.
This is driving me mad!...
It worked for a moment and now I can't make it work any more. I tried it without pull-up resistors, with pull-up resistors, several resistance values, at 3.3V, at 5V, and nothing...
When I try on Arduino Duemilanove, it works in any configuration...
Looking around this forum, I'm not the only have problems with I2C on Netduino.
aalmada
You will need to use a pull-up resistor between 3.3V and the I2C data lines (both of them--clock and data) unless the slave device has appropriately selected I2C pull-ups already.
Also...are you sure that the device supports 400KHz I2C? Have you tried 100KHz instead?
I2C should work consistently...we just need to figure out what's not right. Do you have a logic analyzer by any chance?
Chris
Looking around this forum, I'm not the only have problems with I2C on Netduino.
Just a thought but what is the environment like for noise.
Not sure if this is relevant but I spent all weekend developing with no problems and came back to my kit tonight and nothing would work. This is identical setup to the previous day except for one thing. I had stopped using the trackball and started to use a radio mouse. Switched the radio mouse off and started to use a USB mouse and the kit sprang back to life.
May be a coincidence but would be interested to know if the bus is susceptable to RF noise. Let's face it, I'm prototpying so have plenty of flying leads connecting components and modern life leads to plenty of RF noise - WiFi, Bluetooth, mobile phone....
After many attempts on the Arduino and on the Netduino, I figured the problem had to be in the code.
Nunchuck has a simpler communication protocol so I decided to write a simple sample for both the Arduino and the Netduino. It kept working on the Arduino but failed in the Netduino...
Quick question: is this I2C transaction one where the target device is expecting a "repeated start bit" condition?
If so, that may be the (fluke) reason why the second method works.
Also, some devices may require a bit of delay between the two calls...another reason why the second calling method works better.
Do you have any quick documentation on the target device? If it's another issue, we'd like to make sure we get one in the lab to dig into this issue deeper.
Chris
My didn't freeze, just got zero values. That's why I didn't relate the two issues.
Also, some devices may require a bit of delay between the two calls...
I suspect that's the reason...
Do you have any quick documentation on the target device? If it's another issue, we'd like to make sure we get one in the lab to dig into this issue deeper.
I understand now. It appears that there is no official documentation for the device (i.e. it was meant to be used for the Nintendo Wii...and us makers have figured out how to use it for other purposes).
Based on the Arduino sketch, it looks like the messages are sent separately...so it may be that the device isn't ready to respond right away. The strategy of executing the Read request separately seems to be consistent with the Arduino sketch. So I think you're probably good to go with your new code.
I was never able to consistently connect to the Wiimote extensions. Now that I upgraded to 4.2 firmware, I'm now trying to use the "repeated start bit" feature.
I tried the following code with the Nunchuck but I'm always getting a buffer full of 0xff values (instead of the expected 0x00, 0x00, 0xa4, 0x20, 0x00, 0x00).
var device = new I2CDevice(new I2CDevice.Configuration(0x52, 400));
device.Execute(new I2CDevice.I2CTransaction[] {
CreateWriteTransaction(new byte[] { 0x55, }, 0xf0, 1),
CreateWriteTransaction(new byte[] { 0x00, }, 0xfb, 1),
}, 1000);
Thread.Sleep(1000);
var buffer = new byte[6];
device.Execute(new I2CDevice.I2CTransaction[] {
CreateReadTransaction(buffer, 0xfa, 1),
}, 1000);