8 years, 7 months ago.

i2c not working

I have a 16x2 LCD with i2c address 0x27 form a PCF8574 and cant get any thing to display I have the following modified lines from your code

I2C i2c_lcd(PTB0,PTB1); SDA connected to PTB0, SCL connected to PTB1

LCD instantiation TextLCD_I2C lcd(&i2c_lcd, 0x27, TextLCD::LCD16x2, TextLCD::WS0010); I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type, Ctrl Type

Question relating to:

1 Answer

8 years, 6 months ago.

Hi Richard, sorry didnt notice your question before. Never got a notification. Anyhow, your problem must be the I2C address. The mbed lib uses the 8bit format, you use the 7bit format 0x27. You should use 0x4E instead (assuming all selectable addressbit are high for the pcf8574).

You may also want to check the I2C pins for the KL25Z that I assume you are using. Your example has swapped SDA and SCL, which leads to a runtime crash. The valid pins are shown on the platform page.

//KL25Z example pins
//I2C i2c_lcd(PTE0,PTE1); // SDA connected to PTE0, SCL connected to PTE1
I2C i2c_lcd(PTB1,PTB0); // SDA connected to PTB1, SCL connected to PTB0

//LCD instantiation
TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2, TextLCD::WS0010); //I2C bus, PCF8574 I2C Exp Slaveaddress, LCD Type, Ctrl Type