TinyCircuits

TinyShield BLE - LSBFIRST and MSBFIRST

CloudCityEvan

  • ***
  • 14
  • Senior iOS Developer | twitter: @interactivlogic
    • View Profile
    • Cloud City Development
TinyShield BLE - LSBFIRST and MSBFIRST
« on: December 28, 2015, 12:48:12 PM »
Hi!

I noticed that the TinyShield BLE example uses:

Code: [Select]
SPI.setBitOrder(LSBFIRST);
// Do some stuff...
SPI.setBitOrder(MSBFIRST);

Please pardon my ignorance and lack of knowledge in this area (I'm trying to come up to speed, really!!! ;) ), but is there a general rule of thumb as to when this toggling should be done? Are there times at which it should NOT be done?

Thanks in advance!!!

-Evan

Evan K. Stone | Senior iOS Developer | Cloud City Development | http://www.cloudcity.io

Re: TinyShield BLE - LSBFIRST and MSBFIRST
« Reply #1 on: December 28, 2015, 08:31:40 PM »
That's in there because many SPI devices(especially among those on TinyShields) are MSB first. So, it's simply flipping it for the NRF8001 when necessary, then flipping it back. Common stuff like an SD card, TinyScreen, CC3000 WiFi, etc uses MSB first, and the associated libraries won't work if the bit order is flipped by other code while running.

A better way to take care of this issue is using something along the lines of the newer Arduino SPI 'transaction' interface, but unfortunately very little code out there actually uses this- something we'd like to work on, but rarely get to.

CloudCityEvan

  • ***
  • 14
  • Senior iOS Developer | twitter: @interactivlogic
    • View Profile
    • Cloud City Development
Re: TinyShield BLE - LSBFIRST and MSBFIRST
« Reply #2 on: December 28, 2015, 11:57:03 PM »
OK thanks, Ben!
Evan K. Stone | Senior iOS Developer | Cloud City Development | http://www.cloudcity.io