cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 LCD20x4 i2C

paul sauv
Associate III
Posted on May 01, 2018 at 06:29

Good morning,

I'm beginner with STM but managed to get working a STM32F103 LCD16x2 using i2C

Now, I would like to use i2C but with 20x4 LCD, nothing fancy

I modified the library according to what I was thinking correct but I can't get it working properly.

I used this tutorial for the 16x2 lcd:

http://controllerstech.com/i2c-lcd-in-stm32/

 

because I use this i2C module: 

PCF8574

And the LCD screen 20x4:

https://www.aliexpress.com/item/2PCS-Lot-LCD-Board-2004-20-4-LCD-20X4-5V-Blue-Screen-LCD-2004A-Display-LCD/32637673263.html

 

I have weird characters wrote on the LCD but not at the good position and not what it's supposed to be displayed

The project is attached

Do you have any idea of what I did wrong ?

Thank you

#lcd-display #i2c #stm32f103
16 REPLIES 16
Posted on May 17, 2018 at 11:09

Hi

The problem is I'm a beginner so I try to do with wat I understand.

I took a working library for the same hardware but 16x2LCD instead and adapted it to 20x4 LCD

I already id the same previously with STD periph lib and no I2C communication and it worked well

Now this is with I2C and HAL.

As of today here is the better result I have:

Parameters:

♯ define SLAVE_ADDRESS_LCD 0x4E

♯ define LCD_SET_DDRAM_ADDRESS 0x80

void lcd_init (void)

{

lcd_send_cmd (0x02);

lcd_send_cmd (0x28);

lcd_send_cmd (0x0c);

lcd_send_cmd (LCD_SET_DDRAM_ADDRESS);

}

Code sent:

lcd_send_string ('12345678912345678910');

lcd_send_string ('123');

On the diplay I have: 

12345678912345678910 on the first row and 123 on the third row.

When i use goto and other function, it's a mess.

For what I know, the ddram address seems to be 0x80

But I don't understand the init function, this is why I didn't touch the following commands:

lcd_send_cmd (0x02);

lcd_send_cmd (0x28);

lcd_send_cmd (0x0c);

It was working great for 16x2 with these commands but not with 20x4

Thank you once again for your help

Posted on May 18, 2018 at 11:00

If continuous writing writes to lines 1 and 3, it's probably the usual arrangement, i.e. 1st+3rd line for one logical line, and so do 2nd+4th line which are offset by 0x40

As I've said, keep on writing. The 64th (0x40th) character should appear on line 4.

Note, that the goto routine above assumes 0-based coordinates, i.e. 1st line is y=0; y=2 is 3rd line.

JW

Posted on May 24, 2018 at 12:06

look into my libraries, you might find something useful

________________

Attachments :

ll_library.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxXz&d=%2Fa%2F0X0000000azx%2FB4DQcXflIPB_CQTjclH5PgJkFOWRBoSJSvQAojT2FCU&asPdf=false
Posted on May 24, 2018 at 22:42

Hi

For what I understand there is a difference here:

my code:

// Number of visible lines of the display (1 or 2/4)

&sharpdefine LCD_LINES 4

// Visible characters per line of the display

&sharpdefine LCD_DISP_LENGTH 20

// DDRAM address of first char of line 1

&sharpdefine LCD_START_LINE_1 0x00

// DDRAM address of first char of line 2

&sharpdefine LCD_START_LINE_2 0x40

// DDRAM address of first char of line 3

&sharpdefine LCD_START_LINE_3 0x14

// DDRAM address of first char of line 4

&sharpdefine LCD_START_LINE_4 0x54

and you code:

if (line < LCD_NR_LINES) {

if (line == 0)

return 0x00;

else if (line == 1)

return 0x40;

else if (line == 2)

return 0x00 + LCD_NR_CHARS;

else if (line == 3)

return 0x40 + LCD_NR_CHARS;

with 

LCD_NR_CHARS:

&sharpdefine LCD_NR_CHARS 20

but the result is also 0x14 

MHoch.3
Associate II

Hello,

it seams this task is quite a long time in process. Did you manage to get it running? I'm looking for the exact same.

DTodo
Associate II

Hi,

if you are still interested I am working on an I2C LCD (PCF5874T + HD44780) library for STM32F1x. It's still WIP, but you can check it out

https://github.com/meteowrite/stm32_i2cLcd

Cheers,

-

DTodo
Associate II

Hey there,

in the past I've worked with the same LCD+I2C combination. You may check it out on github, see if it helps:

https://github.com/meteowrite/stm32_i2cLcd

Br,

Dimitar