1
Character LCDs / Re: NHD-0420D3Z-FL-GWB-V3 no I2C code example for Arduino??
« on: July 27, 2017, 10:35:19 AM »
Hi All, just an amendment to the last code
the statement TWBR = 100000, is incorrect
see http://www.gammon.com.au/i2c
Where the TWBR value is defined in the formula
I2C freq = CPU Clock / ( 16+(2*TWBR*Prescaler)
Default Prescaler =1 and the formula I2C freq = 16000000/(16+144) = 100000
For a TWBR = 12, Prescaler =1, I2C freq = 400 kHz
For a TWBR = 32, Prescaler =1, I2C freq = 200 kHz
For a TWBR = 72, Prescaler =1, I2C freq = 100 kHz
For a TWBR = 152, Prescaler =1, I2C freq = 50 kHz
I installed Arduino v1.8.3 and tried to compile the code with TWBR = 100000
and got a warning that the TWBR value was not correct and was truncated, posibly to 100 since all values of TWBR are under 255
the statement
TWBR = 152; //sets I2C speed to 50kHz for NHD LCD display compiled OK with out any warnings, and the display ran OK
Under Reference in the Wire Library, the I2C command
Wire.setClock(100000); // is valid for I2C speed of 100 KHz
In my case with the NHD-0216S3Z-FL-GBW-V3 16 x 2 Display, with builtin I2C,
would only work properly if the I2C frequency value
was set at or below 70000, anything higher, and the display would not show all of the characters sent properly, some characters would be missing, and others in the wrong location.
Wire.setClock(100000); // did not work
Wire.setClock(90000); // did not work
Wire.setClock(80000); // did not work
but
Wire.setClock(70000); // did work
So there are two ways to change the I2C clock speed
the statement TWBR = 100000, is incorrect
see http://www.gammon.com.au/i2c
Where the TWBR value is defined in the formula
I2C freq = CPU Clock / ( 16+(2*TWBR*Prescaler)
Default Prescaler =1 and the formula I2C freq = 16000000/(16+144) = 100000
For a TWBR = 12, Prescaler =1, I2C freq = 400 kHz
For a TWBR = 32, Prescaler =1, I2C freq = 200 kHz
For a TWBR = 72, Prescaler =1, I2C freq = 100 kHz
For a TWBR = 152, Prescaler =1, I2C freq = 50 kHz
I installed Arduino v1.8.3 and tried to compile the code with TWBR = 100000
and got a warning that the TWBR value was not correct and was truncated, posibly to 100 since all values of TWBR are under 255
the statement
TWBR = 152; //sets I2C speed to 50kHz for NHD LCD display compiled OK with out any warnings, and the display ran OK
Under Reference in the Wire Library, the I2C command
Wire.setClock(100000); // is valid for I2C speed of 100 KHz
In my case with the NHD-0216S3Z-FL-GBW-V3 16 x 2 Display, with builtin I2C,
would only work properly if the I2C frequency value
was set at or below 70000, anything higher, and the display would not show all of the characters sent properly, some characters would be missing, and others in the wrong location.
Wire.setClock(100000); // did not work
Wire.setClock(90000); // did not work
Wire.setClock(80000); // did not work
but
Wire.setClock(70000); // did work
So there are two ways to change the I2C clock speed