Arduino DUE and SPI 9 bits

Hello,

I want use the functionality of the arduino DUE to send 9 bits SPI data.

I havn't found anything in your SPI documentation about the SPI data length..

Any hint for me?

Thanks and regards,

Fabien D.

What function would you actually be using to transfer the data? Perhaps there's a clue in the data type.

You might have write your own code to do it manually, and not depend on libraries or hardware. 8 bit bytes are pretty well ingrained nowadays. 8^)

duayfabi:
I want use the functionality of the arduino DUE to send 9 bits SPI data.

Why do you want to? For what device? Link to datasheet please.

You will have to "bit bang" 9 bits - SPI uses internal 8 bit register to output 8 bits.
Or send out 16, first 7 as don't cares and the final 9 as the keepers, if your device will ignore them and just latch the last 9 on CS/SS going high.

duayfabi:
I want use the functionality of the arduino DUE to send 9 bits SPI data.

I havn't found anything in your SPI documentation about the SPI data length..

Any hint for me?

The SPI peripheral in the SAM3X can do 9 bit transfers, but this is not supported by the SPI library. It would be very easy to add though.

bobcousins:
The SPI peripheral in the SAM3X can do 9 bit transfers, but this is not supported by the SPI library. It would be very easy to add though.

Exactly, in the SAM3X datasheet, on page 679, you can read :

– 8- to 16-bit Programmable Data Length Per Chip Select

My question was on the implementation of this functionality in the new arduino framework.
In the documentation, nothing is said about this but perhaps the doc isen't up to date...

I will see to add it myself.

Thank you.

Moderator Gammon asks what is the application for 9 bit SPI and asks for data sheets.

A common application is for graphic LCDs where the 9th bit is clear for a data byte and set for a command byte. Two displays using this are:
2.2 18-bit color TFT LCD display with microSD card breakout [HX8340BN] : ID 797 : $29.95 : Adafruit Industries, Unique & fun DIY electronics and kits and 1.8 Color TFT LCD display with MicroSD Card Breakout [ST7735R] : ID 358 : $19.95 : Adafruit Industries, Unique & fun DIY electronics and kits

It would be a well received extension to the current library (documentation at http://arduino.cc/en/Reference/DueExtendedSPI) if this type of addressing could be accommodated for rather than a bitbanging method.

Several AVR libraries exist - they mostly turn off the hardware SPI, toggle the line manually if needed and clock, then turn it back on. This is very hard to do if one is using the SPI library, the functionality is not exposed.

If this cannot be accomplished, there is some code for bitbanging the SAM in a way similar to the AVR but it has not been ported to a tidy library. Tom Carpenter's gLCD libary appears to do this.