cancel
Showing results for 
Search instead for 
Did you mean: 

Using I2C Communication Protocol with LCD

Khansokhua
Associate III

STM32F407G DISC-1   STMCubeIDE

Greetings, I am trying to send data to LCD screen by using I2C Communication Protocol. I succeed in doing it by using HAL library. Also, my current work does work in debug mode.However, I could not make it work by running it normally.

I did it in HAL by using the same clock, frequency configurations. I could not find the problem. 

Here is my code:

 

 

 

int main(void)
{
				GPIO_Handle_t I2C1_SCL_PB6 = {  .PORTNAME = GPIOB,
												.PINCONF.PIN = GPIO_PIN_6,
												.PINCONF.MODE = GPIO_MODE_ALTARNATE,
												.PINCONF.OTYPE = GPIO_OTYPE_OD,
												.PINCONF.OSPEED = GPIO_OSPEED_VHIGH,
												.PINCONF.PUPD = GPIO_PUPD_PU,
												.PINCONF.AF = AF4

				 	 	 	 	 	 };
				GPIO_Handle_t I2C1_SDA_PB7 = {  .PORTNAME = GPIOB,
										 	    .PINCONF.PIN = GPIO_PIN_7,
												.PINCONF.MODE = GPIO_MODE_ALTARNATE,
												.PINCONF.OTYPE = GPIO_OTYPE_OD,
										        .PINCONF.OSPEED = GPIO_OSPEED_VHIGH,
											    .PINCONF.PUPD = GPIO_PUPD_PU,
												.PINCONF.AF = AF4
								 	  };
				gpioInit(&I2C1_SCL_PB6);
				gpioInit(&I2C1_SDA_PB7);
				I2C1_CLOCK_ENABLE();
				I2C1_FREQ_16MHZ();
				I2C1_FREQ_SCL_100MHZ();
				I2C1_RISE_TIME_17();

				I2C1_ENABLE();
				I2C1_ACK_ENABLE();
				I2C1_START_GENERATION();
				I2C1->I2C_DR = SLAVE_ADDRESS_LCD;
				 
			 lcd_init ();
	    		 lcd_send_string ("ABCDE");


			while(1)
			{
			}

}

 

 

 

 

21 REPLIES 21

Yes, I already checked them, in HAL structured code, no-pull up, no pull-down is configured.Also, I tried to use external pull-up resistor but in any case TxE is never set.I already shared each file as public.

> Yes, I already checked them

Chip should work the same way then. Registers dictate how it works. It's a mystery. Good luck.

If you feel a post has answered your question, please click "Accept as Solution".