SPI bit ordering

If you have a simple question and just want an answer.
psupine
New User
Posts: 3
Joined: Wed May 16, 2018 7:28 am

SPI bit ordering

Postby psupine » Wed May 16, 2018 7:44 am

I'm playing with the Explorer-200 board and an OLED display over the SPI, and am looking at the SPI library documentation (SPI 3.0.2).

The mode diagrams on pages 2-3 show MSB first, but the <<spi_master_if>> description on page 18 specifies LSB first. Can anyone tell me which is correct?
psupine
New User
Posts: 3
Joined: Wed May 16, 2018 7:28 am

Postby psupine » Thu May 17, 2018 1:21 am

I'm answering my own question here, in the hope it might be useful for someone else searching the forum like I did.

I looked at the library code. The SPI library function explicity bit reverses the data that is passed to it before it send it to the port shift register. That means if I want to use the SPI library I'd have to first bit reverse my data for the library function to then bit reverse it back again. That seems pretty dumb to me, so I'll just talk to the port directly.
User avatar
mon2
XCore Legend
Posts: 1063
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Postby mon2 » Thu May 17, 2018 4:45 am

Please review appnote AN00160: How to use the SPI library as SPI master and related demo source code:

https://www.xmos.com/support/appnotes/AN00160

This project will run in the simulator.

Also review:

https://www.allaboutcircuits.com/techni ... interface/

viewtopic.php?t=1617

Code: Select all

reversed_value = bitrev(value_to_send); // could be used to reverse any data if required


Personally would just experiment and confirm the operation with your OLED display.
psupine
New User
Posts: 3
Joined: Wed May 16, 2018 7:28 am

Postby psupine » Fri May 18, 2018 5:45 am

Ah hah!

The shift register at the port is natively LSB first. So the bitrev call in the spi library function makes this MSB first. Now I know.

Who is online

Users browsing this forum: No registered users and 8 guests