Currently I am trying to use a new haven display (product number NHD-C0216CiZ-FN-FBW-3V) with an i2c to usb device. I am using there bit banger code from the documentation, link http://www.newhavendisplay.com/specs/NHD-C0216CiZ-FN-FBW-3V.pdf, but whenever I send a old bit into I2C_Out I get suck into the while loop, because SDA never goes low. And I see that I never get an ack from SDA. If anyone knows how to solve this issue it would be greatly appreciated.
while(SDA==1){
SCL=0;
SCL=1;
}
EDIT I thought that the time was two short between setting SCL low then high so I added in a 1 second delay but I am still getting suck into an infinite loop. Also I have already tried to use the given function that the i2c to usb device gives me, but those functions weren't working as well so I decided to just use the bitbanger code. The reason for this is because with the functions given from the device it sends the i2c_start then sends the data then sends the i2c_stop command. But what I need to do is send the start command then a lot of commands then the i2c_stop command. Here is the complete code that I am trying to execute
void Show(unsigned char *text){
int n;
I2C_Start();
for(n=0;n<1;n++){
I2C_out(0x7C);
Delay(.05);
I2C_out(0x40);
Delay(.05);
I2C_out(*text);
++text;
}
I2C_Stop();
}
void I2C_out(unsigned char j) {
BYTE value;
int n, rc;
unsigned char d;
d=j;
for(n=0;n<8;n++){
if((d&0x80)==0x80)
rc = HidSmbus_WriteLatch(i2cDevice,0xFF,0x40); //SDA = 1
else
rc = HidSmbus_WriteLatch(i2cDevice,0,0x40); //SDA = 0
d=(d<<1);
Delay(.001);
rc = HidSmbus_WriteLatch(i2cDevice,0,0x80); //Clock = 0
Delay(.001);
rc = HidSmbus_WriteLatch(i2cDevice,0xFF,0x80); //Clock = 1
Delay(.001);
rc = HidSmbus_WriteLatch(i2cDevice,0,0x80); //Clock = 0
Delay(.001);
}
rc = HidSmbus_WriteLatch(i2cDevice,0xFF,0x80); //Clock = 1
Delay(.001);
rc = HidSmbus_ReadLatch(i2cDevice, &value);
n = 116;
while(((value &0x20)==0x20) && n--){
rc = HidSmbus_WriteLatch(i2cDevice,0x00,0x80); //Clock = 0
Delay(.001);
rc = HidSmbus_WriteLatch(i2cDevice,0xFF,0x80); //Clock = 1
Delay(.001);
//rc = HidSmbus_WriteLatch(i2cDevice,0x00,0x80);
rc = HidSmbus_ReadLatch(i2cDevice, &value);
}
rc = HidSmbus_WriteLatch(i2cDevice,0,0x80); //Clock = 0
}
void I2C_Stop(void) {
int rc;
rc = HidSmbus_WriteLatch(i2cDevice,0,0x40); //SDA = 0
rc = HidSmbus_WriteLatch(i2cDevice,0,0x80); //SCL = 0
rc = HidSmbus_WriteLatch(i2cDevice,0xFF,0x80); //SCL = 1
rc = HidSmbus_WriteLatch(i2cDevice,0xFF,0x40); //SDA = 1
}
void I2C_Start(void) {
int rc;
rc = HidSmbus_WriteLatch(i2cDevice,0xFF,0x80);//pin 7 is clock
rc = HidSmbus_WriteLatch(i2cDevice,0xFF,0x40);//pin 6 is data
rc = HidSmbus_WriteLatch(i2cDevice,0x00,0x40); //SDA = 0
rc = HidSmbus_WriteLatch(i2cDevice,0x00,0x80); //SCL = 0
}
void init_LCD(){
I2C_Start();
Delay(.05);
I2C_out(0x7C);
Delay(.05);
I2C_out(0x00);
Delay(.05);
I2C_out(0x38);
Delay(0.10);
I2C_out(0x39);
Delay(0.10);
I2C_out(0x14);
Delay(.05);
I2C_out(0x78);
Delay(.05);
I2C_out(0x5E);
Delay(.05);
I2C_out(0x6D);
Delay(.05);
I2C_out(0x0E);
Delay(.05);
I2C_out(0x01);
Delay(.05);
I2C_out(0x06);
Delay(0.10);
I2C_Stop();
}
int BitBanger(){
unsigned char text[]={"B"};
int rc;
BYTE dir, mode, special, clk;
rc = HidSmbus_GetGpioConfig(i2cDevice, &dir, &mode, &special, &clk);
rc=HidSmbus_SetGpioConfig(i2cDevice, dir,0, 0, 0);
init_LCD();
Show(text);
}