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.
To use the new I2C InternalAddress feature (repeated start bit) in the v4.1.1 alpha, add the following two methods to your code...and then call them instead of built-in I2CDevice.CreateWriteTransaction/CreateReadTransaction functions when appropriate.
The InternalAddressSize parameter defines the # of bytes used to represent the InternalAddress. The InternalAddress is a set of bytes sent to a device before the buffer--often a register # or memory location to write/read. When used in an I2C ReadTransaction, an extra start bit will be sent to the I2C device after the InternalAddress (followed by the traditional buffer read/write).
These can also be easily integrated as extension methods to the I2CDevice class. We're still sorting out the details on integrating them into the object model (as we want to reduce the risk that future .NET MF releases could break existing code).
I don't fully understand when/why this is used. Is this so you don't have to swap out the configuration when sharing the device, is is this something else?
Roy
Is this so you don't have to swap out the configuration when sharing the device, is is this something else?
No, the repeated start condition "merges" two I2C transactions (replaces the first transaction stop bit). This is required by certain devices, in most cases the first write transaction is used to set an address or register to read/write from and the second transaction performs the desired data operation.
No, the repeated start condition "merges" two I2C transactions (replaces the first transaction stop bit). This is required by certain devices, in most cases the first write transaction is used to set an address or register to read/write from and the second transaction performs the desired data operation.
OK.. I'll make sure to read the data sheets for any indication that it need to use this.
To use the new I2C InternalAddress feature (repeated start bit) in the v4.1.1 alpha, add the following two methods to your code...and then call them instead of built-in I2CDevice.CreateWriteTransaction/CreateReadTransaction functions when appropriate.
While it works fine for the Netduino 1, running it on Netduino 2 (firmware V 4.2.2.2), throws an exception because [color=#ff0000;]fieldInfo[/color] remains Null after the line:
For the Netduino 2 the repeated start bit feature seems to work without needing this workaround, so standard features from the I2CDevice.I2CTransaction class can be used directly.
I don't know why but I'm using N+2 with firmware 4.2.2.2 and I only read the value 255 into the buffer
Pull-up are used on SDASCL pins
What does your code look like? What I2C address are you using?
Also, what type of component are you talking to? What value of pull-up resistors? Have you communicated with this component before, from another board?
Do you have a logic analyzer by any chance?
Chris
This code successfully reads and writes a single byte of data to 24c32 chip without the code above. the 12bit memory location is split into 2 bytes and precedes the actual data byte you want to read or write as seen in the code here:
/// <summary> /// Writes a single Byte of data to the chip /// </summary> /// <param name="Address">Memory Address. Must not exceed 4095</param> /// <param name="Data">a single Byte of Data</param> public void WriteByte(uint Address, byte Data) { if (Address > maxBytes) { throw new Exception("Address cannot exceed 4095"); } byte[] iByte=new byte[1]; iByte[0]=Data; //byte address1a = (byte)(Address >> 8); //byte address2a = (byte)(Address - (address1a << 8)); byte address1 = (byte)((Address & 0xff00) >> 8);//1111111100000000 mask + shift byte address2 = (byte)(Address & 0xff);//0000000011111111 mask var writeX = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] { address1, address2, Data }) }; if (EEPROM.Execute(writeX,TimeOutMs)==0) { throw new Exception("I2C transaction failed"); } } /// <summary> /// Reads a Single Byte from the Chip from a single memory location 0-4095 /// </summary> /// <param name="Address">Memory Address </param> /// <returns></returns> public byte ReadByte(uint Address) { if (Address > maxBytes) { throw new Exception("Address cannot exceed 4095"); } byte[] returnByte=new byte[1]; byte address1 = (byte)((Address & 0xff00) >> 8); byte address2 = (byte)(Address & 0xff); var readX = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(new byte[] {address1, address2}), I2CDevice.CreateReadTransaction(returnByte) }; if (EEPROM.Execute(readX, TimeOutMs) == 0) { throw new Exception("I2C transaction failed"); } return returnByte[0]; }
I haven't tried the page write and sequential reading, but I can address that elsewhere.
Just a note: Sequential calls to read and/or write without a thread.sleep(5) between caused the routines to throw an exception. Is this to be expected? I'm ok with 5mS sleep, but just wondering.
Here's a snip from the logic analyzer during a read with repeated start... The code I posted above has a "repeating start condition". Here's the data sheet Random Read spec as well.
I'm reading from location bit 1 and it returns a 2 from the memory.
The original Netduino (gen1) boards used Atmel SAM7 microcontrollers. The I2C hardware interface on those chips did not support repeated start bits outside of the context of a register-style address.
Generally speaking, with modern Netduino boards, you should just be able to group multiple I2C transactions together and I2C repeated start bits should just work.
I can't speak to any other version except the Netduino 3 as it's all that I have. With the Netduino 3, this worked just fine with the MPL3115A2 that's on the SparkFun WeatherShield.
That said, if you don't have repeated start bit support, doing a read will start reading from byte 0 of the registers. So you can get all of the registers and just grab the bytes you want out of the array. Icky, I know, but it should work from what I saw.