2021-05-02 08:37 PM
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
Solved! Go to Solution.
2021-05-06 07:17 AM
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
2021-05-06 07:17 AM
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
2021-05-09 05:58 PM
Thank you for ur inputs.Now Lcd display is working fine after changing sequence of the data.