2 years, 11 months ago.

I2C not working, Parallel bus works

Hi, Hen I hook a 20x4 LCD to mbed p15-p20 It works.

I end up with a report on the USBterminal and 4 lines that start with a line number, some asterisks and a + symbol at the end. The first line also contains two facing triangles as chars 1 (triangle points right) and 2 (triangle points left)

If I use http://www.ebay.com/itm/291780291995?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT I get nothing.

The PCB has a genuine Philips PCF8574AT.

I tried: -modules 'default' and 'lcm1602' -addresses 0x20, 0x27, 0x40, 0x4E and 0x38, 0x3F, 0x70, 0x7E -2k2 resistor pll-ups on SDA and SCL to +3v3 (do I need 5v?)

I probed the I2C IO and I get a legible address byte followed by an uninterpretable byte on my scope/protocol analyzer.

Where am I going wrong?

Question relating to:

Please share more details. Post your code with the proper <<code>> and <</code>> tags as well as the I2C analyzer logs for other readers to view. The address for this module is stated to be 0x27. Are you receiving a response from this address ? If not, try with address 0x27 << 1 = 0x4E. The 3v3 PU should be fine since 3v3 will be seen as a high to even a 5 volt interface. Which library are you using ? Try this one: https://developer.mbed.org/teams/BlueNetDT/code/STMNucleoF401RE_ExampleCode_05_LCD/. Is your contrast control ok on this module ? Be sure you see a response from the I2C to parallel NXP chip else this will not work as expected.

posted by Sanjiv Bhatia 20 Dec 2016

I used the TextLCD2 code from Wim Huiskamp. I TextLCD_config.h changed for an LCM1602 module. Also I used 2k2 pull-ups on SDA and SCL. All I changed to Wim Huiskamp's code are: -enable only I2C config (all others commented out) in the main.cpp -change addresses -Set module type in TextLCD_config.h

posted by Marout Yasuo Sluijter-Borms 20 Dec 2016

1 Answer

2 years, 11 months ago.

The ebay page shows a module with the PCF8574. That device has a default I2C address 0x4E (mbed format) since by default the module sets A0-A2 at logic high. However, I have seen the same module with the PCF8574A. The default address for that version is 0x7E (mbed format). Looks like you have that type. The analyser will only display the slaveaddress and no data because the mbed I2C routines dont get an Ack from the slave and abort.. The Ack (bit 9 of a communication frame) is missing (high level) because the Slaveaddress is wrong.

Try this approach:

First update the TextLCD lib (right click on the lib in your project) to make sure you have the latest version

Open the lib and adapt the TextLCD_config.h file, select LCM1602:

//Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces
//Different commercially available LCD portexpanders use different wiring conventions.
//LCD and serial portexpanders should be wired accordingly.
//Select Serial Port Expander Hardware module (one option only)
#define DEFAULT   0
#define ADAFRUIT  0
#define DFROBOT   0
#define LCM1602   1
#define YWROBOT   0
#define GYLCD     0
#define MJKDZ     0
#define SYDZ      0
#define WIDEHK    0
#define LCDPLUG   0 

Declare the display:

TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4); // I2C bus, PCF8574A Slaveaddress, LCD Type

Compile and run the code

Make sure the LCD contrast is correct. Adjust the blue potentiometer on the i2C portexpander module. Voltage on pin 3 of the LCD will be close to 0.5 V but that depends on the LCD. What contrast voltage did you use for the parallel port version? You will probably already see dark rectangles on the display when the power is on, even without running any code.

That should work..

Accepted Answer

Dear Wim,

I'm probaby daft, because I was sure I tried this and no avail. Yet now it works.

However, Backlight switches off ?!?

(EDIT: set Backlight inverted solves this issue)

Thanks a lot!!!

(now on to the LCD40x2 :) )

PS: can one create user characters for these displays?

posted by Marout Yasuo Sluijter-Borms 21 Dec 2016

Good to hear that the problem is solved.

The backlight is switched off at startup. You have to activate it by calling


You can create user defined characters by defining a simple table for the character and installing it. The character can be displayed by a ''putc'' call. There are some predefined characters in the library (udc_0 etc). The example in the hello world code that you tried shows two arrowsymbols:

// Set and show user defined characters. A maximum of 8 UDCs are supported by the HD44780.
// They are defined by a 5x7 bitpattern. 
  lcd.setUDC(0, (char *) udc_0);  // Show |>

  lcd.setUDC(1, (char *) udc_1);  // Show <|
posted by Wim Huiskamp 21 Dec 2016