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 have Netduino Plus that i updated last week with the new firmware 4.2 because the I2C don't work in firmware 4.1, and i tried again but the same error again happen (see the attachement).
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
namespace i2C
{
public class Program
{
static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
public static void Main()
{
i2c();
while (true)
{
led.Write(true);
Thread.Sleep(10);
led.Write(false);
Thread.Sleep(1500);
}
//Thread.Sleep(Timeout.Infinite);
}
static void i2c()
{
// i2c configuration(address of my eeprom , clock speed)
I2CDevice myi2c = new I2CDevice(new I2CDevice.Configuration(0xA2, 400));
// to store the received value from eeprom
byte[] readBuffer = new byte[1];
byte[] address = new byte[] { 1 };
// Reading data stored in the selected address register
I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[1];
i added a little more complex sample of how i do it.
it works perfectly on my mini.
maybe you have to change some small things on the ic_ class part, depends on what eeprom your using.
try lock(youri2cdevice) and set the timeout lower.
also, do you have pullup resistors on your i2c lines? 4.7kohms are fine.
also try 100khz instead of 400 when talking to your device. you can change that when you found out what was wrong.
try lock(youri2cdevice) and set the timeout lower.
also, do you have pullup resistors on your i2c lines? 4.7kohms are fine.
also try 100khz instead of 400 when talking to your device. you can change that when you found out what was wrong.
i have pullup my eeprom with 1k resistors.
i have locked my "myi2c" object but its still not working.
when i try to read the value of the selected register ,this message appears in output windows
Une exception de première chance de type 'System.ArgumentException' s'est produite dans Microsoft.SPOT.Hardware.dll.
Une exception non gérée du type 'System.ArgumentException' s'est produite dans Microsoft.SPOT.Hardware.dll
with some traduction, it will be somthig like this
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll.
An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll
You are using invalid slave address, 0xA2 includes the R/W bit which is not part of the slave address in .NET MF (max. value is 0x7F, hence the exception), try passing 0x51 instead (assuming A2 = 0, A1 = 0, A0 = 1).
Additional note: The memory requires repeated start condition for random read, you'd need special method for that (you have to pass 'word address' via internalAddress parameter).
You are using invalid slave address, 0xA2 includes the R/W bit which is not part of the slave address in .NET MF (max. value is 0x7F, hence the exception), try passing 0x51 instead (assuming A2 = 0, A1 = 0, A0 = 1).
i haven't thinking about this trick, thank you .
now it work, i can read data from my eeprom, but i can't write on it anything.
Unfortunately, I don't have this particular device to check it, but I think the correct method to write a byte is to create just one write transaction of two byte buffer (address, data):
// Write transaction (up to 8 or 16 bytes, depending on the page size)
var xWrite = I2CDevice.CreateWriteTransaction(new [] { RegisterNum[0], Value[0] });
myi2c.Execute(new I2CDevice.I2CTransaction[] { xWrite }, 100);
// Write cycle time is 10 ms
Thread.Sleep(10000);
// Random read transaction requires repeated start condition, but CreateWriteTransaction(...)
// followed by CreateReadTransaction(...) generates two separate transactions,
// you have to use CreateReadTransaction from http://forums.netduino.com/index.php?showtopic=944
var data = new byte[8];
uint startAddressToReadFrom = 0;
var xRead = CreateReadTransaction(data, startAddressToReadFrom, 1);
myi2c.Execute(new I2CDevice.I2CTransaction[] { xRead }, 100);
Note: The code is written from head, may not even compile.
Unfortunately, I don't have this particular device to check it, but I think the correct method to write a byte is to create just one write transaction of two byte buffer (address, data):
// Write transaction (up to 8 or 16 bytes, depending on the page size)
var xWrite = I2CDevice.CreateWriteTransaction(new [] { RegisterNum[0], Value[0] });
myi2c.Execute(new I2CDevice.I2CTransaction[] { xWrite }, 100);
// Write cycle time is 10 ms
Thread.Sleep(10000);
// Random read transaction requires repeated start condition, but CreateWriteTransaction(...)
// followed by CreateReadTransaction(...) generates two separate transactions,
// you have to use CreateReadTransaction from http://forums.netduino.com/index.php?showtopic=944
var data = new byte[8];
uint startAddressToReadFrom = 0;
var xRead = CreateReadTransaction(data, startAddressToReadFrom, 1);
myi2c.Execute(new I2CDevice.I2CTransaction[] { xRead }, 100);
Note: The code is written from head, may not even compile.
it work now, thanks
you too NooM, thanks for your help
Just been thinking about this repeatable read fix (link). Can this be applied in all cases, or will the code have to be used on a device by device basis?
Just been thinking about this repeatable read fix (link). Can this be applied in all cases, or will the code have to be used on a device by device basis?
Basically, it is device-specific. When there is "repeated start condition" mentioned in the device communication protocol description, or it has some kind of addressing scheme (register + data, address + data), those special methods are usually required.
Basically, it is device-specific. When there is "repeated start condition" mentioned in the device communication protocol description, or it has some kind of addressing scheme (register + data, address + data), those special methods are usually required.