Hi
I try to comunicate from my G30 HDR to eprom 24lc04b but without success . This is the code i wrote
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHI.Pins;
namespace I2C
{
public class Program
{
public static void Main()
{
I2CDevice.Configuration con = new I2CDevice.Configuration(0xA0>>1 , 100);
I2CDevice MyI2C = new I2CDevice(con);
I2CDevice.I2CTransaction[] xActions= new I2CDevice.I2CTransaction[3];
byte[] outBuffer = new byte[2] {0x00 ,0xFF};
xActions[0] = I2CDevice.CreateWriteTransaction(outBuffer);
byte[] outBuffer1 = new byte[1] {0x00};
xActions[1] = I2CDevice.CreateWriteTransaction(outBuffer1);
byte[] inBuffer = new byte[1];
xActions[2] = I2CDevice.CreateReadTransaction(inBuffer);
if (MyI2C.Execute(xActions, 1000) == 0)
{
Debug.Print(“Failed”);
}
else
{
Debug.Print(“OK”);
}
}
}
}
I dident configurate the pin because i think is the I2C library do that is right ? And i connect my logic level but i don’t see any signal come out. I saw the data sheet and i connect PB6 and PB7 is right ?
I HOPE some one can help me
:
Thank you so much
Sergio
What value pull up resistors? Can you confirm you can see logic level high of 3v3 when the board is powered up and not doing anything?
Also does the debug output report “failed” ? or is the failure some other form of failure?
I’d add a long wait (wait for a IO pin to go high, and you physically connect it to 3v3; or a ~15 sec initialisation wait) so you know when the code executes, otherwise you are guessing when your logic analyser is looking for the signal. If you have a trigger setting you could use that on a different IO pin to make sure you started sampling correctly
Hi the resistor value are 2.2 k . I have 3.3 v on sda and scl when the board is turn on . Yes is the debug output wrote failed . Really i don’t wait any time for the signal stabilizase . And with the Logic analizer and don’t see any signal . I think mabye is the board dosen’t work ?
What do you want to do with your Code? Why are there two wirte-operations before the read?
I think you want to write a byte onto the EEPROM and then read it, right? You have to create a new transaction for reading data.
You can try something like this:
//Configure the I2C-interface
I2CDevice.Configuration con = new I2CDevice.Configuration(0x50, 100); //0x50 for the first EEPROM-block, 0x51 for the second
//if you have multiple devices, you only need different configurations (you should maybe name them more meaningful, so you can remember them)
I2CDevice MyI2C = new I2CDevice(con); //There can only be one I2C-device-object at a time, multiple devices can be accessed with different configurations.
I2CDevice.I2CTransaction[] WriteAction = new I2CDevice.I2CTransaction[1];
byte[] outBuffer = new byte[2] {0x00 ,0xFF}; //First byte is the memory-block-adress, everything behind the first is the data you want to write, can the more than one
WriteAction[0] = I2CDevice.CreateWriteTransaction(outBuffer); //Write-transaction with the created buffer
if (MyI2C.Execute(WriteAction, 1000) == 0) //The .Execute-method returns the transfered bytes
{
Debug.Print("Write failed");
}
//Bytes for read-transactions
byte[] outBuffer1 = new byte[1] {0x00}; //Memory-block-adress byte
byte[] inBuffer = new byte[1]; //Buffer for received data, the size is the number of bytes that sould be read.
I2CDevice.I2CTransaction[] ReadAction = new I2CDevice.I2CTransaction[2]; //Read-transactions consist of two operations
ReadAction[0] = I2CDevice.CreateWriteTransaction(outBuffer1); //The first tells the IC what you want to read
ReadAction[1] = I2CDevice.CreateReadTransaction(inBuffer); //The second only receives the bytes
if (MyI2C.Execute(ReadAction, 1000) == 0)
{
Debug.Print("Read failed");
}
else
{
Debug.Print(inBuffer[0].ToString());
}
I prefer using the 7-bit-adresses for I2C-devices, because they normaly are mentioned in the datasheet.
If you want to use multiple devices, it can be done with multiple configurations with something like this:.
I2CDevice.Configuration EEPROM_A = new I2CDevice.Configuration(0x50, 100);
I2CDevice.Configuration EEPROM_B = new I2CDevice.Configuration(0x51, 100);
I2CDevice MyI2C = new I2CDevice(EEPROM_A);
//Some code for EEPROM_A here
MyI2C.Configuration = EEPROM_B
//Some code for EEPROM_B here
First thank you for the code, i try but continue doesn’t work, i try another G30HDR and is the same. BUT the strange thing (is the same for the two boards) is that the first part (i think) work is when is read the data told me Failed Lecture. Are maybe the resistor ? the eprom is 24C04 microchip connect a the board 3.3V is possible the signal are not clear ? and if i need the change the value you have some idea ?
I wasn’t asking you to leave that as a permanent addition, just for testing. This is a common thing you will see, to help everything settle (eg voltages in the circuit).
Try using 10k resistors.
can you also confirm the chip revision and that you’re not using 24LC04? Tell us how your power connections are set up?
Do you have another I2C-IC for testing? The wiring would be interessting, but actually there can’t be much done wrong, for some ICs it works even without the pullups. The EEPROM itself is wired up correctly? I haven’t read the complete datasheet, but sometimes there are things like ‘enable’-pins, that can be overseen.
The last news
It works. Today i was at home and i try a couple of things, one poste i wrote “i think he wrote the byte” and that was true because with the logic analyze i saw the right signals. I comment the first part of the code and i run the program i saw he read the right data. I just put one delay between write byte and read byte and now work good. I post the code:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHI.Pins;
using GHI.IO;
namespace I2C
{
public class Program
{
public static void Main()
{
I2CDevice.Configuration con = new I2CDevice.Configuration(0x50 , 100);
I2CDevice MyI2C = new I2CDevice(con);
I2CDevice.I2CTransaction[] WriteAction= new I2CDevice.I2CTransaction[1];
byte[] outBuffer = new byte[2] {0x00 ,0xFF};
WriteAction[0] = I2CDevice.CreateWriteTransaction(outBuffer);
if (MyI2C.Execute(WriteAction, 1000) == 0)
{
Debug.Print("Scrittura Fallita");
}
Thread.Sleep(1000);
byte[] outBuffer1 = new byte[1] {0x00};
byte[] inBuffer = new byte[1];
I2CDevice.I2CTransaction[] ReadAction = new I2CDevice.I2CTransaction[2];
ReadAction[0] = I2CDevice.CreateWriteTransaction(outBuffer1);
ReadAction[1] = I2CDevice.CreateReadTransaction(inBuffer);
if (MyI2C.Execute(ReadAction, 1000) == 0)
{
Debug.Print("Lettura Fallita");
}
else
{
Debug.Print("Valore letto");
Debug.Print(inBuffer[0].ToString());
}
}
}
}
Thank you soo much at everybody.
Last question, someone can help me to understand how the class works ? i saw .NET Micro Framework Platform SDK | Microsoft Learn
but really i have a problem to understand how start