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.
I need to communicate with I2C sensor on some project. I do not know why, but after adding any code that executes I2C transaction, program breaks on exception.
using System;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;namespace NetduinoSandbox{ public class Program { public static void Main() { I2CDevice.Configuration config = new I2CDevice.Configuration(1, 1); I2CDevice device = new I2CDevice(config); I2CDevice.I2CTransaction[] array = new I2CDevice.I2CTransaction[1]; byte[] data = new byte[2]; array[0] = I2CDevice.CreateWriteTransaction(data); device.Execute(array,1000); } }}
What exception? I think you are using incorrect configuration parameters, the clock rate must be >= 10 [kHz]. Also, slave address 1 seems a little bit suspicious, although it should not cause any exception.
What exception? I think you are using incorrect configuration parameters, the clock rate must be >= 10 [kHz]. Also, slave address 1 seems a little bit suspicious, although it should not cause any exception.
Hi,
Thanks,
You are right about configuration parameters. I have increased clock rate to 15 kHz. Now it does not cause exception. But, unfortunately, I am still not able to communicate with the sensor, maybe wrong address.
Also, which pin is SDA, and which SCL? I have wired SDA to A4, SCL to A5.
If you could find me correct address, its this sensor .
@NooM: I am not using pull-up resistors, which value would be best?
If I remember it correctly, LEGO NXT uses software I2C ("bit-banged"), which does not comply to the I2C protocol specification, so I think you'll not be able to communicate with sensor using Netduino hardware I2C module. You'd probably need to have a look at LEGO NXT firmware source code or information published by various hackers that were able to communicate with LEGO sensors using Arduino, mbed etc., the best would be to capture the communication between the brick and sensor with a logic analyzer.
@CW2: Maybe NXT Brick, but I am not using NXT Brick.
@All: So, it seems to be working fine. Using following code, when you connect HiTechnic Color Sensor V2 to I2C bus, you will see color number in output window of Visual Studio.
I2CDevice.Configuration config = new I2CDevice.Configuration(1, 12); I2CDevice device = new I2CDevice(config); I2CDevice.I2CTransaction[] trans = new I2CDevice.I2CTransaction[2]; byte[] mosi = new byte[1]; byte[] miso = new byte[1]; mosi[0] = 0x42; trans[0] = I2CDevice.CreateWriteTransaction(mosi); trans[1] = I2CDevice.CreateReadTransaction(miso); while (true) { device.Execute(trans, Timeout.Infinite); Debug.Print(miso[0].ToString()); }
I havesomedaysarea "Netduino2".One of my firstapplicationsshouldconnect to theI2C busofan LCD display.I have trieda variety ofsource code, butallthe same error.Even if noconnection to theI2Chardwareis present,isthe same error.Whatam I doing wrong?Here's mysimplecode:I2CDevice.Configurationconfig = newI2CDevice.Configuration(0xDE,1);I2CDevicedevice =newI2CDevice(config);I2CDevice.I2CTransaction[]array = newI2CDevice.I2CTransaction[1];byte []buffer = new byte[1];buffer [0]= 0x0C;array [0]=I2CDevice.CreateWriteTransaction(buffer);device.Execute(array, 1000);
>> here comes theerror:
'System.ArgumentException' occurred inMicrosoft.SPOT.Hardware.dll.""device.m_xAction":Thevalue of the "m_xAction"cannotbe retrieved becauseno information aboutthe containing classis available.
I2C bus of an LCD display...System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll
The slave address 0xDE in I2CDevice.Configuration constructor is out of range, .NET MF does not include the R/W bit in the address, so the max value is 0x7F. It would help to know what LCD you are using, but I guess the address should be 0x6F.
Welcome to the community!
Thank you "CW2" for the helpful info,
after the change of address to 0x6F is not an "exception".
But the connection still does not work. The following code:
"
I2CDevice.Configuration config = new I2CDevice.Configuration (0x6F, 100);
I2CDevice device = new I2CDevice (config);
I2CDevice.I2CTransaction [] array = new I2CDevice.I2CTransaction [1];
Encoding code = Encoding.UTF8;
byte [] buffer = code.GetBytes write ("#DL" + "n");
array [0] = I2CDevice.CreateWriteTransaction (write buffer);
COUNT_1 device.Execute int = (array, 1000);
Debug.Print ("count1" count_1.ToString + ());
array [0] = I2CDevice.CreateWriteTransaction (write buffer);
int = COUNT_2 device.Execute (array, 1000);
Debug.Print ("count2" count_2.ToString + ());
"
The return value of COUNT_1 = 0 but of COUNT_2 = 4 (sometimes even 0).
The display should be deleted with this command, but no response ..
The connection via I2C bus by a different controller (not Netduino) to the display is working properly.
The pullup resistors to VCC or 4.7 k
What can I do?
What is the value of count (result of Execute() call)? If it is non-zero, check the ack[0] value. Otherwise, try executing transactions one-by-one and check the result of Execute() method.
I found the cause: the display is set to power down mode.
The power consumption is lowered to a minimum. The display remains visible.
By addressing the I2C address of the display should be awakened. Does it not!
I suspect the time between the writing of the address and the data is too low.
Without power-down mode, the connection is normal.
Thanks you for the help!
Hi,
I again problems with the I2C bus in connection with the display and the serial EEPROM.
When code in I2CBus "transferred = _slaveDevice.Execute (writeXAction, transactionTimeout)" Transferred is always 0 and there is also no exception.
The multimeter can be seen in SCL and SDL has a frequency of 0.34 kHz and 4.85 V, and this is always constant.
The motherboard is defective?
I again problems with the I2C bus in connection with the display and the serial EEPROM.
What operation does the program perform? What EEPROM do you use? Some EEPROMs require repeated start condition, there is usually mandatory timeout after write etc.
Regarding the multimeter results, it displays average (or RMS) voltage, you'd need a logic analyzer or oscilloscope to inspect the I2C waveforms in detail.
Hi CW2,
The EEPROM is a Microchip 24LC64 (A0,A1,A2,WP = 0)
Here is my Testcode:
public static void Main()
{
I2CDevice.Configuration _slaveConfig = new I2CDevice.Configuration(0x50, 100);
uint adresse = 0x01;
byte[] buffer = new byte[2];
buffer[0] = (byte)(adresse >> 8);
buffer[1] = (byte)adresse;
int count = I2CBus.GetInstance().Write(_slaveConfig, buffer, 500);
byte[] data = new byte[] { 0x42 };
count = I2CBus.GetInstance().Write(_slaveConfig, data, 500);
Debug.Print("Count: " + count.ToString());
}
The I2C connection to the display is the same.
Another board with an ATmega32 working on the bus without problems