In one of my projects I use the cheap 2.4" 320x240 TFT display with a ILI9340/41 controller. It works quite good, taking into consideration the price, and I do not have any problems when I display something. But I can’t read anything. I think that it uses 4 wire SPI
But unfortunately any read attempt is unsuccessful. On the first dummy write, I see some strange activity on the MISO line and MISO is driven high.
void LCD_SendCommand(SPI_TypeDef * volatile SPIx, int command)
{
ReSetBit(CS_PORT,CS);
ReSetBit(DC_PORT,DC);
while(!(SPIx -> SR & SPI_SR_TXE));
*(volatile uint8_t *)&SPIx -> DR = (uint8_t)command;
while(!(SPIx -> SR & SPI_SR_TXE));
while(SPIx -> SR & SPI_SR_BSY);
SetBit(CS_PORT,CS);
}
void LCD_SendPar(SPI_TypeDef * volatile SPIx, int par)
{
ReSetBit(CS_PORT,CS);
SetBit(DC_PORT,DC);
*(volatile uint8_t *)&(SPIx -> DR) = (uint8_t)(par);
while(!(SPIx -> SR & SPI_SR_TXE));
while(SPIx -> SR & SPI_SR_BSY);
SetBit(CS_PORT,CS);
}
Maybe someone knows where the problem is. I have tried literally everything.
I have sorted it out eventually :). For some reason it requires two consecutive software reset commands to start sending data back :), and now it works as expected.