2024-02-05 11:30 AM - edited 2024-02-05 11:30 AM
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)
2024-02-05 11:41 AM
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.
2024-02-05 11:47 AM - edited 2024-02-05 11:50 AM
Hi,
which cpu ? F4xxx
+
lsb or msb first can select in Cube:
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.
2024-02-05 11:59 AM
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.
2024-02-05 12:40 PM
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...
2024-02-05 11:40 PM
>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 :
+ and write the uint16 to the spi . (here from ili9341 ds )
2024-02-06 10:53 AM
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.
2024-02-06 11:01 AM
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.