cancel
Showing results for 
Search instead for 
Did you mean: 

3-wire 9-bit SPI using STM32F030C6

Maunik Patel
Associate II

I need to interface ILE9341V TFT display with STM32F030C6 MCU.

My project hardware has only 3 wires (CSX, SDA and SCL) from the display side.

By referring the TFT display's datasheet, I found that I have to use 3-wire 9-bit mode only (to be compatible with the hardware).

Am I correct here ?

If so, I would like to know how to send 9 bits (1 D/C bit + 8 data bits) using SPI APIs.

I have gone through many blogs and forums on internet for the same but ended up with the option 'Bit-banding SPI'.

But I think it will consume more power and will take long time.

Also, I am afraid that handling other interrupt while using 'Bit-banding/software SPI' may end up in misbehavior of the TFT display.

Seeking for your support here.

1 REPLY 1
S.Ma
Principal

9 bit SPI should be working, possibly even with DMA.

If you don't need to read data from display, connect only MOSI and keep MISO unconnected or as input.

If you want to read, short MISO and MOSI on the PCB to have bidirectional mode (and use GPIO MODER to disable MOSI when getting data from display).

Now try to program the SPI directly by LL or HW register programming.

Remember that for sending 9 bits, you should write SPI DR as 16 bit mode (bit 0..8 are the significant ones). The FIFO allows you to push next 9 bit words manually if you want to minimize pause between data word transmission.

Here some code extract for guidance:

void SPI_WaitIdle(void) {
  while(SPI3->SR & 1<<7); // wait while BUSY (transaction complete)
}
 
void SPI_Wait_u16(void) {
  while(SPI3->SR & (1<<12)); // while the FIFO can't digest 16 bit
}
 
void SPI_SetBits(uint8_t bits) {
  uint16_t r;
  r = SPI3->CR2;
  r &= ~(15<<8);  
  r |= (bits-1)<<8; // go to n-1 bit mode
  SPI3->CR2 = r;
}
 
void FlushRxFifo(void) {
uint8_t byte;
  byte = *((__IO uint8_t *)&SPI3->DR);
  byte = *((__IO uint8_t *)&SPI3->DR);
  byte = *((__IO uint8_t *)&SPI3->DR);
  byte = *((__IO uint8_t *)&SPI3->DR);
}