Skip to main content
Nchun.1
Associate III
May 3, 2021
Solved

Getting Junk data on I2C LCD 16x2 display while interfacing with stm32f401re Micro controller . please help

0693W00000AN7W0QAL.jpgInterfaced i2c_lcd with stm32f401re and try to program without any library .but getting junk data always,tried changing delay but same.

 void I2C_WriteData(uint32_t data)

{

uint8_t data1=0,data2=0,data3=0,data4=0; 

  data1= data & 0x000000ff;

  data2= (data & 0x0000ff00)>>8;

  data3= (data & 0x00ff0000)>>16;

  data4= (data & 0xff000000)>>24;

  uart_printf("The data1 is %x :\n",data1);

  uart_printf("The data2 is %x :\n",data2);

  uart_printf("The data3 is %x :\n",data3);

  uart_printf("The data4 is %x :\n\n\n",data4);

  delay(100);

  while(!(I2C1->SR1 & (1<<7))) ;/* Wait for Bit 7 TxE: Data register empty */

  I2C1->DR=data1;

  while(!(I2C1->SR1 & (1<<2)));/*Wait for the byte Tranfer */

  while(!(I2C1->SR2 & (1<<1)));/**Wait for busy flag*/

  delay(10);

  while(!(I2C1->SR1 & (1<<7))) ;/* Wait for Bit 7 TxE: Data register empty */

  I2C1->DR=data2;

  while(!(I2C1->SR1 & (1<<2)));/*Wait for the byte Tranfer */

  while(!(I2C1->SR2 & (1<<1)));/**Wait for busy flag */

  delay(10);

  while(!(I2C1->SR1 & (1<<7))) ;/* Wait for Bit 7 TxE: Data register empty */

  I2C1->DR=data3;

  while(!(I2C1->SR1 & (1<<2)));/*Wait for the byte Tranfer */

  while(!(I2C1->SR2 & (1<<1)));/**Wait for busy flag*/

  delay(10);

  while(!(I2C1->SR1 & (1<<7))) ;/* Wait for Bit 7 TxE: Data register empty */

  I2C1->DR=data4;

  while(!(I2C1->SR1 & (1<<2)));/*Wait for the byte Tranfer */

  while(!(I2C1->SR2 & (1<<1))) ;/**Wait for busy flag */

  delay(10);

}

 Code is attached below

This topic has been closed for replies.
Petr DAVID
Petr DAVIDBest answer
ST Employee
May 6, 2021

Hello NChun.1,

you did not write what display are you using. So I am not sure what protocol of communication is expected. But are you sure you could just write the all the commands and data in one block between 1 start and 1 stop? Further I would recommend you to check the transmission with either another slave device or oscilloscope to see whether you are really sending what expected. It will also help to determine if there is problem with the display or with your code.

With the best regards,

Petr

2 replies

Petr DAVID
Petr DAVIDBest answer
ST Employee
May 6, 2021

Hello NChun.1,

you did not write what display are you using. So I am not sure what protocol of communication is expected. But are you sure you could just write the all the commands and data in one block between 1 start and 1 stop? Further I would recommend you to check the transmission with either another slave device or oscilloscope to see whether you are really sending what expected. It will also help to determine if there is problem with the display or with your code.

With the best regards,

Petr

Nchun.1
Nchun.1Author
Associate III
May 10, 2021

Thank you for ur inputs.Now Lcd display is working fine after changing sequence of the data.