cancel
Showing results for 
Search instead for 
Did you mean: 

Setting up HD44780 on STM32F103R6

UMilo.1
Associate III

Hello everyone,

I am trying to make an LM020L work in Proteus. I am using Eclipse to code.

I am trying to follow the datasheet for the initialization of the LCD and set the cursor at the beginning. This is where I found info: https://web.alfredstate.edu/faculty/weimandn/lcd/lcd_initialization/lcd_initialization_index.html

I want to use 4-bit mode.

Here is my current code:

void resetlcd(void){
 
	GPIOB->BSRR &= ~(GPIO_BSRR_BS9); //RS
	GPIOB->BSRR &= ~(GPIO_BSRR_BS10); //RW 
	GPIOB->BSRR &= ~(GPIO_BSRR_BS11); //E
	GPIOB->BSRR &= ~(GPIO_BSRR_BS12); //D4
	GPIOB->BSRR &= ~(GPIO_BSRR_BS13); //D5
	GPIOB->BSRR &= ~(GPIO_BSRR_BS14); //D6
	GPIOB->BSRR &= ~(GPIO_BSRR_BS15); //D7
 
	GPIOB->BSRR |= (GPIO_BSRR_BR9);
	GPIOB->BSRR |= (GPIO_BSRR_BR10);
	GPIOB->BSRR |= (GPIO_BSRR_BR11);
	GPIOB->BSRR |= (GPIO_BSRR_BR12);
	GPIOB->BSRR |= (GPIO_BSRR_BR13);
	GPIOB->BSRR |= (GPIO_BSRR_BR14);
	GPIOB->BSRR |= (GPIO_BSRR_BR15);
 
}
 
 
void LCD_Init(void){
	// Ukljuciti takt za dati Port -> Enable the peripheral clock of GPIO Port X
	RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; // Enable the peripheral clock of GPIO Port C
 
	GPIOB->CRH &= ~(GPIO_CRH_MODE9 | GPIO_CRH_CNF9); // delete settings for PB9
	GPIOB->CRH |= (GPIO_CRH_MODE9_1 | GPIO_CRH_CNF9_0);  //GPO Push-pull
 
	GPIOB->CRH &= ~(GPIO_CRH_MODE10 | GPIO_CRH_CNF10); // delete settings for PB10
	GPIOB->CRH |= (GPIO_CRH_MODE10_1 | GPIO_CRH_CNF10_0);  //GPO Push-pull
 
	GPIOB->CRH &= ~(GPIO_CRH_MODE11 | GPIO_CRH_CNF11); // delete settings for PB11
	GPIOB->CRH |= (GPIO_CRH_MODE11_1 | GPIO_CRH_CNF11_0);  //GPO Push-pull
 
	GPIOB->CRH &= ~(GPIO_CRH_MODE12 | GPIO_CRH_CNF12); //delete settings for PB12
	GPIOB->CRH |= (GPIO_CRH_MODE12_1 | GPIO_CRH_CNF12_0);  //GPO Push-pull
 
	GPIOB->CRH &= ~(GPIO_CRH_MODE13 | GPIO_CRH_CNF13); // brisemo podesavanja za PB13
	GPIOB->CRH |= (GPIO_CRH_MODE13_1 | GPIO_CRH_CNF13_0);  //GPO Push-pull
 
	GPIOB->CRH &= ~(GPIO_CRH_MODE14 | GPIO_CRH_CNF14); // brisemo podesavanja za PB14
	GPIOB->CRH |= (GPIO_CRH_MODE14_1 | GPIO_CRH_CNF14_0);  //GPO Push-pull
 
	GPIOB->CRH &= ~(GPIO_CRH_MODE15 | GPIO_CRH_CNF15); // delete settings for PB15
	GPIOB->CRH |= (GPIO_CRH_MODE15_1 | GPIO_CRH_CNF15_0);  //GPO Push-pull
 
	delay(20000); // turning on
 
 
	resetlcd();
	delay(10000);
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	delay(30000);
	GPIOB->BSRR |= (GPIO_BSRR_BS12);
	GPIOB->BSRR |= (GPIO_BSRR_BS13);
 
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
 
	delay(10000);
	resetlcd();
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	delay(10000);
	GPIOB->BSRR |= (GPIO_BSRR_BS12);
	GPIOB->BSRR |= (GPIO_BSRR_BS13);
 
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
 
	delay(10000);
 
	resetlcd();
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	delay(10000);
	GPIOB->BSRR |= (GPIO_BSRR_BS12); //DB4
	GPIOB->BSRR |= (GPIO_BSRR_BS13); //DB5
 
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
 
 
	delay(10000);
	resetlcd();
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	delay(10000);
	GPIOB->BSRR |= (GPIO_BSRR_BS13); //DB5
 
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
 
 
	delay(10000);
	resetlcd();
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	delay(10000);
	GPIOB->BSRR |= (GPIO_BSRR_BS13); //DB5
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
 
	delay(10000);
	resetlcd();
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	delay(10000);
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
 
	delay(10000);
 
	//dsp off
	resetlcd();
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	delay(10000);
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
 
 
	delay(10000);
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	delay(10000);
	GPIOB->BSRR |= (GPIO_BSRR_BS15); //DB7
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
 
	delay(10000);
	//dsp on
	resetlcd();
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	delay(10000);
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
 
	delay(10000);
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	GPIOB->BSRR |= (GPIO_BSRR_BS12); //DB4
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
 
	delay(10000);
 
	//entry mode set
	resetlcd();
	delay(10000);
 
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	delay(10000);
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
	resetlcd();
	delay(10000);
	GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
	delay(10000);
	GPIOB->BSRR |= (GPIO_BSRR_BS12); //DB4
	GPIOB->BSRR |= (GPIO_BSRR_BS13); //DB5
	GPIOB->BSRR |= (GPIO_BSRR_BS14); //DB6
 
	GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
 
	delay(100000);
	resetlcd();
 
 
 
}

Can anybody tell what went wrong? Also, I would appreciate it if someone can help me to write a simple "Hello world" message, that is my goal but I am currently stuck on the initialization.

2 REPLIES 2

Yes. First wrong step is to post code without informations about results (how you know that code is wrong).

Few highlits about writing your own driver fro HD44780.

Be sure that you are using right IO voltages (5V powered display does not have to read 3.3V levels). Use 3.3V powered LCD or use Open drain outputs at 5V tolerant pins of your STM and dont forget add pullup on display enable pin.

Be sure that you set contrast to acceptable level. With wrong level you can fall in situation when display works but you simply cant see it.

Be sure that your SW realize right delay times in first part of communication when you can't read busy bit.

Double check connections.

Best way is to adapt some working library. Sending my own in attachment if you want to use ... written for STM32F0. Can be easily adapted to STM32F1 if you modify GPIO init.

Thank you for sharing the library! I found some libraries online I managed to modify some of them in order of my use case. I will post it here once I make it work.

Thank you again!