Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: 9bit SPI Interface (3-wire), teensy 3.2

  1. #1

    9bit SPI Interface (3-wire), teensy 3.2

    Hello,

    TFT/Display Controller sometimes use a 3-Wire 9bit SPI Interface (9 bit = command/data).
    Does somebody know if this 9bit is available on the teensy 3.2?

    I have checked the SPI.h... there I see only the possibilty to transfer 1x, 2x, 3x etc. bytes, but not exactly 9bit.

    thank you
    Last edited by epikao; 04-24-2017 at 02:12 PM.

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,396
    Yes it is possible. There is a way to set the frame size from 4-16 bits.

    It is in SPI section of the reference manual.

    You do this by setting one of the CTAR registers and then specify that CTAR as part of an SPI operation...
    By default we have the two CTAR registers set to 8 and 16 bit mode. But I see instances in the code that set the 2nd ctar to 9 bit mode.

    Right now I am not sure of a clean way to do this. You could probably start a transaction, than update the FMSZ value of CTAR1 for the appropriate SPI module and then do a SPI.transfer16(value) and have it transfer only 9 bits

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,718
    Yup, that sounds about right.

    Don't forget to restore that CTAR register before you end the SPI transaction.

  4. #4
    phuu, that looks not easy,
    I just had a quick look on the reference manual:
    https://www.pjrc.com/teensy/K20P64M72SF1RM.pdf
    Click image for larger version. 

Name:	SPI_CTAR Teensy.png 
Views:	58 
Size:	56.8 KB 
ID:	10411

    I assume I most change something in the SPI.h file - and FMSZ?

    inTransactionFlag = 1;
    #endif
    if (SPI0_CTAR0 != settings.ctar) {
    SPI0_MCR = SPI_MCR_MDIS | SPI_MCR_HALT | SPI_MCR_PCSIS(0x1F);
    SPI0_CTAR0 = settings.ctar;
    SPI0_CTAR1 = settings.ctar| SPI_CTAR_FMSZ(8); // change to SPI0_CTAR1 = settings.ctar| SPI_CTAR_FMSZ(9); - but how...?
    SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_PCSIS(0x1F);
    }
    }

    and usually I should write 9bit and then write/read 8bit...

  5. #5
    Quote Originally Posted by epikao View Post
    phuu, that looks not easy,
    I just had a quick look on the reference manual:
    https://www.pjrc.com/teensy/K20P64M72SF1RM.pdf
    Click image for larger version. 

Name:	SPI_CTAR Teensy.png 
Views:	58 
Size:	56.8 KB 
ID:	10411

    I assume I most change something in the SPI.h file - and FMSZ?

    inTransactionFlag = 1;
    #endif
    if (SPI0_CTAR0 != settings.ctar) {
    SPI0_MCR = SPI_MCR_MDIS | SPI_MCR_HALT | SPI_MCR_PCSIS(0x1F);
    SPI0_CTAR0 = settings.ctar;
    SPI0_CTAR1 = settings.ctar| SPI_CTAR_FMSZ(8); // change to SPI0_CTAR1 = settings.ctar| SPI_CTAR_FMSZ(9); - but how...?
    SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_PCSIS(0x1F);
    }
    }

    and usually I should write 9bit and then write/read 8bit...
    Did you ever get this working? I have some 9-bit(3-wire) tft displays I would like to use too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •