TinyCircuits Forum

TinyCircuits Products => TinyDuino Processors & TinyShields => Topic started by: CloudCityEvan on December 28, 2015, 12:48:12 PM

Title: TinyShield BLE - LSBFIRST and MSBFIRST
Post by: CloudCityEvan 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

Title: Re: TinyShield BLE - LSBFIRST and MSBFIRST
Post by: Ben Rose 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.
Title: Re: TinyShield BLE - LSBFIRST and MSBFIRST
Post by: CloudCityEvan on December 28, 2015, 11:57:03 PM
OK thanks, Ben!