cancel
Showing results for 
Search instead for 
Did you mean: 

9 bit SPI for TFT

PLee.3
Associate II

Hi, I have a TFT screen that is using 3-wire 9-bit SPI (DC bit as 9th bit) has anyone got and experience or examples of this with HAL? I think I have it explained below, the problem is when I test on the oscilloscope the SPI data is reversed as MSB is always sent 1st...

STM32 SPI - 16 Bit mode
Command bit
00000000 11111111
<<7
= 01111111 11000000 (9 bit command bit with "0" DC bit)

Data bit
00000000 11111111
<<7 | (1 << 8
= 11111111 11000000 (9 bit data bit with "1" DC bit)


HAL SPI Data sent MSB on oscilloscope (so reversed)

= 00000011 11111110 (9 bit command bit)


= 00000011 11111111 (9 bit data bit)

 

7 REPLIES 7

SPI have programmable data order. Just use this feature to control if LSB or MSB goes first. Consider also using USART in synchrounous 9bit mode.

AScha.3
Chief

Hi, 

which cpu ? F4xxx

+

lsb or msb first can select in Cube:

AScha3_0-1707162350466.png

But to set 9 bits - need a "newer" cpu , old F4 can only 8 or 16 bit SPI .

You could do a software SPI , bit bang it.

If you feel a post has answered your question, please click "Accept as Solution".

Might be a lot easier to unpack what's necessary from the OTHER END.

Cite the specific display, linking to it's technical documentation or data sheet. Are you sure there isn't a more compatible mode of operation?

The F4 can't do 9-bit SPI.

9 bytes of 8 bits would looks the same as 8 bytes of 9 bits.

You'd perhaps use 16-bit MSB first, and align the patterns to reflect how you want them to appear on the wire.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
PLee.3
Associate II

Hi Thanks for the suggestions, it was originally for an STM32F412G Disco board but have found a STM32G07B board  which can inherently do 9 bit SPI just not sure where it cuts off the 9 bits from the 16 bit data frame. I think the tricky part is somehow pushing the DC command bit in the correct order otherwise the LCD won't accept the data frame...

>the tricky part is somehow pushing the DC command bit in the correct order

You have to put the D/C  bit to the 8 bits , in a uint16 , to get the 9 bits sequence you need :

AScha3_0-1707205061522.png

+ and write the uint16 to the spi . (here from ili9341 ds )

If you feel a post has answered your question, please click "Accept as Solution".
PLee.3
Associate II

Hi Thanks, I will let you know in a few days once we have tried connecting to the 9-Bit TFT screen and got it too initiate, I was kind of hoping someone might have had some HAL sample SPI code but if I get it working I will post it here. Cheers. 

Would be "More Better" if it ignored excess bits and CSX being low

My expectation that the STM32 would take 16-bit words, and be able to shift out MSB first, and considering the lower order 9-bits of the word when doing that.

Or for the older STM32 parts in 16-bit mode you'd shift the 9-bits to the high order end and output MSB first, and then hope the tailing 7-bits would be ignored.

I also think aggressive bit-banging might be the simplest avenue. Certainly anything capable of wire rates in to the 10's of MHz.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..