Getting Junk data on I2C LCD 16x2 display while interfacing with stm32f401re Micro controller . please help
- May 3, 2021
- 2 replies
- 2040 views
Interfaced 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
