#### Exception System.ArgumentException - 0xfd000000 (1) ####
#### Message:
#### Microsoft.SPOT.Hardware.I2CDevice::Execute [IP: 0000] ####
#### Phaser_6140.Program::Main [IP: 0106] ####
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll
Exception was thrown: System.ArgumentException
Microsoft.SPOT.Hardware.I2CDevice::Execute
My code is as follows:
using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace Phaser_6140 { public class Program { public static void Main() { // write your code here OutputPort SDA = new OutputPort(Pins.GPIO_PIN_A4, false); OutputPort SCK = new OutputPort(Pins.GPIO_PIN_A5, false); SDA.Dispose(); SCK.Dispose(); InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled); OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); bool pushState = false; bool pushStatePrev = false; bool ledState = false; bool ledBlinking = false; uint blinkCounter = 0; uint blinkcounterLimit = 1000; ushort writeAddress = 0xA0; ushort readAddress = 0xA1; int clockRateKhz = 100; I2CDevice.Configuration writeConfig = new I2CDevice.Configuration(writeAddress, clockRateKhz); I2CDevice.Configuration readConfig = new I2CDevice.Configuration(readAddress, clockRateKhz); I2CDevice eeprom = new I2CDevice(writeConfig); byte[] writeBuffer = new byte[1]; writeBuffer[0] = 0; byte[] readBuffer = new byte[256]; // create an i2c read transaction to be sent to the device. I2CDevice.I2CTransaction[] writeXAction = new I2CDevice.I2CTransaction[1]; writeXAction[0] = I2CDevice.CreateWriteTransaction(writeBuffer); I2CDevice.I2CTransaction[] readXAction = new I2CDevice.I2CTransaction[1]; readXAction[0] = I2CDevice.CreateReadTransaction(readBuffer); while (true) { try { pushStatePrev = pushState; pushState = button.Read(); led.Write(ledState); if (ledBlinking) { if (blinkCounter > blinkcounterLimit) { blinkCounter = 0; ledState = !ledState; } blinkCounter++; } if (!pushState && pushStatePrev) { Debug.Print("Change LED State"); //the i2c data is received here from the device. int writeTransferred = eeprom.Execute(writeXAction, 1000); eeprom.Config = readConfig; //int readTransferred = eeprom.Execute(readXAction, 1000); //make sure the data was received. //if (transferred != readBuffer.Length) // throw new Exception("Could not read from device."); //else ledBlinking = true; string buff = ""; for (int i = 0; i < 256; i++) { buff += readBuffer[i].ToString(); } Debug.Print(buff); } } catch (Exception e) { Debug.Print(e.Message); if (e.InnerException != null) { Debug.Print(e.InnerException.Message); } Debug.Print(e.StackTrace); } } } } }
Any suggestions?