Page 1 of 2

SPI - lcd interface with ILI9341 driver

Posted: Mon Jun 24, 2019 5:10 pm
by Lyris
Hello,

I would like to read the status of a lcd with a SPI 5 wire bus. The datasheet gives:

https://imgur.com/a/dHOGWJc

Image

Question 1, should I have a rx buffer of size 32 and discard the 1 data bit during the dummy cycle with the spiStartIgnore function in ChibiOS ?
Question 2, should I set D/CX to 0 during the last data write D0 ? I am not familiar with the notation of the datasheet. If yes, any idea how should I synchronize them ?

Lyris

Re: SPI - lcd interface with ILI9341 driver

Posted: Tue Jun 25, 2019 5:26 pm
by Giovanni
Hi,

That diagram does not show a normal SPI, for example, it is not possible to insert that single dummy cycle. The STM32 SPI does not even have all those signals.

An option would be to bit-bang it on a GPIO using pal and delays.

Giovanni

Re: SPI - lcd interface with ILI9341 driver

Posted: Tue Jun 25, 2019 8:02 pm
by Lyris
Ok I'll do that with GPIO thanks.

Lyris

Re: SPI - lcd interface with ILI9341 driver

Posted: Sat Jun 29, 2019 7:18 am
by rew
You should link the datasheet. What I THINK I'm looking at, is NOT what Giovanni interpreted...

I THINK this is a combined I2C and SPI device. It can do both. By using the right lines you can do either I2C or SPI.

Re: SPI - lcd interface with ILI9341 driver

Posted: Sun Jun 30, 2019 12:42 am
by FXCoder
Rew,
In case you want to investigate further here is the datasheet found at Adafruit...
--
Bob

Re: SPI - lcd interface with ILI9341 driver

Posted: Sun Jun 30, 2019 6:19 pm
by rew
OK. Me too was wrong: The chip has an SPI interface, no I2C.

The chip needs 9 bits per transfer: 8 bits for data/command and whether or not those 8 bits are data or command.

You get to choose (or the board manufacturer did that for you), if you want to use a separate GPIO line for the command/data bit or if you want to include it in the serial stream.

You can easily do either with the SPI module in the STM32. Put it in 9-bit mode to include it in the datastream (I'm not sure if chibios supports this mode in the driver, but the hardware can do it). Or you can use a GPIO for the 9th bit.

The driver is inefficient (setting up DMA and such) for short transfers and most transactions will probably be "command - lots-of-data", So doing things through the driver would mean you'd need to set the GPIO to low (0), call the driver for the 1-byte transfer, then set the gpio high again and then call the driver with the data. A dedicated driver would set the GPIO low, write the command to the SPI FIFO and the start setting up the DMA, and only fire that off after the SPI FIFO becomes empty and setting hte GPIO high again.

Anyway, chibios might already have something to do the small transactions without DMA, that should help a lot already. All this is irrelevant if you're not aiming to get the max performance out of the hardware. And in that case you should not have been using serial at all.

Re: SPI - lcd interface with ILI9341 driver

Posted: Tue Jul 02, 2019 1:30 pm
by Lyris
Hello guys,

I think my lcd is internaly hard-wired to work without chip select pin and only in 8 bits mode with mosi and miso wires since the chinese seller provides the following informations:

Feature:

Size: 2.4 inches
Drive chip: ILI9341
Touch type: without touching
Resolution: 240*320
Communication interface: SPI

Interface description:

1. GND (power ground)
2. VCC (power supply is 3.3V)
3. CLK (clock line)
4. MOSI (data input)
5. RES (reset line)
6. DC (data / command selection line)
7. BLK (backlight)
8. MISO (data output)


I am still trying to figure out if I can use the ChibiOS SPI driver. I think I can but for now I was not able to communicate.
The Adafruit library use this to send commands:

Code: Select all

From Adafruit lib

/**************************************************************************/
/*!
    @brief  Read 8 bits of data from ILI9341 configuration memory. NOT from RAM!
            This is highly undocumented/supported, it's really a hack but kinda works?
    @param    commandByte  The command register to read data from
    @param    index  The byte index into the command to read from
    @return   Unsigned 8-bit data read from ILI9341 register
 */
/**************************************************************************/
uint8_t Adafruit_ILI9341::readcommand8(uint8_t commandByte, uint8_t index) {
  uint8_t data = 0x10 + index;
  sendCommand(0xD9, &data, 1); // Set Index Register
  return Adafruit_SPITFT::readcommand8(commandByte);
}

/*!
 @brief   Read 8 bits of data from display configuration memory (not RAM).
 This is highly undocumented/supported and should be avoided,
 function is only included because some of the examples use it.
 @param   commandByte
 The command register to read data from.
 @param   index
 The byte index into the command to read from.
 @return  Unsigned 8-bit data read from display register.
 */
/**************************************************************************/
uint8_t Adafruit_SPITFT::readcommand8(uint8_t commandByte, uint8_t index) {
  uint8_t result;
  startWrite();
  SPI_DC_LOW();     // Command mode
  spiWrite(commandByte);
  SPI_DC_HIGH();    // Data mode
  do {
    result = spiRead();
  } while(index--); // Discard bytes up to index'th
  endWrite();
  return result;
}


I would prefere to avoid using adafruit lib but rather make it with ChibiOS SPI. My goal is to stream data from my camera directly to the LCD. I want to configure the LCD at init and then only send pixel data.

Greetings,
Lyris

Re: SPI - lcd interface with ILI9341 driver

Posted: Tue Jul 02, 2019 2:07 pm
by Giovanni
That dummy cycle cannot be generated using the ChibiOS SPI driver. Also, it is not possible to send frames of 8+1+32=41 bits. There is no CS so it is not possible to round that in excess, you need to send the exact number of clock cycles per operation.

Giovanni

Re: SPI - lcd interface with ILI9341 driver

Posted: Tue Jul 02, 2019 2:12 pm
by Lyris
Ok I thought I could send more clock cycle and discard some data.

I found out that ChibiOS got some contrib for ili9341 driver:

Probably worth spending time to have a look at :)

https://github.com/ChibiOS/ChibiOS-Contrib/blob/master/os/various/devices_lib/lcd

Re: SPI - lcd interface with ILI9341 driver

Posted: Tue Jul 02, 2019 2:23 pm
by Giovanni
Are you sure that diagram you posted is the correct one? that thing cannot be done using the SPI driver.

Giovanni