TinyShield BLE - LSBFIRST and MSBFIRST

CloudCityEvan

  • Full Member
  • ***
    • Posts: 14
  • Senior iOS Developer | twitter: @interactivlogic
    • View Profile
    • Cloud City Development
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


Ben Rose

  • Administrator
  • Hero Member
  • *****
    • Posts: 342
    • View Profile
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

  • Full Member
  • ***
    • Posts: 14
  • Senior iOS Developer | twitter: @interactivlogic
    • View Profile
    • Cloud City Development
OK thanks, Ben!
Evan K. Stone | Senior iOS Developer | Cloud City Development | http://www.cloudcity.io


 

SMF spam blocked by CleanTalk