SPI - lcd interface with ILI9341 driver Topic is solved

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Lyris
Posts: 11
Joined: Thu Jun 20, 2019 11:58 am
Has thanked: 2 times

SPI - lcd interface with ILI9341 driver

Post 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
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SPI - lcd interface with ILI9341 driver

Post 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
Lyris
Posts: 11
Joined: Thu Jun 20, 2019 11:58 am
Has thanked: 2 times

Re: SPI - lcd interface with ILI9341 driver

Post by Lyris »

Ok I'll do that with GPIO thanks.

Lyris
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: SPI - lcd interface with ILI9341 driver

Post 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.
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Re: SPI - lcd interface with ILI9341 driver

Post by FXCoder »

Rew,
In case you want to investigate further here is the datasheet found at Adafruit...
--
Bob
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: SPI - lcd interface with ILI9341 driver

Post 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.
Lyris
Posts: 11
Joined: Thu Jun 20, 2019 11:58 am
Has thanked: 2 times

Re: SPI - lcd interface with ILI9341 driver

Post 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
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SPI - lcd interface with ILI9341 driver

Post 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
Lyris
Posts: 11
Joined: Thu Jun 20, 2019 11:58 am
Has thanked: 2 times

Re: SPI - lcd interface with ILI9341 driver

Post 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
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SPI - lcd interface with ILI9341 driver

Post by Giovanni »

Are you sure that diagram you posted is the correct one? that thing cannot be done using the SPI driver.

Giovanni
Post Reply