Main Site Documentation

Problem to use the I2CDevice on a FEZ panda II


#1
I´m trying to use a 24lc32 EEPROM Memory on a FEZ Panda II board, but when I try to debug on the platform an exception occurs (An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll
).

Can you help me to solve the problem?
mi code is:

```cs
using System;
using System.Threading;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;

namespace FTicketeraFez
{
    public class Program
    {
        public static void Main()
        {
            byte[] bBuffer = Encoding.UTF8.GetBytes("Prueba del Folio:   ");
            string sBuffer = "Prueba de Folio:   ";
            byte[] buf= new byte[2];
            byte[] bFolio = new byte[3]{0,0,0};
            bool LedState = false;
            byte[] lectura = new byte[1];
            string Numero;
            UInt16 Address = 0;
            
            //DateTime Fechahora = new DateTime(2014, 4, 21, 19, 02, 0);
            
            FTP_628DSL490R Printer = new FTP_628DSL490R("COM1");

            //RealTimeClock.SetTime(Fechahora);

            OutputPort Led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, LedState);
            InputPort Botton = new InputPort((Cpu.Pin)FEZ_Pin.Digital.LDR, true, Port.ResistorMode.PullUp);
            
            I2CDevice.Configuration config = new I2CDevice.Configuration(0xA0, 100);
            I2CDevice idevice = new I2CDevice(config);

            byte[] buffer = new byte[] { 0xAA }; // dummy data
            I2CDevice.I2CWriteTransaction writeTransaction = I2CDevice.CreateWriteTransaction(buffer);

            I2CDevice.I2CTransaction[] trans = new I2CDevice.I2CTransaction[] { writeTransaction };

            int transfered = idevice.Execute(trans, 100);
           

            

            
           

            
            while (true)
            {
                Thread.Sleep(500);
                LedState = !LedState;
                Led.Write(LedState);

                if (Botton.Read() == false)
                {
                    //Printer.PrintStringLine(DateTime.Now.ToString());
                    Printer.PrintStringLine(RealTimeClock.GetTime().ToString());
                    
                    
                    Printer.PrintText(sBuffer);
                    Numero = bFolio[0].ToString();
                    bFolio[0] += 1;
                    Printer.PrintStringLine(Numero);
                    if (bFolio[0] == 10)
                    {
                        Printer.NLineFeed(4);
                        bFolio[0] = 0;
                        Printer.PaperFullCut();
                    }

                   
                }
            }

        }

    }
}

#2

For those who can’t read the long scroll (everyone :)) here’s what the post says:

Panda II - so you’re targeting 4.1 framework, right? Can you confirm when the exception is thrown, as soon as your app is deployed or some time later? What are your references you’ve added?


#3

The exception gets thrown on the I2C transaction execute line:

 

but the cause of the error is the I2C address being wrong.  A0 is not a valid I2C address. The address format of an 24LC32 in 7-bit I2C is 1010xxx where the last 3 x's represent the A0/A1/A2 pin settings. Assuming they're all 0's, your address is 0x50.

You can take a look at the I2C page on the documents sub-site here and see the very explicit 7-bit warning. https://www.ghielectronics.com/docs/12/i2c