Ok the transactions aren’t failing anymore after I connected my scope to it…must be a loose wire somewhere as well. Now I just need to go back and 1) verify what I am initializing and 2) Fix my driver so I can write strings.
In their initialization code they send 0x38 then 0x39 - this is just two different versions of the same settings right? So i just need to do one version of function settings. They then send 0x14 which configures the cursor/display shift. Next they send 0x78 which corresponds to setting the CGRAM. WHAT THE HELL IS CGRAM?And why do they have AC2 AC1 and AC0 set as 0? They then send 0x5E which appears to be a different version of the previous CGRAM settings. I really need someone to explain the differences here. The next coommand is 0x6D which appears to be yet another CGRAM configuration, only one of these is needed correct? But what does each do? 0x0C is sent next which turns the display on and cursor off followed by 0x01 which is another version of the display settings. The final command is 0x06 which does “Entry Mode Set,”
@Brett You helped me redo my other I2C driver but not the Write(string) method of it. Can you take a look at it please?
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.Threading;
namespace DisplayTest
{
public class Display
{
public I2CDevice.Configuration I2CConfig;
public I2CDevice I2C;
/// <summary>
/// Initializes a new instance of the <see cref="EEPROM"/> class.
/// </summary>
public Display()
{
I2CConfig = new I2CDevice.Configuration(0x3C, 400);
I2C = new I2CDevice(I2CConfig);
Thread.Sleep(100);
I2CDevice.I2CTransaction[] transaction = new I2CDevice.I2CTransaction[1];
transaction[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x00, 0x38});
Thread.Sleep(10);
if (I2C.Execute(transaction, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
// I2C.Execute(transaction, 500);
Thread.Sleep(10);
transaction[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x00, 0x39 });
Thread.Sleep(10);
if (I2C.Execute(transaction, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
Thread.Sleep(10);
transaction[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x00, 0x14 });
Thread.Sleep(10);
if (I2C.Execute(transaction, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
transaction[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x00, 0x78 });
Thread.Sleep(10);
if (I2C.Execute(transaction, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
transaction[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x00, 0x5E });
Thread.Sleep(10);
if (I2C.Execute(transaction, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
transaction[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x00, 0x6D });
Thread.Sleep(10);
if (I2C.Execute(transaction, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
transaction[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x00, 0x0C });
Thread.Sleep(10);
if (I2C.Execute(transaction, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
transaction[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x00, 0x01});
Thread.Sleep(10);
if (I2C.Execute(transaction, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
transaction[0] = I2CDevice.CreateWriteTransaction(new byte[] { 0x00, 0x06 });
Thread.Sleep(10);
if (I2C.Execute(transaction, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
Thread.Sleep(10);
}
/// <summary>
/// Writes a one byte data at the specified address.
/// </summary>
/// <param name="Address">The address to write to.</param>
/// <param name="data">The byte to write</param>
public void Write(int Address, byte[] data)
{
byte[] byte1 = new byte[2];
byte1 = new byte[] { (byte)(Address >> 8), (byte)(Address & 0xFF) };
int length = byte1.Length + data.Length;
byte[] payload = new byte[length];
byte1.CopyTo(payload, 0);
data.CopyTo(payload, byte1.Length);
var xActions = new I2CDevice.I2CTransaction[1];
// byte1=[(byte)(Address>>8),(byte)(Address&0xFF)];
xActions[0] = I2CDevice.CreateWriteTransaction(payload);
Thread.Sleep(5);
if (I2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
}
/// <summary>
/// Writes the string Text at the specified address.
/// </summary>
/// <param name="Address">The starting address to write to</param>
/// <param name="Text">The text to write to EEprom</param>
public void Write(int Address, string Text)
{
var xActions = new I2CDevice.I2CTransaction[1];
byte[] buffer = System.Text.Encoding.UTF8.GetBytes("00" + Text); // the "00" string reserves the room for the 2 bytes address that follows
buffer[0] = (byte)(Address >> 8);
buffer[1] = (byte)(Address & 0xFF);
xActions[0] = I2CDevice.CreateWriteTransaction(buffer);
Thread.Sleep(5);
if (I2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
}
/// <summary>
/// Reads the specified address.
/// </summary>
/// <param name="Address">The address to be read</param>
/// <returns>One byte from the EEprom</returns>
public byte Read(int Address)
{
var Data = new byte[1];
var xActions = new I2CDevice.I2CTransaction[1];
xActions[0] = I2CDevice.CreateWriteTransaction(new byte[] { (byte)(Address >> 8), (byte)(Address & 0xFF) });
Thread.Sleep(5);
if (I2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
else
{
xActions[0] = I2CDevice.CreateReadTransaction(Data);
Thread.Sleep(5); // Mandatory after each Write transaction !!!
if (I2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
else
{
Debug.Print("Register value: " + Data[0].ToString());
return Data[0];
}
}
return 0;
}
}
}